Search code examples
javascriptjqueryfunctiongsapsuperscrollorama

jquery start a function only after one function completes


I was wondering if it was possible to have a function start only after the previous function completed. I have two functions listed below that I'm trying to run one after the other. Thanks!

                var controller = $.superscrollorama();


                controller.addTween('#graphicOne', TweenMax.from( $('#graphicOne'), .7, {css:{right:'1000px'}, ease:Back.easeOut}));
                controller.addTween('#graphicTwo', TweenMax.from( $('#graphicTwo'), .7, {css:{left:'1000px'}, ease:Back.easeOut})); 
                controller.addTween('#graphicThree', TweenMax.from( $('#graphicThree'), .7, {css:{right:'1000px'}, ease:Back.easeOut}));        
            }

Function 2:

        function footerAnimation() {
            TweenMax.from( $('#footerTextLight'), .7, {css:{opacity:'0'}})
        }

Solution

  • use onComplete callback

    controller.addTween(
           '#graphicThree', 
           TweenMax.from( $('#graphicThree'), .7, 
                         {
                         css:{right:'1000px'},
                         ease:Back.easeOut, 
                         onComplete : footerAnimation
                        }
                      )
           );
    

    Pass in a function to the tween for when the animation is complete.

    http://johnpolacek.github.io/superscrollorama/