据我目前了解 $("#someElement").animate() 它将相对于任何其他 JavaScript 语句异步执行。例如:
$("#anotherElement").css("display", "none");
$("#someElement").animate();
//Setting the CSS display may fire AFTER the animation takes place.
如果我对动画工作原理的理解是正确的,我该如何:
- 使动画与我的代码的其余部分同步运行?
- 如果我想要排序影响不同元素的动画,如何同步它们以按给定顺序运行?
感谢您的帮助。
最佳答案
- 不可以,您无法同步运行动画(仅限回调)。
- 对此行为使用回调。
示例:
$('#elem1').animate(params, function () {
$('#elem2').animate(params, function () {/* ...other elements */});
});
关于javascript - 同步 JQuery 动画的好方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1561315/