A kinetic typography library for ReactJS
0.1.0
Author: Me |
Link: https://mqkqw2n9qx.codesandbox.io/ |
npm i react-punch
import { animateText, samples } from "react-punch";
<b>{animateText("Hello World!",samples.emphasis.bounce(10, "ease-out", 1000, "infinite"),100)}</b>
animateClass
Triggers the animation on mount
<div
className={animateClass({
frames:{
from: { opacity: 0, transform: "scale(0,0)" },
to: { opacity: 1, transform: "scale(1,1)" },
},
easing: "cubic-bezier(0.0, 0.06, 0.05, 0.95)"
})}
/>
Triggers the animation on hover
const [hover , setHover] = useState(false);
<div
onMouseEnter={() => setHover(true)}
onMouseLeave={() => setHover(false)}
className={hover && animateClass({
frames:{
from: { opacity: 0, transform: "scale(0,0)" },
to: { opacity: 1, transform: "scale(1,1)" },
},
easing: "cubic-bezier(0.0, 0.06, 0.05, 0.95)"
})}
/>
animateElement
Triggers a succession of animations using a Promise
useEffect(() => {
const ballA = document.getElementById("ballA");
const ballB = document.getElementById("ballB");
animateElement(
ballA,
{frames: {to: {transform: "translateX(100px)"}}}
).then(() => {
animateElement(
ballB,
{ frames: { to: { transform: "translateX(200px)" } } }
)
});
}, []);
<div id="ballA" />
<div id="ballB" />
Or using simply the duration on the delay property
useEffect(() => {
const ballA = document.getElementById("ballA");
const ballB = document.getElementById("ballB");
animateElement(
ballA,
{frames: {to: {transform: "translateX(100px)"}}, duration: 1000}
);
animateElement(
ballB,
{frames: {to: {transform: "translateX(200px)"}}, delay: 1000}
)
}, []);
<div id="ballA" />
<div id="ballB" />
animateText
Triggers an animation on each letter of the text
<b>{animateText("Hello World!", samples.emphasis.rubber(), 500)}</b>
Or on the whole word
<b>{animateText("Hello World!", samples.emphasis.rubber(), 0)}</b>