JQuery synchronous animation

前端 未结 7 1929
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-29 07:00

In many cases I wish animation to be executed synchronously. Especially when I wish to make a a series of sequential animations.

Is there an easy way to make a jQuer

7条回答
  •  隐瞒了意图╮
    2020-11-29 07:10

    jQuery cannot make synchronous animations.

    Remember that JavaScript runs on the browser's UI thread.

    If you make a synchronous animation, the browser will freeze until the animation finishes.

    Why do you need to do this?

    You should probably use jQuery's callback parameter and continue your method code in the callback, like this:

    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;
        });
    }
    

    This is called a closure.

提交回复
热议问题