我有一些列表项和 id,就像正在交换的两个项目之间的幻灯片效果。
这就是我到目前为止所拥有的。这个动画第一次工作,但在那之后,最初移动的列表项的“顶部”值为 0,我不知道为什么。我认为这是原因,但不确定。一旦动画完成,我也尝试将位置设置回正常,但这也不起作用。
listItemPushed
是<li>
在上面,listItem
是在<li>
下面
listItemPushed.css('position', 'relative');
listItem.css('position', 'relative');
var top1 = listItemPushed.position().top;
var top2 = listItem.position().top;
listItemPushed.animate({ top: (top2-top1) }, 300);
listItem.animate({ top: (top1 - top2) }, 300, 'linear', function() {
listItemPushed.before(listItem);
});