Last active
October 21, 2023 19:58
-
-
Save HadalyVillasclaras/c51ff80ff25b71362c47ef0fa31a7f75 to your computer and use it in GitHub Desktop.
GSAP context simple implementation in React
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const elementRef = useRef(null); | |
const tl1Ref = useRef(null); | |
const tl2Ref = useRef(null); | |
useLayoutEffect(() => { | |
tl1Ref.current = gsap.timeline(); | |
gsap.set(elementRef.current, { y: "100%", opacity: 1 }); | |
const ctx = gsap.context(() => { | |
tl1Ref.current | |
.to(elementRef.current, { | |
onStart: () => { | |
console.log('Start!'); | |
}, | |
y: "0%", | |
duration: 0.8 | |
}, 0) | |
.to(elementRef.current, { | |
delay: 2.3, | |
y: "-150%", | |
ease: "power2.out", | |
}, ">-0.2"); | |
}, parentRef.current); | |
return () => { | |
ctx.revert(); | |
}; | |
}, []); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment