Sayeem Posted August 17, 2023 Share Posted August 17, 2023 Can you please convert this code to react. im not able to create horizontal scroll trigger for box-1 like it is there in the (URL) example... See the Pen WNjaxKp by GreenSock (@GreenSock) on CodePen Link to comment Share on other sites More sharing options...
GSAP Helper Posted August 17, 2023 Share Posted August 17, 2023 Hi @Sayeem and welcome to the GreenSock forums! Unfortunately we don't have the time resources to create custom solutions or convert a specific example to X or Y framework. Here are a few tips that should help and a link to some valuable resources for using GSAP with react. Proper animation cleanup is very important with frameworks, but especially with React. React 18 runs in strict mode locally by default which causes your useEffect() and useLayoutEffect() to get called TWICE. In GSAP 3.11, we introduced a new gsap.context() feature that helps make animation cleanup a breeze. All you need to do is wrap your code in a context call. All GSAP animations and ScrollTriggers created within the function get collected up in that context so that you can easily revert() ALL of them at once. Here's the structure: // typically it's best to useLayoutEffect() instead of useEffect() to have React render the initial state properly from the very start. useLayoutEffect(() => { let ctx = gsap.context(() => { // all your GSAP animation code here }); return () => ctx.revert(); // <- cleanup! }, []); This pattern follows React's best practices, and one of the React team members chimed in here if you'd like more background. We strongly recommend reading the React information we've put together at https://greensock.com/react Finally keep in mind that react is just JavaScript, the caveat lays just when and where the code should go and be executed. I strongly recommend you to understand the container animation feature, not just the example above, and experiment with it. Then get a good grasp about using GSAP and ScrollTrigger in react and you'll have enough to create a container animation in react. There is a learning curve, no doubt about it, but is not super steep. Happy tweening! Link to comment Share on other sites More sharing options...
Sayeem Posted August 18, 2023 Author Share Posted August 18, 2023 thanks for teh help! will follow the advice diligently... 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