JQueryUI:放入容器内、追加和恢复
我被 JQueryUI 困住了。具体来说,我剪掉了以下 html:
<div class="from">
<div class"item">Item 1</div>
<div class"item">Item 2</div>
<div class"item">Item 3</div>
</div>
<div class="to"></div>
现在我想通过 JQueryUI 库使项目可拖放到“to”框中。因此,我使用这个 javascript 片段:
$('.item').draggable({
revert: true
});
$('.to').droppable({
drop: function(event, ui) {
ui.draggable.appendTo(this);
}
});
虽然就结果而言这工作得很好,但处理“恢复”的动画并没有按照我想要的方式运行。问题在于,拖动显然是通过设置“position:relative”然后更改“top”和“left”CSS属性来实现的。一旦该项目附加到新容器(这发生在恢复动画之前),它就会跳转到新位置,因为它现在相对于新容器定位。恢复动画现在从新位置开始。
将项目附加到新容器后,有什么方法可以实现平滑的恢复动画吗?也许我的处理方式完全错误,所以请毫不犹豫地提出任何不同的方法。
我一直在尝试根据新容器的绝对位置重新计算 css left 和 top 属性,但这当然仅适用于第一个删除的项目,第二个项目还必须考虑第一个项目的位置。
谢谢。
I got stuck with JQueryUI. Specifically, I have the following html snipped:
<div class="from">
<div class"item">Item 1</div>
<div class"item">Item 2</div>
<div class"item">Item 3</div>
</div>
<div class="to"></div>
Now I want to make the items draggable and droppable on the "to" box via the JQueryUI library. Therefore, I use this javascript snippet:
$('.item').draggable({
revert: true
});
$('.to').droppable({
drop: function(event, ui) {
ui.draggable.appendTo(this);
}
});
While this works perfectly as far as the result is concerned, the animation handling the 'revert' doesn't behave as I want it to. The problem is that dragging is obviously implemented by setting "position: relative" and then changing 'top' and 'left' css properties. As soon as the item is attached to the new container (which happens before the revert animation), it jumps to a new position because it's now positioned relatively to the new container. The revert animation now starts at the new position.
Is there any way I can have a smooth revert animation after attaching the item to a new container? Perhaps I am going about this completely the wrong way, so please don't hesitate to suggest any different approach.
I have been trying to recalculate the css left and top properties based on the new containers absolute position, but this of course works only for the first dropped item, the second one would additionally have to consider the first item's position.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论