Can someone help, I'm trying to avoid the flesh of the text on the screen (FOUC). Also I'm trying to animate the text one by one, but seems like the timeline does not work as it supposed to.
'use client'
import gsap from 'gsap-trial'
import { useGSAP } from '@gsap/react'
import { useRef } from 'react'
import SplitText from 'gsap-trial/SplitText'
gsap.registerPlugin(SplitText)
export default function Page() {
const container = useRef<HTMLElement | null>(null)
const tl = useRef<GSAPTimeline | null>(null)
useGSAP(
() => {
const titles = gsap.utils.toArray<Element>('p', container.current)
titles.forEach(title => {
const splitTitle = new SplitText(title)
tl.current = gsap
.timeline()
.from(
splitTitle.lines,
{ opacity: 0, y: 20, stagger: 0.02, autoAlpha: 0 },
'<'
)
.to(
splitTitle.lines,
{ opacity: 0, y: -20, stagger: 0.02, autoAlpha: 1 },
'<1'
)
})
},
{ scope: container }
)
return (
<section
ref={container}
className='flex justify-center items-center h-screen'
>
<div className='text-2xl leading-[0px] invisible'>
<p>My name is Illia</p>
<p>I am a cool guy</p>
<p>Great developer</p>
<p>and a funny fellow</p>
</div>
</section>
)
}