Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery ui Jquery UI可排序-仅在删除事件时排序_Jquery Ui - Fatal编程技术网

Jquery ui Jquery UI可排序-仅在删除事件时排序

Jquery ui Jquery UI可排序-仅在删除事件时排序,jquery-ui,Jquery Ui,我想在拖动项目时禁用项目排序。只有在完成放置后,项目才能相应地排序 $( "#sortable" ).sortable({ tolerance: 'pointer', revert: 'invalid', forceHelperSize: true, scroll: true, forcePlaceholderSize: true, placeholder: 'ui-state-highl

我想在拖动项目时禁用项目排序。只有在完成放置后,项目才能相应地排序

     $( "#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,
    });

一种方法是在不同的事件中微观管理占位符位置。这会导致revert出现问题,但可能有某种方法可以解决此问题。行为可能并不完全相同,但再一次,稍微调整一下,它可能就在那里。无论如何,我的建议是:

$(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
        },

    });

});

不包括您的链接。你能更新吗?@mjk OP的小提琴是,如果你试图编辑问题,你可以看到它。@OP:我假设你删除了这个链接,因为SO的编辑抱怨你包含了一个没有任何代码的链接;不要试图绕过这个过滤器,只要试着改进这个问题。我已经从中复制了JS,请编辑到您认为相关的内容