JQuery synchronous animation

前端 未结 7 1926
爱一瞬间的悲伤
爱一瞬间的悲伤 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条回答
  •  Happy的楠姐
    2020-11-29 07:13

    I think you should take a look at the jQuery queue() method.

    Not only does queue()'s doc explain jQuery animations don't really block the UI, and actually queues them after one another.

    It also provides with a way to make your animations and function calls sequential (this is my best understanding of what you mean by "synchronous"), like:

    $("#myThrobber")
        .show("slow")                 // provide user feedback 
        .queue( myNotAnimatedMethod ) // do some heavy duty processing
        .hide("slow");                // provide user feedback (job's 
    
    myNotAnimatedMethod() { // or animated, just whatever you want anyhow...
        // do stuff
        // ...
    
        // tells #myThrobber's ("this") queue your method "returns", 
        // and the next method in the queue (the "hide" animation) can be processed
        $(this).dequeue();
    
        // do more stuff here that needs not be sequentially done *before* hide()
        // 
    }  
    

    This is of course overkill with asynchronous processing; but if your method is actually a plain old synchronous javascript method, that could be the way to do it.

    Hope this helps, and sorry for my poor english...

提交回复
热议问题