Ver Mensaje Individual
  #1 (permalink)  
Antiguo 05/07/2010, 19:31
Blashak
 
Fecha de Ingreso: noviembre-2007
Mensajes: 471
Antigüedad: 16 años, 6 meses
Puntos: 2
Coger informacion del div

Buenas,

Tengo un div en el cual se puede arrastrar pero lo que me falta es que cuando ese div lo arrastre sobre un td me salte la informacion del div.

dejo mi codigo

Código HTML:
Ver original
  1. <html xmlns="http://www.w3.org/1999/xhtml">
  2. <style type="text/css">
  3.   .objMovible{
  4.     position:absolute;
  5.     cursor:pointer;
  6.     z-index:1;
  7.     left: 16px;
  8.     top: 17px;
  9. }
  10. <title>Documento sin título</title>
  11.  
  12. <script type="text/javascript">
  13.         //Si el navegador del cliente es Mozilla la variable siguiente valdrá true
  14.         var moz = document.getElementById && !document.all;
  15.        
  16.         //Flag que indica si estamos o no en proceso de arrastrar el ratón
  17.         var estoyArrastrando = false;
  18.         //Variable para almacenar un puntero al objeto que estamos moviendo
  19.         var dobj;
  20.        
  21.         function arrastrarRaton(e){
  22.            
  23.             if (estoyArrastrando) {
  24.                
  25.                 newLeft = moz ? e.clientX : event.clientX;
  26.                 newTop = moz ? e.clientY : event.clientY;
  27.                 //alert(newLeft - parseInt(dobj.style.width)/2);
  28.            
  29.                 dobj.style.left = newLeft - parseInt(dobj.style.width)/2;
  30.                 dobj.style.top = newTop - parseInt(dobj.style.height)/2;
  31.  
  32.                 return false;
  33.             }
  34.         }
  35.  
  36.  
  37.         function soltarBoton(e) {  
  38.             estoyArrastrando = false;
  39.         }
  40.        
  41.        
  42.         function presionarBoton(e) {
  43.             //Obtenemos el elemento sobre el que se ha presionado el botón del ratón
  44.             var fobj = moz ? e.target : event.srcElement;
  45.             //alert(fobj.parentNode);
  46.             // Buscamos el primer elemento en la que esté contenido aquel sobre el que se ha pulsado
  47.             // que pertenezca a la clase objMovible.
  48.            
  49.             while (fobj.tagName.toLowerCase() != "html" && fobj.className != "objMovible") {
  50.                 fobj = moz ? fobj.parentNode : fobj.parentElement;
  51.             }
  52.            
  53.             // Si hemos obtenido un objeto movible...          
  54.             if (fobj.className == "objMovible") {
  55.                 // Activamos el flag para indicar que se empieza a arrastrar
  56.                 estoyArrastrando = true;
  57.                 // Guardamos un puntero al objeto que se está moviendo en la variable global
  58.                 dobj = fobj;
  59.                
  60.                 // Devolvemos false para no realizar ninguna acción posterior
  61.                 return false;
  62.             }
  63.         }
  64.        
  65.         document.onmousedown = presionarBoton;
  66.         document.onmouseup = soltarBoton;
  67.         document.onmousemove = arrastrarRaton;
  68.  
  69.         document.oncontextmenu=new Function("return false");   
  70.     </script>
  71. </head>
  72.  
  73. <div class="objMovible" style="width:80px;height:80px;background-color:#CC0000"></div><br>
  74. <table width="200" border="1">
  75.   <tr>
  76.     <td></td>
  77.     <td>&nbsp;</td>
  78.   </tr>
  79.   <tr>
  80.     <td>&nbsp;</td>
  81.     <td>&nbsp;</td>
  82.   </tr>
  83. </body>
  84.  
  85. </html>

Alguna idea???

Saludos