我要做的方式是在拖动开始时存储可拖动的父级,然后我们来确定我是要交换孩子还是停止事情。
这是小提琴:
http://jsfiddle.net/vvn5S/
和javascript:
$(function () {
var origin;
$(".tire").draggable({
appendTo: "body",
cursor: "move",
helper: 'clone',
revert: "invalid",
start: function (event, ui) {
origin = event.target.parentNode;
}
});
$("#tire_deck").droppable({
tolerance: "intersect",
accept: ".tire",
activeClass: "ui-state-default",
hoverClass: "ui-state-hover",
drop: function (event, ui) {
$("#tire_deck").append($(ui.draggable));
}
});
$(".drop_1, .drop_2, .drop_3, .drop_4, .drop_5, .drop_6").droppable({
tolerance: "intersect",
accept: ".tire",
drop: function (event, ui) {
if (this.children.length == 0) {
$(this).append($(ui.draggable));
} else {
if (origin.id !== "tire_deck") {
event.stopPropagation();
var copyNode = $(this).children().detach();
$(this).append($(ui.draggable));
$(origin).append(copyNode);
} else {
alert("Stopped!");
}
}
}
});
});