reasonable animation system

This commit is contained in:
2026-03-13 19:42:22 +01:00
parent 166ae50c49
commit e0e32d16e2
7 changed files with 93 additions and 55 deletions

View File

@@ -1,24 +1,25 @@
import { useGSAP } from "@gsap/react"; import { useRef } from "react";
import { useGSAP } from "@gsap/react"; import { useEffect, useLayoutEffect, useRef } from "react";
import { useGsapContext } from "~/app/_providers/GsapProvicer";
import { SplitText } from "gsap/SplitText";
import gsap from 'gsap'
const AnimatedPageTitle = (
{ text }: { text: string }
{ text, position }: { text: string, position:gsap.Position }
) => {
const el = useRef<HTMLHeadingElement>(null)
const gsapContext = useGsapContext();
useGSAP(() => {
console.log("add animated title with:",position)
const tl = gsap.timeline();
tl.addLabel("title")
const split = new SplitText(el.current, { type: "chars" })
tl.to(el.current, { opacity: 100 })
tl.from(el.current, { opacity: 0 })
tl.from(split.chars, {
stagger: 0.05, rotate: -90, opacity: 0, x: -10
}, '>')
gsapContext?.addAnimation(tl)
}, { scope: el })
gsapContext?.addAnimation(tl,position)
})
return (
<h1 className="text-4xl opacity-0 font-bold text-balance w-full" ref={el}> {text} </h1>
<h1 className="text-4xl opacity-100 font-bold text-balance w-full" ref={el}> {text} </h1>
)
}