JQuery Sortable and automatic scrolling

后端 未结 9 2257
走了就别回头了
走了就别回头了 2021-02-05 10:02

I am trying to get JQuery Sortable to work but I have run into a slight usability problem.

The list that I am trying to sort is quite large (about 200 items). If the

9条回答
  •  北恋
    北恋 (楼主)
    2021-02-05 10:31

    While the value of the scrollSensitivity controls the scroll behaviour when the helper item approaches an edge (top or bottom), you can use the "sort" event to unconditionally scroll while you drag if you use the following code:

    $(".sortable").sortable({
        scroll: true,
        scrollSensitivity: 80,
        scrollSpeed: 3,
        sort: function(event, ui) {
            var currentScrollTop = $(window).scrollTop(),
                topHelper = ui.position.top,
                delta = topHelper - currentScrollTop;
            setTimeout(function() {
                $(window).scrollTop(currentScrollTop + delta);
            }, 5);
        }
    });
    

    Not sure if this completely addresses the issue you're seeing, but I found that usability with larger list improves with this approach. Here is a link to jsfiddle.

提交回复
热议问题