等待jQueryanimation内循环完成 [英] Wait for a jQueryanimation to complete within for loop
本文介绍了等待jQueryanimation内循环完成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有类似如下的code
I have something like the following code
for(i=0, j=10; i<j ; i++){
$('#an-element-'+i).fadeIn();
}
我如何让这个循环中每次迭代只启动一次淡入();动画已经完成?
How do I make it so that each iteration in the loop will only start once the fadeIn(); animation has completed?
编辑 - 对不起,是我不好我没有包括'我'在环
edit---sorry my bad I had not included the 'i' in the loop
推荐答案
为
循环是同步的,但动画是异步的。你需要使用递归。
for
loops are synchronous, but animations are asynchronous. You'll need to use recursion.
var i = 0, j = 10;
(function fadeNext () {
if (i < j) {
$('#an-element-' + i++).fadeIn(fadeNext);
}
}) ();
这篇关于等待jQueryanimation内循环完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文