Last active
April 7, 2023 03:15
-
-
Save TylerBarnes/82ccdb4046a32f178c538f2f8536663b to your computer and use it in GitHub Desktop.
GSAP ScrambleTextPlugin in React with Hooks
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
import React, { useRef, useEffect } from "react"; | |
import TweenLite from "gsap"; | |
import "../../libs/gsap/ScrambleTextPlugin"; | |
export default ({ children }) => { | |
if (typeof window === "undefined") return children; | |
const text = useRef(null); | |
useEffect(() => { | |
TweenLite.to(text.current, 1.2, { | |
scrambleText: { | |
text: children, | |
chars: children, | |
revealDelay: 1, | |
speed: 0.5 | |
} | |
}); | |
}); | |
return <span ref={text}>{children}</span>; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment