好的,我还没有能够解决这个问题。如果可放置插槽中已存在可拖动元素,则I found this answer有助于拒绝丢弃,但是一旦清空后我无法重新启动接收子节点。此外,它不适用于可拖动片段的初始状态(请注意,如果它是孩子的初始状态,您可以在插槽中堆叠多个片段。)
Here is the link to the project
以下是具体的代码:
jQuery(window).on("load",function() //if document has loaded
{
//Code to be executed when the document loads here
$( ".b-piece" ).draggable({ cursor: "move", revert: "invalid"});
$( ".grid-b .grid-slot" ).droppable({
accept: ".b-piece",
drop: function(event, ui) {
$(this).droppable('option', 'accept', 'none'); /* STOP ACCEPTING OBJECTS */
$(this).append(ui.draggable); /* MOVE DRAG OBJECT TO NEW PARENT */
$(this).children(".game-piece").css({"top":"0", "left":"0"}); /* MAKE GAME PIECE SNAP INTO PLACE */
},
out: function(event, ui){
accept: ".b-piece"
}
});
});
谢谢!
答案 0 :(得分:1)
要重新启动droppable,您只需修改option
开始时的draggable
即可。这将导致恢复问题,因此您还应该在draggable
的停止事件上移动droppable禁用。像这样:
$( ".b-piece" ).draggable({
cursor: "move",
revert: "invalid"
start: function(e, ui){
ui.helper.parent().droppable('option','accept','.b-piece');
},
stop: function(e, ui){
ui.helper.parent().droppable('option','accept','none');
}
});
至于初始状态,在设置droppable
之后运行它,它应该做的诀窍:
$( ".grid-b:not(:empty) .grid-slot:not(:empty)" ).droppable('option', 'accept', 'none');