2017-07-20 6 views
0

ドロップ要素の高さと幅を取得するにはどうすればよいですか?私は 'ui.draggable.width'または 'ui.width'を試しましたが、動作しません。この私のコード:JQuery UIでドロップされた要素の幅と高さを取得

 $('#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); 
       } 
      } 
    }); 

答えて

1

$(ui.draggable)要素にheight()width()機能を使用してください。たとえば、

$('#bagpack').droppable({ 
     accept: '.item', 
     drop: function(ev, ui) { 
      console.log($(ui.draggable).width()); 
      console.log($(ui.draggable).height()); 
     } 
関連する問題