演示:http://jsfiddle.net/py3DE/禁用/啓用可拖動jQuery中
$(".source .item").draggable({ revert: "invalid", appendTo: 'body', helper: 'clone',
start: function(ev, ui){ ui.helper.width($(this).width()); } // ensure helper width
});
$(".target .empty").droppable({ tolerance: 'pointer', hoverClass: 'highlight',
drop: function(ev, ui){
var item = ui.draggable;
if (!ui.draggable.closest('.empty').length) item = item.clone().draggable();// if item was dragged from the source list - clone it
this.innerHTML = ''; // clean the placeholder
item.css({ top: 0, left: 0 }).appendTo(this); // append item to placeholder
}
});
$(".target").on('click', '.closer', function(){
var item = $(this).closest('.item');
item.fadeTo(200, 0, function(){ item.remove(); })
});
我的目標是當一個項目從.source取出並丟棄到.TARGET,我想禁用滴入所以拖動我只能將.source中的項目的單個實例以.target結尾。相反,我也試圖在從.target中移除項目後重新啓用該項目。
我不知道我理解你提出什麼 – S16
做,檢查我的答案和小提琴 –