Capítulo 182 de 411
When a SplitText instance re-splits (e.g. via autoSplit on resize), any animation nested inside a Timeline that referenced the old split elements becomes stale. This helper wraps SplitText with an animate() method that automatically swaps a fresh animation into the same timeline position when a re-split happens, killing the old one.
SplitTextAnimator(target, config) takes the same config as SplitText.create() and forces autoSplit: true..animate(callback) method — the callback receives the current split (self) and must return the GSAP animation to run; that returned animation is what gets added to your timeline.animate() callback re-runs automatically, and its new returned animation replaces the old one at the same timeline position.let split = SplitTextAnimator(target, { type: "words,lines", autoSplit: true });
let tl = gsap.timeline();
tl.add(split.animate((self) => gsap.to(self.words, { opacity: 1, stagger: 0.05 })));