我的解决方案可能不是最优雅的(也许某人可以提供更直观的东西?),但似乎它有效;)
小提琴:http://jsfiddle.net/W9Z46/14/
(function ($) { var lastPlace; $("#choises li img").draggable({ revert: true, zIndex: 10, snap: "#answers li", snapMode: "inner", snapTolerance: 40, start: function (event, ui) { lastPlace = $(this).parent(); } }); $("#answers li").droppable({ drop: function (event, ui) { var dropped = ui.draggable; var droppedOn = this; if ($(droppedOn).children().length > 0) { $(droppedOn).children().detach().prependTo($(lastPlace)); } $(dropped).detach().css({ top: 0, left: 0 }).prependTo($(droppedOn)); } }); })(jQuery);
正如你所看到的那样,我只是保留你在变量中lastPlace
开始拖拽的地方,然后当你放下并检查某些东西时,你将它放在你之前开始拖动的地方.
我的解决方案可能不是最优雅的(也许某人可以提供更直观的东西?),但似乎它有效;)
小提琴:http://jsfiddle.net/W9Z46/14/
(function ($) { var lastPlace; $("#choises li img").draggable({ revert: true, zIndex: 10, snap: "#answers li", snapMode: "inner", snapTolerance: 40, start: function (event, ui) { lastPlace = $(this).parent(); } }); $("#answers li").droppable({ drop: function (event, ui) { var dropped = ui.draggable; var droppedOn = this; if ($(droppedOn).children().length > 0) { $(droppedOn).children().detach().prependTo($(lastPlace)); } $(dropped).detach().css({ top: 0, left: 0 }).prependTo($(droppedOn)); } }); })(jQuery);
正如你所看到的那样,我只是保留你在变量中lastPlace
开始拖拽的地方,然后当你放下并检查某些东西时,你将它放在你之前开始拖动的地方.