Jquery UI可排序 - 仅对drop事件进行排序

时间:2015-05-19 10:04:11

标签: jquery-ui

我想在拖动项目时禁用项目的排序。只有在完成丢弃后,项目才必须进行相应的排序。

     $( "#sortable" ).sortable({

        tolerance: 'pointer',
        revert: 'invalid',
        forceHelperSize: true,
        scroll: true,
        forcePlaceholderSize: true,
        placeholder: 'ui-state-highlight',
        helper: 'clone',
        containment: 'parent',
        cursor: 'move',        
        distance: 5,
        opacity: 0.3,
    });

link:jsfiddle

1 个答案:

答案 0 :(得分:2)

这样做的一种方法是在不同的事件中微观管理占位符位置。它会导致恢复问题,但可能有办法以某种方式解决这个问题。并且行为可能不完全相同,但同样,一点点调整,它可能在那里。无论如何,我的建议是:

$(function () {
    $("#sortable").sortable({

        tolerance: 'pointer',
        //revert: 'invalid',
        forceHelperSize: true,
        scroll: true,
        forcePlaceholderSize: true,
        placeholder: 'ui-state-highlight',
        helper: 'clone',
        containment: 'window',
        cursor: 'move',
        distance: 5,
        opacity: 1,
        start: function (event, ui) {
            place_prev = ui.placeholder.prev();//get position when selecting item
        },
        change: function (event, ui) {
            place_pos = ui.placeholder.index(); //each change you gather where the placeholder is going
            place_prev.after(ui.placeholder);//then you place it back where it started
        },
        beforeStop: function (event, ui) {

            $('li').eq(place_pos).after(ui.item);//before stopping you place item where it was on last change event
        },

    });

});

http://jsfiddle.net/2mxw14vv/3/