【发布时间】:2011-01-03 20:48:21
【问题描述】:
当框“一”被拖放到框“二”上时,下面的极简工作示例交换了两个框。问题是当盒子'one'被丢弃时,它的样式有'top'和'left'值,导致它被放置在远离它应该丢弃的地方。它的类包括“ui-draggable-dragging”。似乎顶部和左侧的值与放置前拖动元素的数量有关。并且拖动被“中断”,因此剩余的“ui-draggable-dragging”类?
为了让交换无缝工作,我缺少什么? full jsfiddle example here
<html>
<head>
<script type="text/javascript" src="includes/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="includes/jquery-ui-1.8.2.custom.min.js"></script>
<script type="text/javascript">
jQuery.fn.swapWith = function(to) {
return this.each(function() {
var copy_to = $(to).clone(true);
var copy_from = $(this).clone(true);
$(to).replaceWith(copy_from);
$(this).replaceWith(copy_to);
});
};
$(document).ready(function() {
options = {revert: true};
$("li").draggable(options)
$('#wrapper').droppable({
drop: function(event, ui) {
$(ui.draggable).swapWith($('#two'));
}
});
});
</script>
</head>
<body>
<form>
<ul id="wrapper">
<li id='one'>
<div style="width: 100px; height: 100px; border: 1px solid green">
one<br /></div>
</li>
<li id='two'>
<div style="width: 110px; height: 110px; border: 1px solid red">
two<br /></div>
</li>
</ul>
<br />
</form>
</body>
</html>
【问题讨论】: