Ver Mensaje Individual
  #4 (permalink)  
Antiguo 11/01/2013, 15:05
Avatar de patilanz
patilanz
 
Fecha de Ingreso: enero-2012
Mensajes: 880
Antigüedad: 12 años, 4 meses
Puntos: 29
Respuesta: Objetos arrastrables

Tengo varios objetos que quiero que cuando un objeto que es movido choque con otro se pare y no entre en el. Pero no consigo hacer nada... Tengo el siguiente codigo:

En el window.load tengo esto:

Código Javascript:
Ver original
  1. $( "#p1" ).draggable({containment: 'parent', cursor: "move", cursorAt: { bottom: 0}, drag: function(event, ui){
  2.         almacenar(1);  
  3.     }});
  4.     $( "#p1" ).resizable({animate: true, minHeight: 200, minWidth: 200, maxHeight: 300, maxWidth: 400, helper: 'rezisable_helper', containment: "parent"});
  5.     $( "#p2" ).draggable({containment: 'parent', cursor: "move", cursorAt: { bottom: 0}, drag: function(event, ui){
  6.         almacenar(1);  
  7.     }});
  8.     $( "#p2" ).resizable({animate: true, minHeight: 200, minWidth: 200, maxHeight: 300, maxWidth: 400, helper: 'rezisable_helper', containment: "parent"});
  9.     for(var s=1;s!=7;s++){
  10.         var o=document.getElementById('p'+s);
  11.         p[s]={x:o.style.left.substring(0,o.style.left.indexOf('px')),
  12.           y:o.style.top.substring(0,o.style.top.indexOf('px')),
  13.           width:o.style.width.substring(0,o.style.width.indexOf('px')),
  14.           height:o.style.height.substring(0,o.style.height.indexOf('px'))};
  15.     }


Y luego en una función esto:

Código Javascript:
Ver original
  1. function almacenar(s){
  2.     var o=document.getElementById('p'+s);
  3.  
  4.     for(var i=1;i!=7;i++){
  5.         if(i!=s){
  6.             var c=true;
  7.             var ob=document.getElementById('p'+i);
  8.             if(p[s].x+p[s].width<ob.style.left.substring(0,ob.style.left.indexOf('px'))){
  9.                 c=false;
  10.             }
  11.             if(p[s].y+p[s].height<ob.style.top.substring(0,ob.style.top.indexOf('px'))){
  12.                 c=false;   
  13.             }
  14.             if(p[s].x>ob.style.left.substring(0,ob.style.left.indexOf('px')) + ob.style.width.substring(0,indexOf('px'))){
  15.                 c=false;
  16.             }
  17.             if(p[s].y>ob.style.top.substring(0,ob.style.top.indexOf('px')) + ob.style.height.substring(0,indexOf('px'))){
  18.                 c=false;
  19.             }
  20.         }
  21.         if(c==true){
  22.             document.getElementById('p'+s).style.left=p[s].x+'px';
  23.             document.getElementById('p'+s).style.top=p[s].y+'px';
  24.             document.getElementById('p'+s).style.width=p[s].width+'px';
  25.             document.getElementById('p'+s).style.height=p[s].height+'px';
  26.             alert(document.getElementById('s'+s).style.left);
  27.         }
  28.     }
  29. }

Pero no sucede nada y entran uno en otro :(

Alguien me puede ayudar??