Jump to content
Search Community

Reset function with TimelineMax Timeline

phillip_vale test
Moderator Tag

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

Hi there,

 

I am attempting to restart the #counter in this codepen example once the timeline has finished playing.

 

Ideally i would like to trigger the restart (20 secs) from the timeline.

 

I added the onComplete: "resetTimer" which is queuing this function and it didn't throw an error so i am wondering if I am on to something?

function resetTimer() {
   var seconds = 20;
}
Any help is appreciated!
 
Thanks,
 
Phil

See the Pen RaZNpX?editors=0010 by phillip_vale (@phillip_vale) on CodePen

Link to comment
Share on other sites

Hi ,

 

You are into something for sure. Nearly got it. Just a matter of organising your code a little bit and changing the callback.

 

I have forked your pen and made some alterations:

See the Pen oxebgP?editors=0010 by dipscom (@dipscom) on CodePen

 

And here were the things that were altered:

  • The scope of your seconds variable. And then, you were defining the seconds a second time inside the resetTimer(), rather than just updating it.
  • The tick() function, did not need to be nested inside the countdown() one. Unless you're creating self-contained objects, I was told it is not a good thing to go nesting functions inside functions.
  • The timeline was infinite, therefore, would never 'complete'. You would want to use a 'onRepeat' in this case.

 

Happy tweening!

  • Like 4
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.
×
×
  • Create New...