Please use Desktop to view and interact with components
Components300msspring
Animated Card Stack
Stacked cards that expand on hover
cardstackhovershadcn
Useto navigate between components
Preview
Card 1
First card
Hover to expand this card
Card 2
Second card
Hover to expand this card
Card 3
Third card
Hover to expand this card
This component requires shadcn/ui
This component uses shadcn/ui components. Make sure you have shadcn/ui set up in your project.
- Install shadcn/ui:
npx shadcn-ui@latest init - Install required components based on the imports in the code (e.g.,
npx shadcn-ui@latest add button) - Ensure your
tailwind.config.tsandglobals.cssare configured as per shadcn/ui documentation
Code
TypeScript + React
'use client'
import { motion } from 'framer-motion'
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'
const cards = [
{ title: 'Card 1', description: 'First card' },
{ title: 'Card 2', description: 'Second card' },
{ title: 'Card 3', description: 'Third card' },
]
export function AnimatedCardStack() {
return (
<div className="relative h-64">
{cards.map((card, index) => (
<motion.div
key={index}
initial={{ scale: 1 - index * 0.05, y: index * 10 }}
whileHover={{ scale: 1, y: -10 }}
transition={{ type: 'spring', stiffness: 300, damping: 20 }}
className="absolute w-64"
style={{ zIndex: cards.length - index }}
>
<Card>
<CardHeader>
<CardTitle className="text-lg">{card.title}</CardTitle>
<CardDescription>{card.description}</CardDescription>
</CardHeader>
<CardContent>
<p className="text-sm">Hover to expand this card</p>
</CardContent>
</Card>
</motion.div>
))}
</div>
)
}
How to Use
- 1Install Framer Motion:
npm install framer-motion - 2Set up shadcn/ui: Install shadcn/ui components used in this code. Check the imports in the code above and install the required components (e.g.,
npx shadcn-ui@latest add button card) - 3Copy the code from above
- 4Paste it into your project and customize as needed
- 5Colors are customizable via Tailwind CSS classes. The default theme uses dark mode colors defined in your globals.css file