jQuery Sortable List - scroll bar jumps up when sorting

后端 未结 13 1026
慢半拍i
慢半拍i 2020-12-24 12:28

I created a demo: http://pastebin.me/584b9a86d715c9ba85b7bebf0375e237

When the scroll bar is at the bottom and you drag items to sort them, it causes the scroll bar

13条回答
  •  有刺的猬
    2020-12-24 13:18

    I was loading my sortable divs VIA Ajax into a wrapper with an auto height.

    Instead of trying to link into sortable events, I just made the height auto when loading and changing the list and then set it to a static height afterwards.

    Vit's solution is similar, but I didn't want to add unnecessary overhead by doing this on every mousedown and mouseup event. Instead, I just do it when the list is changing on the load or when new elements are added (I use a slideDown animation and just set the height to static when it is complete).

    $("#wrapper").load("list.php",function() {
        $("#wrapper").css({ "height":"auto" });
        $("#wrapper").css({ "height": $("#wrapper").height() });
    }
    

    The other solutions weren't working for me when I reload data as I only made them sortable once during the page load.

    My list/div changes with a dropdown so I am able to select different lists and my wrapper resizes accordingly without the annoying jump.

    If you need to add elements or reload anything, just throw those two lines of code into a function and call the function.

    Hope this helps someone!

提交回复
热议问题