Jump to content
Search Community

Speeding Countdown

LK1037 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

Does anyone know how to create a countdown that easeIn (speeds up) as it gets closer to 0 and confine the duration to a 10 second window?

 

Format:

06 HR : 00 MM : 00 SS

 

Please advise. Thanks to anyone who can shed some light on it. 

Link to comment
Share on other sites

Hey LK1037,

 

The main thing you need is the logic to count down using a time format. Maybe this thread may help you come up with that:

Once you have that in a timeline, it's easy to add easing to it and adjust the total time that it takes. You can just use a tween with the timeline as a target and apply an ease to it.

 

Feel free to post back here if you get stuck on something.

Link to comment
Share on other sites

22 minutes ago, LK1037 said:

Here's where we're at so far...

Cool, but you don't want your animation duration to be based on how many times you run a function. Instead the process should look something like this:

  1. Create a function that takes a value between 0 and 1 and outputs a time format corresponding with that percentage. It'd be easiest to create using linear easing (e.g. an input of 0.5 would output 03 00 00).
  2. Create a timeline (var tl = new TimelineMax() for example). Make sure it's paused.
  3. In the timeline's onUpdate function, send the progress to the function that you created in 1.
  4. Create a tween that animates the timeline you've created in steps 2-3 with whatever duration and ease that you'd like.

Does that seem doable?

Link to comment
Share on other sites

I think it'd be easiest to describe in code (with comments). Please let me know if you have questions.

 

See the Pen RwwPmRe?editors=0010 by GreenSock (@GreenSock) on CodePen

 

Though my above approach would also work, I realized you don't actually need a timeline. One regular tween will do just fine. So the actual steps were:

  1. Create a function that takes a value between 0 and 1 and outputs a time format corresponding with that percentage. It'd be easiest to create using linear easing (e.g. an input of 0.5 would output 03 00 00).
  2. Create a tween that animates from your start time to 0 with whatever duration and ease that you'd like.
Link to comment
Share on other sites

7 minutes ago, LK1037 said:

When I drop in the function, it removes the target placeholder—it shows for a split second, then is overtaken by the counter.

 

See what I mean?

Uh... yes. Did you read my code? You need to change where the counter is updated to whatever elements you want to use. I would suggest taking a free course on JavaScript online somewhere.

 

You also are not loading TweenMax properly. CodePen is meant to have all the things inside of your <body> in the HTML section. You can load additional JS resources by clicking the cog in the JS panel.

Link to comment
Share on other sites

Zach — after running through testing, we found that the countdown playback is inconsistent. Seems to be a Chrome issue. 

 

On initial load, the countdown is stuck at the beginning. Refresh triggers it to play all the way through as intended. Refresh causes it to get stuck. Seems to work every other time.

 

Does this have to do w/ the "pause" you mentioned? How do we fix it?

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