简体   繁体   English

在同一位置交换来自分开的div的可拖动项

[英]Swap draggable items from separated div`s in the same position

I tried to make a nice example for Draggable jQuery with Bootstrap, it's working fine till now but what I need to make is: 我试图为带有Bootstrap的Draggable jQuery做一个很好的例子,到现在为止一切正常,但是我需要做的是:

  1. Swap the div s <div class='col-sm-12'></div> that I created between the div.cart with same place. 在我的div.cart之间的同一位置交换div<div class='col-sm-12'></div>

  2. Can add 1 item only in one div.cart . 只能在一个div.cart添加1个项目。

Demo 演示

 $(function() { $("#catalog div").draggable({ appendTo: "body", helper: "clone" }); $(".cart ").droppable({ hoverClass: "ui-state-hover", accept: ":not(.ui-sortable-helper)", drop: function(event, ui) { $(this).find(".RemoveDIV").remove(); $("<div class='col-sm-4'></div>").text(ui.draggable.text()).appendTo(this); } }) .sortable({ connectWith: ".cart" }).sortable({ items: " > div" }); }); 
 #products { float: left; width: 500px; margin-right: 2em; background-color: yellow; } #cart { margin-top: 1em; background-color: #B3B3B3; height: 200px; } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <script src="http://code.jquery.com/ui/1.11.2/jquery-ui.js"></script> <link href="http://code.jquery.com/ui/1.11.2/themes/smoothness/jquery-ui.css" rel="stylesheet"/> <div class="container" style="height:220px;background-color:gray;"> <div id="catalog"> <div> <div class="col-sm-3 color">Test1</div> <div class="col-sm-3 color1">Test2</div> <div class="col-sm-3 color">Test3</div> </div> </div> </div> <div id="bigContainer"> <div class="container" style=" margin-top:10px;"> <div class="cart col-sm-6" style="height:250px;background-color:#043F35;"> <div class="RemoveDIV">Add your items here</div> </div> <div class="cart col-sm-6" style="height:250px;background-color:#BC0F76;"> <div class="RemoveDIV">Add your items here</div> </div> </div> </div> 

I think that you could achieve your goal editing accept property of droppable in this way 我认为您可以通过这种方式实现您的目标编辑droppable的accept属性

accept: function(draggable) {
        return $(this).find(".col-sm-4").length == 0;
}

in this way the function will allow the draggable elements only if there is no element with class col-sm-4 inside it 以这种方式,该函数仅在其中不存在带有col-sm-4类的元素时才允许可拖动元素

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

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