Jquery UI可拖动不滚动可排序容器

Man*_*ain 4 jquery jquery-ui jquery-ui-sortable jquery-draggable

我有一些可拖动的项目(#draggable li),我将它们拖放到可排序的(#sortable)中.

sortable由两个div包装,最外面的div有overflow-y:scroll.拖放机制工作正常,直到可排序列表扩展和滚动.

当我尝试拖动并直接在可排序项上放置一个项目时,我无法使用可排序的滚动条以我想要的方式自动滚动(比如想要上升到第一个元素上方或者下降到下方最后一个元素).但是当我尝试在它们之间拖动和排序项目时,滚动条会在拖动时自动滚动.

它是一个错误还是我的代码工作方式有错.

这是完整的代码:

<body>
    <ul id="draggable" class="connectedSortable">
        <li class="ui-state-default big">Item 1</li>
        <li class="ui-state-default big">Item 2</li>
        <li class="ui-state-default big">Item 3</li>
        <li class="ui-state-default big">Item 4</li>
        <li class="ui-state-default big">Item 5</li>
        <li class="ui-state-default big">Item 6</li>
    </ul>

  <div id="outerDiv">
    <div id="innerDiv">
      <ul id="sortable" class="connectedSortable">
      </ul>
    </div>
  </div>
</body>
Run Code Online (Sandbox Code Playgroud)

// CSS

#sortable, #draggable { 
  list-style-type: none; 
  margin: 0; 
  padding: 0 0 2.5em; 
  margin-right: 10px; 
}
#sortable li, #draggable li { 
  margin: 0 5px 5px 5px; 
  padding: 5px; 
  font-size: 1.2em; 
  width: 120px; 
}
.marker{
    background: none repeat scroll 0 0 #DDDDDD;
    border-bottom: 1px solid #BBBBBB;
    border-top: 1px solid #BBBBBB;
    display: block;
    height: 20px;
    width: 100%;
    text-align: center;
    vertical-align: middle;
    color: #666;
    font-size: 18px;
    font-style: italic;
}

#outerDiv{
    background: none repeat scroll 0 0 #EEEEEE;
    height: 100%;
    right: 0;
    position: absolute;
    overflow-y: scroll; 
    top: 0;
    width: 300px;
}

#innerDiv{
    border: 1px solid #CCCCCC;
    min-height: 400px;
    position:absolute;
}
#sortable{
    width: 200px;
    padding: 10px;
    border : 1px solid black;
    min-height: 230px;
}

#draggable{
    position:absolute;
    top:0;
    left:0;
}
.big{
    height: 80px;
}
Run Code Online (Sandbox Code Playgroud)

// JS

$(function() {
  $( "#sortable" ).sortable({
       placeholder: "marker",
       axis: "y",
  });

  $("#draggable li").draggable({
      helper: "clone",
      cursor: "move",
      revert: "invalid",
      revertDuration: 500,
      connectToSortable: "#sortable"
  });
});
Run Code Online (Sandbox Code Playgroud)

小提琴演示http://jsfiddle.net/8KDJK/21/

任何帮助将不胜感激.谢谢 :)

sde*_*ont 6

我不确定它是一个错误,但它不是一个经典的场景.

几个月前我花了很多时间找到一个解决方法,这是我的解决方案:http://jsfiddle.net/8KDJK/23/

它现在正在工作几个月没有问题.

我们的想法是元素克隆追加到滚动容器durring助手建设的回调,然后用setTimeout函数1毫秒后,能够将所有拖动网页周围的助手追加到身体.

  $("#draggable li").draggable({
      cursor: "move",
      revert: "invalid",
      revertDuration: 500,
      connectToSortable: "#sortable",

      //Here is the workaround 
      //**********************

      containment: 'body',
      helper: function(){ 
        //Hack to append the element to the body (visible above others divs), 
        //but still bellonging to the scrollable container  
        $('#sortable').append('<div id="clone" class="ui-state-default big">' + $(this).html() + '</div>');   
        $("#clone").hide();
        setTimeout(function(){
            $('#clone').appendTo('body'); 
            $("#clone").show();
        },1);
        return $("#clone");
    }
  });
Run Code Online (Sandbox Code Playgroud)

链接到我之前的问题:JqueryUI,将元素拖动到包含大表的滚动可删除div的单元格中