2

我有 div:

<div class="sortable container">
    <div class="line">
        content
    </div>
    <div class="line">
        content
    </div>
</div>
<div class="sortable container">
    <div class="line">
        content
    </div>
    <div class="line">
        content
    </div>
    <div class="line">
        content
    </div>
    <div class="line">
        content
    </div>
</div>
<div class="sortable container">
    <div class="line">
        content
    </div>
    <div class="line">
        content
    </div>
    <div class="line">
        content
    </div>
    <div class="line">
        content
    </div>
</div>

和js:

$(function() {
    $(".sortable").sortable();
    $(".sortable").disableSelection();
});

这项工作很好 - 我可以拖放“线” div,但我想在“容器” div 之间拖动这个 div。怎么做?

4

1 回答 1

5

jQuery UI 可排序页面有一个关于连接列表的完整示例:http: //jqueryui.com/demos/sortable/#connect-lists

从那里提取:

<style>
    #sortable1, #sortable2 { list-style-type: none; margin: 0; padding: 0 0 2.5em; float: left; margin-right: 10px; }
    #sortable1 li, #sortable2 li { margin: 0 5px 5px 5px; padding: 5px; font-size: 1.2em; width: 120px; }
</style>
<script>
    $(function() {
        $( "#sortable1, #sortable2" ).sortable({
            connectWith: ".connectedSortable"
        }).disableSelection();
    });
</script>
<div class="demo">

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

<ul id="sortable2" class="connectedSortable">
    <li class="ui-state-highlight">Item 1</li>
    <li class="ui-state-highlight">Item 2</li>
    <li class="ui-state-highlight">Item 3</li>
    <li class="ui-state-highlight">Item 4</li>
    <li class="ui-state-highlight">Item 5</li>
</ul>
于 2012-09-27T16:34:46.753 回答