我寫了自己的解決方法,通過dioslaska的解決方案的啓發,他自己的問題在這裏: jQuery UI sortable tolerance option not working as expected
它的工作原理很順利:)
取出tolerance
選項,並使用以下功能sort
選項:
function(e, ui) {
var container = $(this),
placeholder = container.children('.ui-sortable-placeholder:first');
var helpHeight = ui.helper.outerHeight(),
helpTop = ui.position.top,
helpBottom = helpTop + helpHeight;
container.children().each(function() {
var item = $(this);
if(!item.hasClass('ui-sortable-helper') && !item.hasClass('ui-sortable-placeholder')) {
var itemHeight = item.outerHeight(),
itemTop = item.position().top,
itemBottom = itemTop + itemHeight;
if((helpTop > itemTop) && (helpTop < itemBottom)) {
var tolerance = Math.min(helpHeight, itemHeight)/2,
distance = helpTop - itemTop;
if(distance < tolerance) {
placeholder.insertBefore(item);
container.sortable('refreshPositions');
return false;
}
} else if((helpBottom < itemBottom) && (helpBottom > itemTop)) {
var tolerance = Math.min(helpHeight, itemHeight)/2,
distance = itemBottom - helpBottom;
if(distance < tolerance) {
placeholder.insertAfter(item);
container.sortable('refreshPositions');
return false;
}
}
}
});
}
只是一個頭:排序被稱爲非常頻繁,所以遍歷所有容器的每個鼠標移動的孩子可能是昂貴的.. – plesatejvlk 2013-10-14 07:51:49