开发者

What is a good approach to synchronizing JQuery Animations?

As I currently understand $("#someElement").animate() it will execute asynchronously relative to any other JavaScript statements. For instance:

$("#anotherElement").css("display", "none");

$("#someElement").animate(); 

//Setting the CSS display may fire AFTER the animation takes place.

If I am correct in my understanding of how开发者_如何学JAVA animations work, how do I:

  1. Make the animations run synchronously with the rest of my code?
  2. If I have animations that I'd like to order that affect different elements how do I synchronize them to run in a given order?

Thanks for the help.


  1. No, you can not run animation synchronously (callbacks only).
  2. Use callbacks for this behaviour.

Sample:

$('#elem1').animate(params, function () {
    $('#elem2').animate(params, function () {/* ...other elements */});
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜