所以後有點來回我已經成功克隆原ui.helper
元素(即sortable
創建),並用該克隆(這是不被還原回明顯),完成自定義動畫序列來解決這個同時刪除原始幫手和佔位符(由sortable
創建)以隱藏sortable
的恢復動畫。
它並不像我想要的那樣乾淨,因爲我仍然在讓sortable
的恢復函數執行(而不是取消它),但是直到有人有更好的主意,它才起作用。下面
代碼:
// default sortable interaction/setup.
$('.sortable-list').sortable({
placeholder: 'sortable-list__item sortable-list__item--placeholder',
revert: true,
helper: 'clone',
tolerance: 'pointer',
connectWith: '.sortable-list',
appendTo: 'body',
zIndex: 1000
});
// dropzone interaction will grab the ui.helper from sortable clone it and then
// reuse it for it's own finish animation while removing the helpers from the
// sortable list and dom.
$('.dropzone')
.droppable({
accept: '.sortable-list__item',
hoverClass: 'dropzone--hover',
activeClass: 'dropzone--active',
tolerance: 'pointer'
})
.on('drop', function(event, ui) {
var $item = ui.draggable, // this is the original item.
$helper = ui.helper; // this is the cloned item the user drags
// clone the helper instance and position it in the same exact spot where
// the user had left it using the ui.position
// (or ui.offset depending on your nesting/positioning of the helper)
var $clone = $helper.clone().css({
"position": "absolute",
"top": ui.position.top,
"left": ui.position.left
}).appendTo('body');
// cleanup the original helper (remove from stage) and hide placeholder
// elements. We're hiding the latter because the revert callback of
// sortable is removing it for us and will otherwise throw an error that
// the placeholder can't be removed because it no longer exists in the DOM.
$helper.remove();
$('.sortable-list__item--placeholder').hide();
// launch into your own animation sequence using the $clone of $helper
// and process the drop data accordingly.
});