在动画回调完成之前触发 jquery 循环进行迭代?
我正在尝试制作一个顺序动画,其中循环遍历元素列表 .post
并缓慢淡出它们。困难的部分是让下一个迭代在上一个迭代完成淡入之前开始淡入。到目前为止,我所拥有的只是一个简单的顺序动画器,可以将它们一个接一个地淡入淡出。
$(".post").hide();
var posts = $(".post"),
i = 0;
(function() {
$(posts[i++]).fadeIn('slow', arguments.callee);
})();
有谁知道我如何更改此设置以允许 .post
在前面的 elem/s 完成之前淡入()?
I am trying to make a sequential animation, where a loop iterates through a list of elements .post
's and fades them in slow. The difficult part is having it so that the next iteration begins fading in before the last one has finished fading. All I have so far is a simple sequential animator that fades them in one after the other.
$(".post").hide();
var posts = $(".post"),
i = 0;
(function() {
$(posts[i++]).fadeIn('slow', arguments.callee);
})();
Does anyone know how I could change this to allow .post
to fadeIn() before the previous elem/s have finished?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用
each()
迭代它们,并为每一个使用setTimeout()
,将动画的持续时间乘以当前的index
每个。因此,每个
setTimeout()
的持续时间为n*600
,这应该会给您带来您想要的效果。顺便说一句,如果您不需要
posts
变量用于任何其他目的,您可以消除它并将.each()
链接在之后>.hide()
,如$(".post").hide().each(func...)
编辑: 我有一个错误。我在
setTimeout()
中使用了this
,它具有不同的值。编辑以传递正确的值。编辑:误读了问题。将
setTimeout()
的持续时间更改为300
以在动画中提供部分重叠。Iterate over them using
each()
and use asetTimeout()
for each one, multiplying the duration of the animation by the currentindex
in the each.So each
setTimeout()
will have a duration ofn*600
, which should give you the effect you want.By the way, if you don't need the
posts
variable for any other purpose, you can eliminate it and chain the.each()
after the.hide()
, as in$(".post").hide().each(func...)
EDIT: I had an error. I was using
this
inside thesetTimeout()
which has a different value. Edited to pass in the correct value.EDIT: Mis-read the question. Changed the duration of
setTimeout()
to300
to give a partial overlap in the animations.与帕特里克的解决方案类似,但我认为
演示(
300
) 更干净一些是延迟的持续时间,其中'slow'
是淡入淡出的持续时间Similar to patrick's solution, but a little cleaner in my opinion
demo, the
300
is the duration of the delay where as the'slow'
is the duration of the fade