How do I chain or queue custom functions using JQuery?

前端 未结 15 1391
暗喜
暗喜 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:26

    Really Simple Fix.

    function One() {
            $('div#animateTest1').animate({ left: '+=200' }, 2000, Two);
        }
        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();
    //We no longer need to call Two, as it will be called when 1 is completed.
        //Two();
    

提交回复
热议问题