[英]How do I get a draggable to revert to the original position only if it was dragged onto an invalid droppable?
[英]How do I revert back to original position when you hit 'cancel' upon delete confirmation (JQUERY UI draggable & droppable )?
jsfiddle.net/L9tba27k/
當您點擊取消時,看到我的可拖動圖像如何坐在垃圾箱的頂部嗎? 我該如何解決? 如果您將圖片拖到垃圾箱外面一點,它只會恢復到原始位置。
非常感謝您的幫助:)
您可以這樣做:
function doConfirm() {
if (confirm('Are you sure you want to delete?')) {
return false;
} else {
return true;
}
}
$(function () {
$(".draggable").draggable();
$('.trash').droppable({
accept: '.draggable',
drop: function (event, ui) {
$('.draggable').draggable("option", "revert", doConfirm);
}
});
});
您可以將.remove()
代碼doConfirm()
以在確認后刪除該元素。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.