如何等待一个jQuery的动画完成下一个开始之前? [英] How to wait for one jquery animation to finish before the next one begins?
本文介绍了如何等待一个jQuery的动画完成下一个开始之前?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下jQuery的:
I have the following jQuery:
$("#div1").animate({ width: '160' }, 200).animate({ width: 'toggle' }, 300 );
$("#div2").animate({ width: 'toggle' }, 300).animate({ width: '150' }, 200);
我的问题是,无论发生在同一时间。我想DIV2动画时,第一个完成启动。我试着下面的方法,但它做同样的事情:
My issue is that both happen at the same time. I would like the div2 animation to start when the first one finishes. I've tried the method below, but it does the same thing:
$("#div1").animate({ width: '160' }, 200).animate({ width: 'toggle' }, 300, ShowDiv() );
....
function ShowDiv(){
$("#div2").animate({ width: 'toggle' }, 300).animate({ width: '150' }, 200);
}
我
如何使它等待第一个完成?
How can I make it wait for the first one to finish?
推荐答案
http://api.jquery.com/animate/一>
有生有一个完整的功能。你应该放置第二个动画第一的功能齐全。
animate has a "complete" function. You should place the 2nd animation in the complete function of the first.
编辑:例如 http://jsfiddle.net/xgJns/
$("#div1").animate({opacity:.1},1000,function(){
$("#div2").animate({opacity:.1},1000);
});
这篇关于如何等待一个jQuery的动画完成下一个开始之前?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文