Share Posted October 15, 2022 Hello, Like you can see, Product Image Placeholder is jumping when animation started. Still trying to figure out but can't find a way how to solve it. Demo: https://codesandbox.io/s/whdnt2 Link to comment Share on other sites More sharing options...
Solution Solution Share Posted October 15, 2022 Hey, Replace your useEffect with this and it should probably work as you wanted it to. useEffect(() => { const element = parent.current let ctx = gsap.context(() => { gsap.to('.title', { opacity: 0, scale: 0.7, delay: 0.5, ease: 'power1.out', scrollTrigger: { trigger: '.title', markers: true, scrub: true, start: 'top top', end: 'bottom top' } }) gsap.to('.image', { scrollTrigger: { trigger: '.productImage', markers: true, scrub: 2, start: 'top top', end: '+=400', pin: true }, scale: 1.3 }) }, parent) return () => ctx.revert() }, []) For further reading you can check this link out, it will definitely help you out. 2 1 Link to comment Share on other sites More sharing options...
Share Posted October 15, 2022 Welcome to the forums, @schwarzsky. It looks like you're getting bitten by React 18's new double-useEffect() call behavior, so you're effectively creating multiple duplicated ScrollTriggers/Tweens. Don't worry - it's easy to fix. In GSAP 3.11, we introduced a new gsap.context() feature that makes it super easy to do cleanup operations to prevent this kind of thing. Here's a fork: https://codesandbox.io/s/blockbud-co-landing-forked-ertbb1?file=/pages/index.js Ah, it looks like @alig01 just beat me to it! Nice! 🙌 You also might want to read our React guide: Happy tweening! 2 1 Link to comment Share on other sites More sharing options...
Author Share Posted October 15, 2022 Thanks to both of you guys! It worked. I have an another question too, like you can see in `.image` animation i am pinning object to screen. But i want to position object smoothly in center of the screen, stay like that a 100-200px and stay in last position (end state). But i don't know how to position object smoothly in center of the secreen, how i can accomphlish this kinda effect? By smoothly, i mean like editing y position smoothly in GSAP. 1 Link to comment Share on other sites More sharing options...
Share Posted October 15, 2022 If I understood you correctly, it sounds to me like you are describing the CSS property position: sticky to me. codesandbox I've included a small example and added a timeline where you can put all kinds of transformations, as needed. 1 Link to comment Share on other sites More sharing options...
Author Share Posted October 15, 2022 By `.image`, i mean the div with the `.image` class. Your codesandbox explains how to center an item but i can't figure out how to do it for existing div. I wanted to center object when animation is going on. Thanks for the help! I created a new demo in case you guys wanna look. https://codesandbox.io/s/9v134x In this one, object pins correctly into screen but i still can't figure out how to center it into screen. Link to comment Share on other sites More sharing options...
Share Posted October 15, 2022 You want it to start pinning/scaling when the top of the image hits the top of the viewport, and you want it to move to the center of the viewport vertically? https://codesandbox.io/s/blockbud-co-landing-forked-r4zx1s?file=/pages/index.js 1 Link to comment Share on other sites More sharing options...
Author Share Posted October 15, 2022 1 hour ago, GreenSock said: You want it to start pinning/scaling when the top of the image hits the top of the viewport, and you want it to move to the center of the viewport vertically? https://codesandbox.io/s/blockbud-co-landing-forked-r4zx1s?file=/pages/index.js Thank you so much and also sorry for my complex langugage 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