Jump to content


Restart timeline

Go to solution Solved by OSUblake,

Warning: Please note

This thread was started before GSAP 3 was released. Some information, especially the syntax, may be out of date for GSAP 3. Please see the GSAP 3 migration guide and release notes for more information about how to update the code to GSAP 3's syntax. 

Recommended Posts

I'm new to JS and GSAP so good chance I'm missing something basic. I'm trying to restart the timeline when the if statement is true. The console.log fires but not the function. 


Thanks for the help :)


See the Pen aJYBzN by gram3000 (@gram3000) on CodePen

Link to comment
Share on other sites

  • Solution

You have some logic errors going there.


But first, don't use setTimeout/setInterval for animations. It's not synced to the animation frames, and can cause problems if the users switches tabs and comes back later. Use TweenLite.delayedCall() instead. 


About your logic problem. You're declaring a new timeline on each call to your carousel function, then you have an if statement with a call to restart the timeline, then you declare the animations for that new timeline. The if statement is restarting the timeline, there's just no animations to restart because you're declaring them after the if statement.


If all you're trying to do is cycle through some animations, you could probably do it all in a loop like this...

See the Pen ryZZmy?editors=0010 by osublake (@osublake) on CodePen



  • Like 5
Link to comment
Share on other sites

Looks like I've got lots to learn :) Thanks so much for providing a solution for me. I didn't understand how the if statement wrapping the timeline was creating a new instance each time the function ran.


Thanks so much for your guidance on JS :)



  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.