Jump to content
Search Community

Tween up/down through a list of numbers

smallio 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

I've done most of the hard lifting here, instead of going +5 or -5 I want to be able to cycle through a list of numbers with no correlation to each other-

 

var numbers = ["330",  "477",  "20",  "128",  "8"]

 

Preferably I'd like to count up/down between values in the thousands/millions, so a big bonus would be to represent them with a k or and m at the end. 

 

For Example:

var numbers = ["330",  "477",  "20",  "128",  "8"]

var values = ["k",  "k",  "m",  "k",  "m"]

 

But outputting like: (number, value) or 330k, 447k, 20m etc... 

 

I've stripped down the example to like 20 lines of code to it's easy to see what's going on. My guess is I'd have to do the k/m separately and output in a separate field next to it, if there's an easier way I'd love to know though! 

 

Cheers,

Will 

 

See the Pen jZQjJV?editors=0010 by smallio (@smallio) on CodePen

Link to comment
Share on other sites

If you want it to be fancy, when going eg. from 20km to 20m, you could make it tween down to 1 and have an onComplete callback that changes "km" to "m" and starts a new tween from 1000 to 20 :)

 

edit: I just realised I invented "km" ! oh well, the logic still works with m and k :P

  • Like 3
Link to comment
Share on other sites

2 minutes ago, Acccent said:

If you want it to be fancy, when going eg. from 20km to 20m, you could make it tween down to 1 and have an onComplete callback that changes "km" to "m" and starts a new tween from 1000 to 20 :)

 

Oooo nice idea!!! I'll see if I can implement that :)

  • Like 1
Link to comment
Share on other sites

10 minutes ago, Sahil said:

Here is how you can do it, if you don't want decimal points there is line you can uncomment. Also noticed slight issue with logic in @Acccent's demo, numbers won't animate on first click if you click back and forth on both buttons.

 

See the Pen BYGXBj?editors=0110 by Sahil89 (@Sahil89) on CodePen

 

 

I feel like I'm a parrot at this stage just repeating thank you to some of you guys, but seriously, THANK YOU!!!  You don't even know how much I appreciate the contributions. Things like this can take hours for a noob like me to figure out & being able to see stuff like this is totally invaluable. Gratz on mod status & Superhero as well btw. 

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