Created
October 29, 2020 15:25
-
-
Save mattgperry/6e4315f402bd65356e29054cf32c22a4 to your computer and use it in GitHub Desktop.
TextSplit
This file contains hidden or 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
'The animator’s JavaScript toolbox.'.split('').map((character, i) => ( | |
<TaglineCharacter index={i} key={i} character={character} /> | |
)) | |
function TaglineCharacter({ character, index }) { | |
const ref = useRef(null); | |
useEffect(() => { | |
const controls = animate({ | |
from: 0, | |
to: 0, | |
velocity: -500, | |
stiffness: 120, | |
elapsed: -index * 20, | |
onUpdate: (y) => | |
(ref.current.style.transform = `translateY(${y}px) translateZ(0)`), | |
}); | |
return () => controls.stop(); | |
}, []); | |
return ( | |
<span | |
ref={ref} | |
className="hl" | |
style={{ | |
display: 'inline-block', | |
width: character === ' ' ? 8 : 'auto', | |
}} | |
> | |
{character} | |
</span> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is with Popmotion but you can imagine a similar approach ditching the
useEffect
and usingmotion.span
instead