Share Posted September 7, 2018 Hi, I'm trying to use scrollTo in React. But I can't make the increment value to works with scrollTo... Here is the function that not working: handleClick = () => { let incrementNumber = 500 TweenMax.to('content', 0.5, { scrollTo: { x:'+='+incrementNumber } }); } Here is the function that can works if I just use a fixed number, but like this I can make the scrollTo increase 500px every time I click it: handleClick = () => { TweenMax.to('content', 0.5, { scrollTo: { x:500} }); } Link to comment Share on other sites More sharing options...
Share Posted September 7, 2018 Hi, Actually this has nothing to do with React (how about that React is not the culprit, who would have suspected?? ) but with the fact that the ScrollTo Plugin doesn't work with relative values like a regular tween using the CSS Plugin, that's why the first code you posted doesn't work (it actually doesn't work with or without React) and the second snippet does. What you can do is access the scrollLeft property of the target element and add the increment value to that: TweenMax.to(content, 0.5, { scrollTo: { x: (content.scrollLeft + incrementNumber) } }); That should do the trick. Let us know how that works. Happy Tweening!!! 4 Link to comment Share on other sites More sharing options...
Share Posted September 7, 2018 Sorry about any confusion there - I can make ScrollToPlugin accommodate relative values like that in the next release. In the mean time, feel free to use @Rodrigo's suggestion (though I think he meant "scrollLeft" rather than "scrollTop") 4 Link to comment Share on other sites More sharing options...
Share Posted September 7, 2018 1 minute ago, GreenSock said: though I think he meant "scrollLeft" rather than "scrollTop" Indeed... the blunder has been corrected master!!! 2 3 Link to comment Share on other sites More sharing options...
Author Share Posted September 9, 2018 Tested @Rodrigo answer and it works well! Thanks Rodrigo! ? It's weird that I stumble upon multiple answers are told to use the solution like what I insert there...maybe they didn't test it out... 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