Please use Desktop to view and interact with components
Page Transitions400msspring
Auto-Revealing Heading
Heading that reveals each letter/word with staggered motion on scroll
headingrevealstaggerscroll
Useto navigate between components
Preview
AutoRevealingHeading
Code
TypeScript + React
'use client'
import { useRef } from 'react'
import { motion, useInView } from 'framer-motion'
export function AutoRevealingHeading() {
const ref = useRef(null)
const isInView = useInView(ref, { once: true, margin: '-100px' })
const text = 'Auto Revealing Heading'
const words = text.split(' ')
const containerVariants = {
hidden: { opacity: 0 },
visible: {
opacity: 1,
transition: { staggerChildren: 0.1 },
},
}
const itemVariants = {
hidden: { opacity: 0, y: 20 },
visible: {
opacity: 1,
y: 0,
transition: { type: 'spring', stiffness: 300, damping: 25 },
},
}
return (
<motion.div
ref={ref}
variants={containerVariants}
initial="hidden"
animate={isInView ? 'visible' : 'hidden'}
>
{words.map((word, index) => (
<motion.span
key={index}
variants={itemVariants}
className="inline-block"
style={{ marginRight: '0.25em' }}
>
{word}
</motion.span>
))}
</motion.div>
)
}
How to Use
- 1Install Framer Motion:
npm install framer-motion - 2Copy the code from above
- 3Paste it into your project and customize as needed
- 4Colors are customizable via Tailwind CSS classes. The default theme uses dark mode colors defined in your globals.css file