3
感覺就像問題是已經回答:jQueryUI:如何將可放置區域限制爲多個div?
- How to select multiple areas in containment using jQuery UI draggable
- Set more than one containment in jQuery Draggable
我有3個時間表和一些可拖動的元素放在那裏。出於某種原因,我無法讓它工作。這是我使用的語法:containment: ".timeline1, .timeline2, .timeline3"
$(function() {
$(".timeline1, .timeline2, .timeline3").droppable();
$(".event").draggable({
containment: ".timeline1, .timeline2, .timeline3"
});
});
.timeline1, .timeline2, .timeline3 {
width: 500px;
height: 40px;
border: 3px dashed gray;
margin-bottom: 10px;
}
.event {
height: 40px;
background: gray;
display: inline-block;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/jquery-ui.min.js"></script>
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/themes/smoothness/jquery-ui.css" />
<div class="timeline1"></div>
<div class="timeline2"></div>
<div class="timeline3"></div>
<div class="event">dance</div>
<div class="event">sleep</div>
<div class="event">eat</div>
更新的文檔中發現:http://api.jqueryui.com/draggable/#option-containment
可拖動的元素會被包含到邊框的邊框第一個元素由選擇器發現
問題仍然有效,我真的想知道如何限制droppable區域多個div?
太棒了! ''''span''',''snapMode'''和'''revert'''的組合完成這項工作:) – 2015-02-08 09:27:36