jQuery UI Sortable/Draggable causing window jump

梦想与她 提交于 2020-01-04 15:28:24

问题


On my web page I have a div containing a sortable UL, and whenever I scroll to the bottom of my page and drag the last LI my page jumps and the scrollbar (on the entire window) grows.

Here is a JSFiddle that almost captures my issue: www.jsfiddle.net/u5afykpf. To see something close to what is happening to me, scroll to the bottom and drag the last element downwards. You will see the scrollbar grow and shift. On my page however where there is a lot more content and height this causes a shift in the window which is clearly noticeable and undesired. If you go to the jqueryui draggable demo, decrease the window height and drag the last element, you will see that this behavior doesn't happen for them.

Does anybody have experience with jQuery UI draggable and CSS advice they could give me to stop this jump from occurring?

One thing I thought to do was give the div surrounding the UL position: absolute but then it is out of the flow and the layout gets completely messed up.


回答1:


I stubled across this problem very long time ago. Try adding following parameters to .draggable function

$('.selector').draggable({
    appendTo: 'body',
    containment: 'window',
    scroll: false,
    helper: 'clone'
});


来源:https://stackoverflow.com/questions/31950520/jquery-ui-sortable-draggable-causing-window-jump

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!