2017-07-20 5 views
0

Wie kann ich die Höhe und Breite des Drop-Elements bekommen? Ich habe 'ui.draggable.width' oder 'ui.width' versucht, aber es funktioniert nicht. Das ist mein Code:JQuery UI erhalten Breite und Höhe des dropped Elements

 $('#bagpack').droppable({ 
      accept: '.item', 
      drop: function(ev, ui) { 
        console.log(ui.draggable.width); // Doesn't work 
       if (ui.offset.left - $(this).offset().left < -20 || ui.offset.top - $(this).offset().top < -20 || 
         ($(this).offset().left + $(this).width()) - (ui.offset.left + ui.draggable.width/2) < 20 || 
         ($(this).offset().top + $(this).height()) - (ui.offset.top + ui.draggable.height/2) < 40) 
       { 
        $(ui.draggable).draggable({ 
         revert: true, 
         stop: function(){ 
          $(ui.draggable).draggable('option','revert','invalid'); 
         } 
        }); 
       } 
       else 
       { 
         itemEquip(ui.draggable, this, ui.offset.left - $(this).offset().left, ui.offset.top - $(this).offset().top); 
       } 
      } 
    }); 

Antwort

1

Verwenden Sie die height() und width() Funktionen auf dem $(ui.draggable) Element. Zum Beispiel

$('#bagpack').droppable({ 
     accept: '.item', 
     drop: function(ev, ui) { 
      console.log($(ui.draggable).width()); 
      console.log($(ui.draggable).height()); 
     } 
Verwandte Themen