Jump to content
Search Community

Tracking values while animating

sandbucks test
Moderator Tag

Go to solution Solved by mvaneijgen,

Recommended Posts

Hi all!

 

I feel like this should be a simple one so maybe I'm overlooking something obvious. Basically I have an animation using gsap.to(...), and I'm hoping to track the value/s I'm animating as they animate. I figured this would make sense to be done in the onUpdate() callback, but I'm goofily having trouble figuring out how to get the value (in this case, x) as it animates. 

 

tldr: if I animate my div's 'x' position from 0 to 150, is there a way to log/use the values in between those two numbers as they're reached during the animation?

 

I saw an older forum answer or two about a _gsTransform property that I can't seem to find, guessing it may be deprecated.

 

Thanks!

See the Pen wvNzWyp by Stuart-Mackinnon (@Stuart-Mackinnon) on CodePen

Link to comment
Share on other sites

Hi,

 

There are a couple of reasons for not having a way like this.x to track the value of a property being tweened.

 

  1. Performance. GSAP Tweens are mostly read-only. While you can update the values of certain properties, those are not a lot for a performance reason. A GSAP instance updates 60 times every seconds, which is the amount of times it updates the value being tweened. If you had to update the instance itself it would be super wasteful. Imagine have 100 tweens and you're tweening 4 different values on each. That's a lot of updates! On top of that you would have to include all the code to actually conduct that into the GSAP core.
  2. Name collisions. Keep in mind that GSAP can tween the numeric value of any property of any JS object. A GSAP instance has, among other properties, a timeScale property, which you can actually tween! A GSAP instance is just a JS object and timeScale is a numeric value. So if you're updating the timeScale property that you are tweening you do this:
    this.timeScale = someValue;
    But which Time Scale is that, the target's or the parent Tween? See how this can get really messy really fast?

The getProperty() method is the best way we offer to do this and keep in mind that it basically means calling a simple method on an element which is super fast actually so there isn't a lot of downside, unless you are tracking literally thousands of elements at the same time, which honestly I never even tried, so checking the  of a couple of properties in a few elements shouldn't really cause any type of bottlenecks.

 

We're always thinking and trying different ways to improve GSAP which means keeping our eyes and ears open for suggestions, which we always are thankful for, because it shows an engaged community and users that are paramount to GSAP as their goto animation tool, which we love! But at the same time se are super careful about performance and adding extra KB in the tools for features that don't make a lot of sense or can be solved in a good way already

 

Hopefully this helps.

Happy Tweening!

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