anir Posted November 10, 2023 Share Posted November 10, 2023 const animation = gsap.to(node, { x: width, scrollTrigger: { trigger: '#our_clients_section', start: 'center bottom', end: 'bottom top', scrub: 3, onUpdate: (self) => { distanceTrainCrossed = parseInt(self.animation?._targets[0]._gsap.x) } } }) I need the distanceTrainCrossed sync with train object latest position, but as there is scrub enabled of 3s. During the scrub, the onUpdate function not firing. so i can't get the latest position. Link to comment Share on other sites More sharing options...
mvaneijgen Posted November 10, 2023 Share Posted November 10, 2023 Hi @anir welcome to the forum! Please provide a minimal demo when posting a question, that way we can dive directly in to your code instead of having to create a demo our selfs first. This saves time for everyone and gets you more chance of getting an answer on this forum! What is it you want to do exactly? You should never use properties with an underscore (_) these are only for internal use and could change in the future. Do you just want to get the value of the property you're animating? Check out `gsap.getProperty()` (https://gsap.com/docs/v3/GSAP/gsap.getProperty()/) Hope it helps and happy tweening! See the Pen KKJmoww?editors=0010 by mvaneijgen (@mvaneijgen) on CodePen 1 Link to comment Share on other sites More sharing options...
anir Posted November 10, 2023 Author Share Posted November 10, 2023 Thank you for your explanation @mvaneijgen . And sorry for the inconvenience for the last explanation. Link to comment Share on other sites More sharing options...
GreenSock Posted November 10, 2023 Share Posted November 10, 2023 Just to be clear, the ScrollTrigger's onUpdate fires every time the scroll position updates whereas the tween's onUpdate fires every time the playhead moves on the tween. So it sounds like you just need to move your onUpdate from the ScrollTrigger to the tween: const animation = gsap.to(node, { x: width, onUpdate() { distanceTrainCrossed = parseInt(gsap.getProperty(node, "x")) }, scrollTrigger: { trigger: '#our_clients_section', start: 'center bottom', end: 'bottom top', scrub: 3 } }) Does that help? 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now