【发布时间】:2012-11-06 22:19:12
【问题描述】:
我有以下代码来为动态 div 上下设置动画。这个想法是,可能有任意数量的 div 需要在堆栈上上下移动,与上下的 div 交换位置。一旦处于他们的新位置,我需要能够赶上那个新的重新定位的位置。以下代码一次有效,但是一旦较低的 div 向上移动并且较高的 div 向下移动(交换点)到新位置,它们就会停止工作。我该如何设置它,以便他们继续向上遍历堆栈,在他们去的时候交换紧接在上面或下面的那个?一旦完成更新数据库,我还需要知道新职位。我一直在到处寻找,但似乎找不到如何做到这一点。任何帮助将不胜感激。
$('.editUp', this).click(function() {
thisRowHt = $(this).parents('.rowCont').outerHeight();
upperRowHt = $(this).parents('.rowCont').prev().outerHeight();
$(this).parents('.rowCont').animate({'top': '-=' + thisRowHt + 'px'});
$(this).parents('.rowCont').prev().animate({'top': '+=' + upperRowHt + 'px'});
return false;
});
$('.editDown', this).click(function() {
thisRowHt = $(this).parents('.rowCont').outerHeight();
lowerRowHt = $(this).parents('.rowCont').next().outerHeight();
$(this).parents('.rowCont').animate({'top': '+=' + lowerRowHt + 'px'});
$(this).parents('.rowCont').next().animate({'top': '-=' + thisRowHt + 'px'});
return false;
});
【问题讨论】:
-
将演示放在 jsfiddle.net 中,以便其他人可以看到您遇到的问题
-
你试过了吗? jqueryui.com/sortable 真的好用 :)
标签: jquery jquery-animate