【发布时间】:2017-01-13 12:05:30
【问题描述】:
我正在使用 JQueryUI 可拖动元素,并且想选择当多个元素相互堆叠(一个在另一个之上)时,哪个可拖动元素会被拖动。
我应该在“开始”方法中做点什么吗?
$( ".draggable" ).draggable({
start: function(event, ui) {
// Is there a way I can select to drag #e2:
// so I can use program logic to select which draggable I want to get dragged
}
});
.draggable {
position: absolute;
left: 0px;
top: 0px;
width: 100px;
height: 100px;
opacity: 0.5;
font-size: 50px;
line-height: 100px;
text-align: center;
cursor: pointer;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/themes/smoothness/jquery-ui.css">
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
<div class="draggable" id="e1" style="background-color: red">1</div>
<div class="draggable" id="e2" style="background-color: green">2</div>
<div class="draggable" id="e3" style="background-color: blue">3</div>
我还粘贴了一个 jsFiddle 以进行更简单的测试: Jquery UI stacked (layered) draggables
【问题讨论】:
标签: html jquery-ui draggable jquery-ui-draggable