javascript - 同步 JQuery 动画的好方法是什么?

标签 javascript jquery

据我目前了解 $("#someElement").animate() 它将相对于任何其他 JavaScript 语句异步执行。例如:

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

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

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

如果我对动画工作原理的理解是正确的,我该如何:

  1. 使动画与我的代码的其余部分同步运行?
  2. 如果我想要排序影响不同元素的动画,如何同步它们以按给定顺序运行?

感谢您的帮助。

最佳答案

  1. 不可以,您无法同步运行动画(仅限回调)。
  2. 对此行为使用回调。

示例:

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

关于javascript - 同步 JQuery 动画的好方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1561315/

相关文章:

javascript - 数据表中的 fnAddData() 添加到同一行而不是添加到新行

javascript - HTML 选择,在 DOM 中选择了正确的选项,但在 Firefox 中显示了错误的项目

javascript - 使用jquery从菜单切换div

javascript - rails : How to confirm email address entered in text box matches current user's email address?

javascript - 如何在 mvc razor View 中从 IEnumerable<model> 返回带有索引的模型?

javascript - 字母解码Javascript

javascript - 如何在 android/三星手机的 html 文本输入字段中停止自动大写?

javascript - 如何使输入中的输入显示在输出上

javascript - 从其他站点获取 JSON(P)

javascript - 如何调用保存在单独文件中的 JavaScript?