//scroll animations
Stacking Cards
Cards pin to the top and scale down as subsequent cards scroll underneath, creating a layered stacking effect.
"use client";
import { useRef } from "react";
import {
StackingCardItem,
StackingCards,
} from "@/registry/default/motion/stacking-cards";
const features = [
{
bg: "bg-violet-500/10",
description: "Optimized for 60fps with zero layout thrashing.",
icon: "⚡",
title: "Blazing Fast",
},
{
bg: "bg-emerald-500/10",
description: "Ships with ARIA attributes and reduced-motion support.",
icon: "♿",
title: "Accessible",
},
{
bg: "bg-sky-500/10",
description: "Stack any content — cards, text, media — whatever you need.",
icon: "🧩",
title: "Composable",
},
];
export default function StackingCardsFeatures() {
const containerRef = useRef<HTMLDivElement>(null);
return (
<div className="relative h-56 overflow-y-auto px-6" ref={containerRef}>
<StackingCards
className="mx-auto h-[500px] w-full max-w-sm"
scaleMultiplier={0.05}
scrollOptions={{ container: containerRef }}
totalCards={features.length}
>
{features.map((f, i) => (
<StackingCardItem index={i} key={f.title} topPosition={`${i * 14}px`}>
<div
className={`flex h-44 flex-col justify-between rounded-2xl border border-border ${f.bg} p-5`}
>
<span className="text-2xl">{f.icon}</span>
<div>
<h3 className="font-bold text-foreground">{f.title}</h3>
<p className="mt-0.5 text-muted-foreground text-xs">
{f.description}
</p>
</div>
</div>
</StackingCardItem>
))}
</StackingCards>
</div>
);
}
Installation
pnpm dlx shadcn@latest add @cnippet/stacking-cards
Usage
import {
StackingCardItem,
StackingCards,
} from "@/components/motion/stacking-cards";<StackingCards className="h-[300vh]" totalCards={3}>
{cards.map((card, i) => (
<StackingCardItem index={i} key={card.id} topPosition={`${5 + i * 5}%`}>
<div className="h-64 rounded-2xl border bg-card p-6">
{card.content}
</div>
</StackingCardItem>
))}
</StackingCards>Anatomy
<StackingCards totalCards={3} className="h-[300vh]"> {/* tall scroll track */}
<StackingCardItem index={0} topPosition="5%">…</StackingCardItem> {/* sticky card */}
<StackingCardItem index={1} topPosition="10%">…</StackingCardItem>
<StackingCardItem index={2} topPosition="15%">…</StackingCardItem>
</StackingCards>Good to know
totalCardsmust match the number ofStackingCardItems, and each item needs itsindex(starting at0).- The container needs enough height to scroll through, e.g.
h-[300vh]for three cards. - Give each card a slightly larger
topPositionso the stacked edges stay visible. - Cards stick with
position: sticky, so no parent between them and the scrolling element may useoverflow: hidden. - When the user has turned on reduced motion, cards still stack as you scroll but do not scale down.
Props
StackingCards
| Prop | Type | Default | Description |
|---|---|---|---|
totalCards | number | — | Total number of card items — required for scale calculations |
scaleMultiplier | number | 0.03 | How much each card shrinks relative to the one above it |
scrollOptions | UseScrollOptions | — | Options passed to Motion's useScroll — use container to scope scroll to a div |
className | string | — | Class applied to the outer container — set the height here |
StackingCardItem
| Prop | Type | Default | Description |
|---|---|---|---|
index | number | — | Zero-based position of this card in the stack |
topPosition | string | "5 + index * 3%" | CSS top value for the stacked offset (e.g. "8%", "24px") |
className | string | — | Class applied to the sticky wrapper |
Examples
Feature Cards
Three feature cards stack as you scroll, each pinning to the top while the next slides underneath.
"use client";
import { useRef } from "react";
import {
StackingCardItem,
StackingCards,
} from "@/registry/default/motion/stacking-cards";
const features = [
{
bg: "bg-violet-500/10",
description: "Optimized for 60fps with zero layout thrashing.",
icon: "⚡",
title: "Blazing Fast",
},
{
bg: "bg-emerald-500/10",
description: "Ships with ARIA attributes and reduced-motion support.",
icon: "♿",
title: "Accessible",
},
{
bg: "bg-sky-500/10",
description: "Stack any content — cards, text, media — whatever you need.",
icon: "🧩",
title: "Composable",
},
];
export default function StackingCardsFeatures() {
const containerRef = useRef<HTMLDivElement>(null);
return (
<div className="relative h-56 overflow-y-auto px-6" ref={containerRef}>
<StackingCards
className="mx-auto h-[500px] w-full max-w-sm"
scaleMultiplier={0.05}
scrollOptions={{ container: containerRef }}
totalCards={features.length}
>
{features.map((f, i) => (
<StackingCardItem index={i} key={f.title} topPosition={`${i * 14}px`}>
<div
className={`flex h-44 flex-col justify-between rounded-2xl border border-border ${f.bg} p-5`}
>
<span className="text-2xl">{f.icon}</span>
<div>
<h3 className="font-bold text-foreground">{f.title}</h3>
<p className="mt-0.5 text-muted-foreground text-xs">
{f.description}
</p>
</div>
</div>
</StackingCardItem>
))}
</StackingCards>
</div>
);
}
Testimonial Cards
Customer quotes stack on scroll with subtle scaling, ideal for social proof sections.
"use client";
import { useRef } from "react";
import {
StackingCardItem,
StackingCards,
} from "@/registry/default/motion/stacking-cards";
const testimonials = [
{
name: "Alex Chen",
quote:
"The animation quality is exceptional. Dropped it into production in minutes.",
role: "Frontend Engineer",
},
{
name: "Maria Garcia",
quote: "Finally, a component library that doesn't fight the design system.",
role: "Product Designer",
},
{
name: "James Kim",
quote: "Copy-paste components with zero configuration. This is the future.",
role: "Full-stack Developer",
},
];
export default function StackingCardsTestimonials() {
const containerRef = useRef<HTMLDivElement>(null);
return (
<div className="relative h-56 overflow-y-auto px-6" ref={containerRef}>
<StackingCards
className="mx-auto h-[500px] w-full max-w-sm"
scaleMultiplier={0.05}
scrollOptions={{ container: containerRef }}
totalCards={testimonials.length}
>
{testimonials.map((t, i) => (
<StackingCardItem index={i} key={t.name} topPosition={`${i * 14}px`}>
<div className="flex h-44 flex-col justify-between rounded-2xl border border-border bg-card p-5 shadow-sm">
<p className="text-muted-foreground text-sm italic">
“{t.quote}”
</p>
<div>
<p className="font-semibold text-foreground text-sm">
{t.name}
</p>
<p className="text-muted-foreground text-xs">{t.role}</p>
</div>
</div>
</StackingCardItem>
))}
</StackingCards>
</div>
);
}
Process Steps
Numbered steps stack sequentially on scroll, guiding users through a flow one step at a time.
"use client";
import { useRef } from "react";
import {
StackingCardItem,
StackingCards,
} from "@/registry/default/motion/stacking-cards";
const steps = [
{
description: "Explore 164 animated components across 14 categories.",
step: "01",
title: "Browse",
},
{
description: "Run npx shadcn@latest add @cnippet/<component> to add it.",
step: "02",
title: "Install",
},
{
description: "Adjust props, variants, and Tailwind classes freely.",
step: "03",
title: "Customise",
},
{
description: "Deploy production-ready animations with confidence.",
step: "04",
title: "Ship",
},
];
export default function StackingCardsSteps() {
const containerRef = useRef<HTMLDivElement>(null);
return (
<div className="relative h-56 overflow-y-auto px-6" ref={containerRef}>
<StackingCards
className="mx-auto h-[600px] w-full max-w-sm"
scaleMultiplier={0.04}
scrollOptions={{ container: containerRef }}
totalCards={steps.length}
>
{steps.map((s, i) => (
<StackingCardItem index={i} key={s.step} topPosition={`${i * 14}px`}>
<div className="flex h-32 items-start gap-4 rounded-2xl border border-border bg-card p-5">
<span className="font-black text-3xl text-primary/20">
{s.step}
</span>
<div>
<h3 className="font-bold text-foreground">{s.title}</h3>
<p className="mt-0.5 text-muted-foreground text-xs">
{s.description}
</p>
</div>
</div>
</StackingCardItem>
))}
</StackingCards>
</div>
);
}