Ver Mensaje Individual
  #1 (permalink)  
Antiguo 06/04/2013, 16:13
Avatar de oscard41
oscard41
 
Fecha de Ingreso: mayo-2012
Ubicación: Caracas
Mensajes: 288
Antigüedad: 11 años, 11 meses
Puntos: 8
Drag and drop

Buenas tardes a todos, actualmente estoy haciendo un drag and drop de un div con el fin de practicar un poco javascript y bueno logre hacer que el div se moviera pero al agregar otro div este se mueve cuando arrastro el div que si tiene el drag...

espero me entiendan aqui les dejo el codigo si lo quieren probar copian y pegan..
Código Javascript:
Ver original
  1. <html>
  2. <head>
  3. <script>
  4.  var titulo=null;
  5.  function mover(a){
  6.  titulo=document.getElementById('titulo');
  7.    x=titulo.style.marginTop;
  8.    y=titulo.style.marginLeft;
  9.    document.addEventListener('mousemove',drag,false);
  10.    document.addEventListener('mouseup',detener,false);
  11.  }
  12.  function drag(event){
  13.    x=event.clientX;
  14.    y=event.clientY;
  15.    titulo.style.marginTop=parseInt(y)-30+'px';
  16.    titulo.style.marginLeft=parseInt(x)-30+'px';
  17.  }
  18.  function detener(event){
  19.  
  20.    document.removeEventListener('mousemove',drag,false);
  21.    document.removeEventListener('mouseup',detener,false);
  22.    
  23.  }
  24. </script>
  25. </head>
  26. </body>
  27. <div id='titulo' onmousedown='mover()' style=' position:absolute; width:60px; height:60px; background-color:blue; margin-top:5px;margin-left:5px; position:relative;'></div>
  28.  
  29. <div style='width:20px; height:20px; background-color:black;margin-top:50px; margin-left:250px;'></div>
  30. </body>
  31. </html>

De ante mano gracias..