当我点击可拖动的div时,场景中的一些div变得可以放置,当我将元素拖到目的地时,droppable divs被禁用。它工作正常,但当我想再次删除另一个元素时,我无法启用相同的div。我该如何启用它? http://jsfiddle.net/6v8Lc/3/
function drop (childSocket, inputCache) {
//when "on mousedown" for pawn, pawnSocket calculated if its suitable droppable or not
$(".pawnSocket:nth-child("+childSocket+")").droppable({
hoverClass: "over",
drop: function(ev, ui) {
var thisPosLeft = $(this).position().left;
var thisPosTop = $(this).position().top;
var draggedPawn = $(ui.draggable);
draggedPawn.css({
left: thisPosLeft,
top: thisPosTop
});
var thisIndex = $(this).index();
var suruklenenIndex = piyonYuvaKonum.indexOf(inputCache);
piyonYuvaKonum[suruklenenIndex] = null;
piyonYuvaKonum[thisIndex] = inputCache;
// when i run disable option, it becomes disabled but i can't enable again
$(".pawnSocket").droppable("disable");
//$(this).droppable("option", "disabled", true);
}
});
}
答案 0 :(得分:1)
不是在每次拖动时重新声明一个项目可放置,而是声明它们是可放置的,并在您希望它们被禁用或启用时设置它们。
$(".drag").draggable({ revert: "invalid"})
.on("mousedown", function () {
$(".drop").droppable('enable');
});
$(".drop").droppable({
hoverClass: "over",
drop: function (ev, ui) {
var dizPozL = $(this).position().left + 5;
var dizPozT = $(this).position().top + 5;
var suruklenenPiyon = $(ui.draggable);
suruklenenPiyon.css({
left: dizPozL,
top: dizPozT
});
suruklenenPiyon.hide("slow");
$(".drop").droppable("disable");
},
disabled:true
});