Skip to content

Instantly share code, notes, and snippets.

@HadalyVillasclaras
Last active October 21, 2023 19:58
Show Gist options
  • Save HadalyVillasclaras/c51ff80ff25b71362c47ef0fa31a7f75 to your computer and use it in GitHub Desktop.
Save HadalyVillasclaras/c51ff80ff25b71362c47ef0fa31a7f75 to your computer and use it in GitHub Desktop.
GSAP context simple implementation in React
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