使用Jquery偏移Droppable

时间:2013-12-05 15:14:11

标签: jquery draggable droppable

enter image description here

我的可放置区域似乎被可拖动项目的宽度所抵消。这意味着当我尝试将一个draggable添加到droppable时,当它实际上不在项目的顶部时它会变为活动状态(在我的图像中,Add New Step是我的可拖动div,而New Step是droppable)。如何设置droppable对象的偏移量以考虑可拖动对象的宽度?

这是我尝试过的(不起作用):

 $('.newStep').draggable();
 $('.newStep').draggable('enable');

  $('.stepNode').not('.newStep').droppable({
       create: function(event, ui){
       var off = $(this).offset();
       console.log("off.left: " + off.left);
       off.left += ui.draggable.width()/2;
       ui.draggable.offset(off);
     },
     disabled: false
   });

的jsfiddle:

http://jsfiddle.net/jdxA8/1/

1 个答案:

答案 0 :(得分:0)

试试这样:

$( ".drag" ).draggable();
$( ".drop" ).droppable({
  drop: function( event, ui ) {
    var off = $( this ).offset();
    off.top += 5;
    off.left += 5;
    ui.draggable.offset( off );
  }
});

http://jsbin.com/iqunod/1/edit