我需要一些帮助来理解这有什么问题。
当将项目拖放到可放置区域(模板位置)时,它会移动到另一个位置,然后当再次尝试将其拖动到正确的位置时,它会移动得更远......
例如:在我将苹果和香蕉都放到可掉落区域后,如果我将香蕉靠近苹果,它会粘在一起。
拖动项目光标移动距离项目本身很远,假设如果我没有设置光标位置,它会出现在我想要拖动项目时鼠标所在的位置,所以很奇怪......
只要 item 从 droppable 区域移出,它就需要飞回 draggable 并整齐地显示在 draggable 区域(项目列表位置)。但似乎一直锁定/不能整齐地飞回来
<link rel="stylesheet" href="http://jqueryui.com/themes/base/jquery.ui.all.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/jquery-ui.js"></script>
<style>
#droppable {
border:1px solid #000;
font-weight:bold;
background-color:#FFF;
width: 300px;
height: 400px;
padding: 0.5em;
float: left;
margin: 10px;
}
#draggable{
width:300px;
float:left;
border:1px solid #000;
background-color:#E2EBED;
padding:3px;
height:500px;
}
.dragableBox{
border:1px solid #000;
background-color:#FFF;
font-weight:bold;
text-align:center;
width:150px;
height:auto;
margin-bottom:5px;
padding:3px;
}
</style>
<script type="text/javascript">
$(function() {
//draggable setting
$( ".dragableBox" ).draggable({
revert: "invalid",
revertDuration: 1000,
cursor: "move",
delay: 200,
opacity: .45,
refreshPositions: true,
snap: true,
containment: "#droppable"
//helper: "clone"
});
//to allow item at droppable div go back to draggable div neatly.
$( "#draggable" ).droppable({
accept: '.dragableBox',
drop: function( event, ui ) {
var draggable = ui.draggable;
$("#draggable").append(ui.droppable);
}
});
//to append and show it out
$( "#droppable" ).droppable({
accept: '.dragableBox',
drop: function( event, ui ) {
var draggable = ui.draggable;
var html= 'Dropped!' + '<br>' +
'The square with ID "' + draggable.attr('id') + '" was dropped onto me!' + '<br>' +
'left:'+ ui.position.left + ' top:'+ ui.position.top;
//ajax save actual position to db for later retrieval.
$("#droppable").append(ui.draggable);
}
});
});
</script>
<div class="demo">
<div id="draggable" >
<div class="dragableBox" id="box1">apple</div>
<div class="dragableBox" id="box2">banana</div>
<div class="dragableBox" id="box2">mango</div>
</div>
<div id="droppable" >
</div>
</div>