让我先说我是 Javascript 新手,而不是编程新手。我调用fadeOut
这样的 jQuery 对象:
$(x).fadeOut('fast');
我还有其他事情会淡出淡出,但我需要它们相互等待,我不一定知道有多少人会这样做。x
是来自数组的字符串,其中包含淡入或淡出的项目。在我的第一次尝试中,我fadeOut
像这样使用了回调函数:
$(x).fadeOut('fast', function(){ foo(modifiedArray); })
我想要的方法在哪里foo
, modifiedArray 是数组 minus x
。但这仍然没有让它等待,所以接下来我尝试了:
$(x).fadeOut('fast');
while( $(x).css('display') != 'none' ){}
foo(modifiedArray);
但循环永远不会结束。如何让动画在我foo(modifiedArray)
再次调用之前等待?
编辑:这是完整的代码
function animateElements(elements){
if (elements.length == 1){
var x = elements[0];
$(x).fadeIn('slow');
}
else{
var x = elements.pop();
$(x).fadeOut('fast');
while( $(x).css('display') != 'none' ){}
animateElements(elements);
}
}