Jquery UI Sortable - Div滚动问题

zee*_*aiz 4 jquery jquery-ui jquery-ui-sortable

我在这里创建了一个Demo .

码:

//使用Javascript

$(function() {
    $("#panel").sortable({
        items: ".content",
        axis:"y",
        scroll:true,
    }).disableSelection();

});
Run Code Online (Sandbox Code Playgroud)

// HTML

<ul id="panel" class="scroll">
    <li class="content" style="background-color:red">item1</li>
    <li class="content" style="background-color:green">item2</li>
    <li class="content" style="background-color:blue">item3</li>
    <li class="content" style="background-color:gray">item4</li>
    <li class="content" style="background-color:yellow">item5</li>
    <li class="content" style="background-color:green">item6</li>
    <li class="content" style="background-color:yellow">item7</li>
    <li class="content" style="background-color:red">item8</li>    
</ul>
Run Code Online (Sandbox Code Playgroud)

// CSS

.scroll{
    overflow:scroll;
    border:1px solid red;
    height: 200px;
    width: 150px;
    position:relative;
}
.content{
    height: 50px;
    width: 100%;
}
Run Code Online (Sandbox Code Playgroud)

在那里,当我向下拖动任何框时,它滚动很长并移出其他框.但是,当我向上拖动任何方框时,它可以正常工作.

那么,有什么方法可以防止它长时间向下滚动?

小智 6

像这样更改样式表:

.scroll {
    border: 1px solid red;
    height: 200px;
    overflow: auto;
    position: static;
    width: 150px;
}
Run Code Online (Sandbox Code Playgroud)

并使用此代码的上方ul:

<div style="overflow:hidden;width:150px;height:200px;position:relative">
Run Code Online (Sandbox Code Playgroud)