Jump to content
Search Community

How to get prop value in timeline onUpdate() callback?

mrz test
Moderator Tag

Go to solution Solved by OSUblake,

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

Hello,

 

Ive got a timeline that animates the position of an element using left and Ive attached the onUpdate callback which triggers fine.

 

My question is how can I check the current prop value at the point of the callback, e.g. if I am animating from left:100 to left:200 and the onUpdate() is triggered 10 times, I would like to be able to see 110, 120, etc..

 

I have done a search on the forums and come across a variable assigned to the element (_gsTransform) but it doesnt have the value I am looking for (left). I have quickly gone through the timeline object but couldnt find what I was looking for.

 

I am currently working around the issue by calling getBoundingClientRect() on the element to get its current position. However I believe this causes a reflow and I want to avoid this, especially during an animation.

 

I have made a codepen example that shows it working when I use x rather than left. But this issue remains with other props like top, left, alpha, etc

See the Pen QEvRNw?editors=1111 by anon (@anon) on CodePen

Link to comment
Share on other sites

  • Solution

I am currently working around the issue by calling getBoundingClientRect() on the element to get its current position. However I believe this causes a reflow and I want to avoid this, especially during an animation.

 

Using left does the same thing. That's why using x is better. If you need to use  left, you can get it's value from your element's style.

See the Pen BzRZQg?editors=0011 by osublake (@osublake) on CodePen

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