How do I chain or queue custom functions using JQuery?

前端 未结 15 1421
暗喜
暗喜 2020-12-04 19:49

I have multiple functions the do different animations to different parts of the HTML. I would like to chain or queue these functions so they will run the animations sequenti

15条回答
  •  借酒劲吻你
    2020-12-04 20:36

    Assuming you want to keep One and Two as separate functions, you could do something like this:

    function One(callback) {
        $('div#animateTest1').animate({ left: '+=200' }, 2000, 
            function(e) { callback(); });
    }
    function Two() {
        $('div#animateTest2').animate({ width: '+=200' }, 2000);
    }
    
    // Call these functions sequentially so that the animations
    // in One() run b/f the animations in Two()
        One(Two);
    

提交回复
热议问题