Flip Text
Text flipping character animation
Flip Text
Installation
Copy and paste the following code into your project.
"use client"
import { AnimatePresence, Variants, motion } from "framer-motion"
import { cn } from "@/lib/utils"
interface FlipTextProps {
word: string
duration?: number
delayMultiple?: number
framerProps?: Variants
className?: string
}
export function FlipText({
word,
duration = 0.5,
delayMultiple = 0.08,
framerProps = {
hidden: { rotateX: -90, opacity: 0 },
visible: { rotateX: 0, opacity: 1 },
},
className,
}: FlipTextProps) {
return (
<div className="flex justify-center space-x-2">
<AnimatePresence mode="wait">
{word.split("").map((char, i) => (
<motion.span
key={i}
initial="hidden"
animate="visible"
exit="hidden"
variants={framerProps}
transition={{ duration, delay: i * delayMultiple }}
className={cn("origin-center drop-shadow-sm", className)}
>
{char}
</motion.span>
))}
</AnimatePresence>
</div>
)
}
Update the import paths to match your project setup.
Props
Prop | Type | Description | Default |
---|---|---|---|
className | string | The class name to be applied to the component | |
duration | number | Duration of the animation | 0.2 |
delayMultiple | number | Transition delay multiplier. | 0.08 |
word | string | An array of words to rotate through | "" |
framerProps | HTMLMotionProps | An object containing framer-motion animation props |