以下步骤适用于下面分享的jsFiddle。
步骤:
预期结果:
实际结果:
备注:
相关问题:
我问这个问题,因为它似乎与下面的StackOverflow问题有些相关,但我的情况略有不同。也许它有相同的根本原因,但可能有不同的解决方法?
的jsfiddle:
https://jsfiddle.net/deepankarj/60zz9zgb/
$(function() {
$("#draggable, #draggable2").draggable({
cursor: "move",
cursorAt: {
top: 0,
left: 0
},
});
function logEventId(prefix, event) {
console.log(prefix + ": " + event.target.id);
}
function createLogEventIdFunction(handlerName) {
return function(event, ui) {
logEventId(handlerName, event);
}
}
$("#droppable, #droppable-inner").droppable({
activeClass: "ui-state-hover",
hoverClass: "ui-state-active",
tolerance: "pointer",
over: createLogEventIdFunction("over"),
out: createLogEventIdFunction("out"),
drop: function(event, ui) {
logEventId("drop", event);
$(this)
.addClass("ui-state-highlight")
.find("> p")
.html("Dropped!");
return false;
}
});
function decorateWithDroppable(selector, greedy, canAccept, over) {
canAccept = !!canAccept ? canAccept : function(element) {
console.log("canAccept: this: " + $(this).attr("id") + ", el: " + element.attr("id") + ", result: true");
return true;
};
over = !!over ? over : createLogEventIdFunction("over");
$(selector).droppable({
greedy: greedy,
activeClass: "ui-state-hover",
hoverClass: "ui-state-active",
tolerance: "pointer",
accept: canAccept,
over: over,
out: createLogEventIdFunction("out"),
drop: function(event, ui) {
logEventId("drop", event);
$(this)
.addClass("ui-state-highlight")
.find("> p")
.html("Dropped!");
}
});
};
decorateWithDroppable("#droppable2, #droppable2-inner", true);
decorateWithDroppable("#droppable3", true);
decorateWithDroppable("#droppable3-inner", true, function canAccept(element) {
console.log("canAccept: this: " + $(this).attr("id") + ", el: " + element.attr("id") + ", result: " + (element.attr("id") !== "draggable"));
return (element.attr("id") !== "draggable");
});
});
答案 0 :(得分:0)
初始化draggable时,将refreshPositions设置为true对我有效。这是示例代码。
jQuery().draggable({
....
refreshPositions: true
....
});