问题
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