简体   繁体   English

jquery ui draggable在容器内滚动

[英]jquery ui draggable scrolling within container

I have an unordered list and have added draggable functionality to each of the list item using jquery ui draggable. 我有一个无序列表,并使用jquery ui draggable为每个列表项添加了可拖动功能。 the list is inside a div with id="content". 列表位于id =“content”的div中。 Here is the snapshot of my UL list 这是我的UL列表的快照

在此输入图像描述

Here is the code i have written: 这是我写的代码:

 <script src="../../jquery-1.8.0.js"></script>
<script src="../../ui/jquery.ui.core.js"></script>
<script src="../../ui/jquery.ui.widget.js"></script>
<script src="../../ui/jquery.ui.mouse.js"></script>
<script src="../../ui/jquery.ui.draggable.js"></script>
 <script type="text/javascript">
$(function() {
    $( ".draggable" ).draggable({ 
        scroll: true,
        scrollSensitivity: 100,
        revert: true,
        containment: '#content',
        zIndex: 999990,
        revertDuration: 100,
        delay: 100 
    });
});
</script>
<div style="width:200px;height:300px;overflow:auto;" id="content">
    <ul>
    <li class="draggable">One</li>
    <li class="draggable">Two</li>
    <li class="draggable">Three</li>
    <li class="draggable">Four</li>
    <li class="draggable">five</li>
    <li class="draggable">six</li>
    <li class="draggable">Seven</li>
    <li class="draggable">Eight</li>
    <li class="draggable">Nine</li>
    <li class="draggable">Ten</li>
    <li class="draggable">Eleven</li>
    <li class="draggable">Twelve</li>
    <li class="draggable">Thirteen</li>
    <li class="draggable">Fourteen</li>
    <li class="draggable">Fifteen</li>
    <li class="draggable">Sixteen</li>
    <li class="draggable">Seventeen</li>
    <li class="draggable">Eighteen</li>
    <li class="draggable">Nineteen</li>
    <li class="draggable">Twenty</li>
      </ul>
 </div>

What I would like to do is when I am dragging any list item within the container (ie div with id="content") and when the mouse is at the edge of the div border or size, the container should also scroll so that i could move upward and downward within the container. 我想要做的是当我拖动容器中的任何列表项(即id =“content”的div)时,当鼠标位于div边框或大小的边缘时,容器也应滚动以便我可以在容器内向上和向下移动。

For example if i wanted drag the last list item in the list to the first in the list, so when the mouse is at the top end of the div edge, the container (in our case div) should also scroll automatically. 例如,如果我想将列表中的最后一个列表项拖到列表中的第一个列表项,那么当鼠标位于div边缘的顶端时,容器(在我们的例子中为div)也应该自动滚动。 Is this a bug in jquery ui draggable? 这是jquery ui draggable中的错误吗? Please help 请帮忙

Try downgrading to jQuery 1.7.2 尝试降级到jQuery 1.7.2

(Its not supposed to work with 1.8 yet I think. You can find the latest compatible version within the rar when you download jQuery UI) (我认为它不应该与1.8一起使用。当你下载jQuery UI时,你可以在rar中找到最新的兼容版本)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM