【发布时间】:2017-07-15 20:28:54
【问题描述】:
在这里编写代码:https://codepen.io/anon/pen/weZwVx
我有一些可拖动的图像。我需要仅将它们返回到原来的位置。因此,基本上即使它们被拖回错误的位置,它们也会捕捉到它们在表格中的原始位置。
现在,当您将其拖回原始位置时,即使它包含另一个图像,也可以将其添加到另一个 td。图像应该能够放在紫色框中,然后如果有人将它移回黑色桌子,它应该只回到原来的位置,即使它被拖回另一个位置。
这是 JS:
$( ".emojis" ).draggable({
revert : function(event, ui) {
$(this).data("ui-draggable").originalPosition = {
top : 0,
left : 0
};
return !event;
}
});
$('#drop-em').droppable({
drop: function(ev, ui) {
$(ui.draggable).detach().css({top: 0,left: 0}).appendTo(this);
}
});
$('#emoji-table td').droppable({
drop: function(ev, ui) {
$(ui.draggable).detach().css({top: 0,left: 0}).prependTo(this);
}
});
【问题讨论】:
标签: javascript jquery jquery-ui jquery-ui-draggable jquery-ui-droppable