jQuery 动画多个选择器
我什至不知道如何表达这个问题。下面的代码具有我想要的效果,但它完全多余且丑陋,我不知道如何使它更优雅一点。我尝试了 while 循环但没有成功。也许是递归函数或者有更好的方法来做到这一点?
function next() {
$('#scroll_wrapper li:first-child').animate({
'top' : -elemHeight-offSet
}, {duration: 1000, queue: false, complete: nextDone});
$('#scroll_wrapper li:nth-child(2)').animate({
'top' : offSet
}, { duration: 1000, queue: false });
$('#scroll_wrapper li:nth-child(3)').animate({
'top' : offSet2
}, { duration: 1000, queue: false });
function nextDone() {
var d = $(this).detach();
d.appendTo('#scroll_wrapper ul').css({'top' : elemHeight+100});
}
}
I'm not even sure how to phrase this question. The code below has the desired effect I want, but it's completely redundant and ugly, and I'm not sure how to make it a little more elegant. I've tried a while loop without success. Maybe a recursive function or is there a better way to do this?
function next() {
$('#scroll_wrapper li:first-child').animate({
'top' : -elemHeight-offSet
}, {duration: 1000, queue: false, complete: nextDone});
$('#scroll_wrapper li:nth-child(2)').animate({
'top' : offSet
}, { duration: 1000, queue: false });
$('#scroll_wrapper li:nth-child(3)').animate({
'top' : offSet2
}, { duration: 1000, queue: false });
function nextDone() {
var d = $(this).detach();
d.appendTo('#scroll_wrapper ul').css({'top' : elemHeight+100});
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
像这样的东西可能会起作用:
不过,可以说它更复杂。
Something like this might work:
Though, arguably it's more complex.