Jquery UI Sortable - Div 滚动问题

4

I created a Demo here.

Code:

//Javascript

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

});

//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>

//CSS

.scroll{
    overflow:scroll;
    border:1px solid red;
    height: 200px;
    width: 150px;
    position:relative;
}
.content{
    height: 50px;
    width: 100%;
}

当我向下拖动任何一个框时,它会滚动得很长并移出其他框。但是当我向上拖动任何一个框时,它可以正常工作。

那么,有没有办法防止它向下滚动太长?

2个回答

6
请将您的样式表改为以下形式:

.scroll {
    border: 1px solid red;
    height: 200px;
    overflow: auto;
    position: static;
    width: 150px;
}

并在你的 ul 元素上方使用以下代码:

<div style="overflow:hidden;width:150px;height:200px;position:relative">

但是可拖动的项目移出了盒子(<ul>)。 - zeenfaiz

1

虽然这并没有太大帮助,但是如果您查看jQuery UI 文档,您会发现该问题也会出现在那里。我认为这是一个错误。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接