我有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。怎么做?
答案 0 :(得分:4)
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>