Foros del Web » Programando para Internet » Javascript »

Drag and Drop... al llegar a cierta coordenada realizar evento

Estas en el tema de Drag and Drop... al llegar a cierta coordenada realizar evento en el foro de Javascript en Foros del Web. Pues... primera vez que vengo por aquí, espero que me puedan ayudar. Resulta que quiero mover una capa hacia otra, o por lo menos que ...
  #1 (permalink)  
Antiguo 02/01/2006, 16:49
Avatar de HPNeo  
Fecha de Ingreso: mayo-2004
Ubicación: The Matrix
Mensajes: 223
Antigüedad: 20 años
Puntos: 0
Drag and Drop... al llegar a cierta coordenada realizar evento

Pues... primera vez que vengo por aquí, espero que me puedan ayudar.

Resulta que quiero mover una capa hacia otra, o por lo menos que cuando llegue la capa que muevo a cierta coordenada (x,y) se realize un evento como mostrar un alert o una función.

Este código lo encontré por aqui:

Código HTML:
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Documento sin t&iacute;tulo</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<style type="text/css">
.drag{
position:relative;
cursor:hand;
z-index: 100;
}
</style>
<script type="text/javascript">
/***********************************************
* Drag and Drop Script: © Dynamic Drive (http://www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for this script and 100s more.
***********************************************/
var dragobject={
z: 0, x: 0, y: 0, offsetx : null, offsety : null, targetobj : null, dragapproved : 0,
initialize:function(){
document.onmousedown=this.drag
document.onmouseup=function(){this.dragapproved=0}
},
drag:function(e){
var evtobj=window.event? window.event : e
this.targetobj=window.event? event.srcElement : e.target
if (this.targetobj.className=="drag"){
this.dragapproved=1
if (isNaN(parseInt(this.targetobj.style.left))){this.targetobj.style.left=0}
if (isNaN(parseInt(this.targetobj.style.top))){this.targetobj.style.top=0}
this.offsetx=parseInt(this.targetobj.style.left)
this.offsety=parseInt(this.targetobj.style.top)
this.x=evtobj.clientX
this.y=evtobj.clientY
if (evtobj.preventDefault)
evtobj.preventDefault()
document.onmousemove=dragobject.moveit;}
},
moveit:function(e){
var evtobj=window.event? window.event : e
if (this.dragapproved==1){
this.targetobj.style.left=this.offsetx+evtobj.clientX-this.x+"px";
this.targetobj.style.top=this.offsety+evtobj.clientY-this.y+"px";return false;
}
}
}
dragobject.initialize();
</script></head>
<body>
<img src="http://www.forosdelweb.com/images/vbulletin3_logo_fdw.gif" width="300" height="220" class="drag" /> 
</body>
</html>
 
__________________
HPNeo
  #2 (permalink)  
Antiguo 03/01/2006, 19:09
Avatar de HPNeo  
Fecha de Ingreso: mayo-2004
Ubicación: The Matrix
Mensajes: 223
Antigüedad: 20 años
Puntos: 0
Ya solucione el problema, pero ahora quiero que cuando este dentro de cierto rango de coordenadas se realice un evento como una funcion.

Código HTML:
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Documento sin t&iacute;tulo</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<style type="text/css">
.drag{
position:relative;
cursor:hand;
z-index: 100;
}
</style>
<script type="text/javascript">
/***********************************************
* Drag and Drop Script: © Dynamic Drive (http://www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for this script and 100s more.
***********************************************/
var dragobject={
z: 0, x: 0, y: 0, offsetx : null, offsety : null, targetobj : null, dragapproved : 0,
initialize:function(){
document.onmousedown=this.drag
document.onmouseup=function(){
this.dragapproved=0;
if (this.targetobj.style.left=="570px"){
if (this.targetobj.style.top="165px"){
window.status = "Left y Top";
alert("Eliminar");
}
else{
window.status="Solo Left";
return false;
}
}
else{
window.status="Ni Left ni Top";
return false;
}
}
},
drag:function(e){
var evtobj=window.event? window.event : e
this.targetobj=window.event? event.srcElement : e.target
if (this.targetobj.className=="drag"){
this.dragapproved=1
if (isNaN(parseInt(this.targetobj.style.left))){this.targetobj.style.left=0}
if (isNaN(parseInt(this.targetobj.style.top))){this.targetobj.style.top=0}
this.offsetx=parseInt(this.targetobj.style.left)
this.offsety=parseInt(this.targetobj.style.top)
this.x=evtobj.clientX
this.y=evtobj.clientY
if (evtobj.preventDefault){
evtobj.preventDefault()}
document.onmousemove=dragobject.moveit;
}
},
moveit:function(e){
var evtobj=window.event? window.event : e
if (this.dragapproved==1){
this.targetobj.style.left=this.offsetx+evtobj.clientX-this.x+"px";
this.targetobj.style.top=this.offsety+evtobj.clientY-this.y+"px";return false;
}
}
}
dragobject.initialize();
</script>
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_reloadPage(init) { //reloads the window if Nav4 resized
if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
//-->
</script>
</head>
<body bgcolor="#4477AA">
<img src="http://www.forosdelweb.com/images/vbulletin3_logo_fdw.gif" width="517" height="22" class="drag"/> 
<div id="papelera" style="left: 580px;
top: 180px;
position: absolute;
width: 50px;
height: 20px;
z-index:100px;
background: #000000;">papelera</div>
</body>
</html>
 
__________________
HPNeo
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 08:59.