Jump to content
GreenSock

Search In
  • More options...
Find results that contain...
Find results in...
phillip_vale

Reset function with TimelineMax Timeline

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.
×