2
我在我的jQuery代码中遇到了一个问题。在jquery中拖放和排序DIVs
我需要在包含一些卡片的页面两侧有2个div。我应该能够从左边的拖放到右边的拖放。卡必须克隆,以便原始卡保持原位。
此外卡应该可排序的div内排序,最后我需要有一个列表说明在左边的div中的项目的顺序。
但这里是我的问题:拖放工程,但我不能有2个相同的项目,我的排序不起作用。
这里是我的代码:
$(function drag() {
$(".item").draggable({
cursor:'move',
helper:'clone',
});
});
$(function drop(){
$("#droppable").droppable({
drop:function (event, ui) {
ui.draggable.clone().appendTo($(this)).draggable();
}
});
});
$(function sort(){
$('.item#droppable').sortable();
$('.item#droppable').disableSelection();
});
.item{width:70px; height:100px; border-radius:10%; margin:auto; margin-top:11.5%;}
.red{background-color:red;}
.blue{background-color:blue;}
.black{background-color:black;}
.green{background-color:green;}
.yellow{background-color:yellow;}
#droppable{width:150px; height:600px; border:1px black solid; float:left;}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.0/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/jquery-ui-git.js" />
<div id="draggable">
<div class="item red" draggable="true">
</div>
<div class="item blue" draggable="true">
</div>
<div class="item black" draggable="true">
</div>
<div class="item green" draggable="true">
</div>
<div class="item yellow" draggable="true">
</div>
</div>
<div id="droppable">
</div>
感谢您的回答,但它仍然不能有相同的多个项目颜色,不能排序。任何想法如何解决? – Mamrez
@Mamrez类(颜色)没有问题,只为每个div使用唯一的ID。 –
它的工作原理,但在正确的div。我需要左边的div可排序 – Mamrez