在很多情况下我希望动画能够同步执行。特别是当我想制作一系列连续的动画时。
有没有一种简单的方法来制作 jQueryanimate
函数调用同步?
我想到的唯一方法是在动画完成时将标志设置为 true 并等待该标志。
jQuery 无法制作同步动画。
请记住,JavaScript 在浏览器的 UI 线程上运行。
如果您制作同步动画,浏览器将冻结,直到动画完成。
为什么需要这样做?
您可能应该使用 jQuery 的回调参数并在回调中继续您的方法代码,如下所示:
function doSomething() {
var thingy = whatever;
//Do things
$('something').animate({ width: 70 }, function() {
//jQuery will call this method after the animation finishes.
//You can continue your code here.
//You can even access variables from the outer function
thingy = thingy.fiddle;
});
}
这称为闭包。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)