Copies›Card Stack Scroll

Card Stack Scroll

Cards pin to the top and pile into a stack as the page scrolls, each buried card shrinking and dimming; uses the existing scroller, never its own box.

Copy a ready prompt for Claude Code, Codex or Cursor

Seen on

Skiper UI

Dependencies

reacttailwindcssmotion

Interaction type

scroll

Install via CLI

pnpm dlx shadcn@latest add @copia/card-stack-scroll

Without the namespace: npx shadcn@latest add https://copia-ui.vercel.app/r/card-stack-scroll.json

How to use

demo.tsx
import { CardStackScroll, type CardStackScrollProps } from "./card-stack-scroll"

/** Free photos from Lummi (lummi.ai); authors in meta.json → assets. */
const CARDS = [
  { file: "intense-eye", title: "Look closer" },
  { file: "textured-glass", title: "Glass" },
  { file: "contrasting-vision", title: "Contrast" },
  { file: "metallic-droplets", title: "Chrome" },
  { file: "close-up-eye", title: "Detail" },
]

const items = CARDS.map((card, i) => (
  <div key={card.file} className="relative size-full">
    {/* eslint-disable-next-line @next/next/no-img-element */}
    <img src={`/demo/card-stack-scroll/${card.file}.webp`} alt="" draggable={false} className="absolute inset-0 size-full object-cover" />
    <div className="absolute inset-0 bg-gradient-to-t from-black/50 to-transparent" />
    <div className="absolute inset-x-6 bottom-5 flex items-end justify-between text-white">
      <span className="text-3xl font-medium">{card.title}</span>
      <span className="font-mono text-xs">0{i + 1}</span>
    </div>
  </div>
))

export default function Demo(props: Pick<CardStackScrollProps, "top" | "peek" | "scaleStep" | "autoScroll">) {
  return (
    <div className="flex-1 px-4">
      <div className="flex h-[45vh] flex-col items-center justify-end gap-3 pb-10">
        <span className="text-center text-[10px] tracking-widest text-muted-foreground uppercase">
          Scroll down
          <br />
          to see the card stack
        </span>
        <span className="h-12 w-px bg-muted-foreground/50" />
      </div>
      <CardStackScroll autoScroll={160} {...props} items={items} className="mx-auto w-full max-w-2xl" />
    </div>
  )
}

Customization

Use the sliders button at the top right of the preview to tweak top, peek, scaleStep, autoScroll live and copy the generated JSX.

Props

PropTypeDefaultDescription
itemsReactNode[]-Card contents.
cardHeightnumber | string"min(60vh, 420px)"Card height: pixels or any CSS length.
topnumber24Distance from the top of the scroll area where cards pin (px).
peeknumber16Offset between stacked cards (px).
scaleStepnumber0.05Shrink per buried card.
autoScrollnumber-Scroll the page on its own (px/s) until the user interacts.

Attribution

Inspired by Skiper UI. Recreated by Copia.

Demo images by westkast, nikadominguez_, berol-oac, rena.

Read how it was reverse engineered

Source code

card-stack-scroll.tsx
"use client"

import { useEffect, useLayoutEffect, useRef } from "react"
import { motion, useReducedMotion, useScroll, useTransform, type MotionValue } from "motion/react"
import { cn } from "@/lib/utils"

export type CardStackScrollProps = {
  items: React.ReactNode[]
  /** Card height: pixels or any CSS length (e.g. "60vh"). */
  cardHeight?: number | string
  /** Distance from the top of the scroll area where cards pin (px). */
  top?: number
  /** Vertical offset between stacked cards (px). */
  peek?: number
  /** How much each buried card shrinks. */
  scaleStep?: number
  /** Scroll the page slowly on its own until the user interacts (px per second). */
  autoScroll?: number
  className?: string
}

/** Nearest ancestor that actually scrolls, or null for the window. */
function getScrollParent(el: HTMLElement | null): HTMLElement | null {
  for (let node = el?.parentElement; node; node = node.parentElement) {
    const { overflowY } = getComputedStyle(node)
    if ((overflowY === "auto" || overflowY === "scroll") && node.scrollHeight > node.clientHeight) return node
  }
  return null
}

/**
 * Cards pin near the top and pile up into a stack as the page scrolls.
 * Uses whatever already scrolls (the window or a scrolling parent); it never
 * creates its own scroll box.
 */
export function CardStackScroll({ items, cardHeight = "min(60vh, 420px)", top = 24, peek = 16, scaleStep = 0.05, autoScroll, className }: CardStackScrollProps) {
  const list = useRef<HTMLDivElement>(null)
  const scroller = useRef<HTMLElement | null>(null)
  const reduceMotion = useReducedMotion()

  // Runs before useScroll subscribes, so it tracks the right scroller.
  useLayoutEffect(() => {
    scroller.current = getScrollParent(list.current)
  }, [])

  const { scrollYProgress } = useScroll({ container: scroller, target: list, offset: ["start start", "end end"] })

  useEffect(() => {
    if (!autoScroll || reduceMotion) return
    const el = scroller.current ?? document.scrollingElement ?? document.documentElement
    let frame = 0
    let last = performance.now()
    let position = el.scrollTop // float accumulator: scrollTop may snap to whole pixels
    let stopped = false
    const stop = () => (stopped = true)
    const step = (now: number) => {
      if (stopped) return
      const max = el.scrollHeight - el.clientHeight
      position = position >= max - 1 ? 0 : position + (autoScroll * (now - last)) / 1000
      el.scrollTop = position
      last = now
      frame = requestAnimationFrame(step)
    }
    frame = requestAnimationFrame(step)
    const events = ["wheel", "pointerdown", "touchstart", "keydown"] as const
    events.forEach((type) => window.addEventListener(type, stop, { once: true, capture: true }))
    return () => {
      cancelAnimationFrame(frame)
      events.forEach((type) => window.removeEventListener(type, stop, { capture: true }))
    }
  }, [autoScroll, reduceMotion])

  const height = typeof cardHeight === "number" ? `${cardHeight}px` : cardHeight

  return (
    <div ref={list} className={cn("relative flex flex-col gap-10", className)} style={{ paddingBottom: `calc(100vh - ${height} - ${top}px)` }}>
      {items.map((item, i) => (
        <StackCard key={i} index={i} count={items.length} progress={scrollYProgress} top={top + i * peek} scaleStep={scaleStep} height={height}>
          {item}
        </StackCard>
      ))}
    </div>
  )
}

function StackCard({ index, count, progress, top, scaleStep, height, children }: { index: number; count: number; progress: MotionValue<number>; top: number; scaleStep: number; height: string; children: React.ReactNode }) {
  // Each card starts shrinking once the cards after it begin to cover it.
  const start = index / count
  const scale = useTransform(progress, [start, 1], [1, 1 - (count - 1 - index) * scaleStep])
  const filter = useTransform(progress, [start, 1], ["brightness(1)", `brightness(${1 - (count - 1 - index) * 0.08})`])
  return (
    <div className="sticky" style={{ top, height }}>
      <motion.div className="size-full origin-top overflow-hidden rounded-3xl shadow-[0_-8px_30px_rgb(0_0_0/0.25)]" style={{ scale, filter }}>
        {children}
      </motion.div>
    </div>
  )
}

Keep in mind

Most components here are recreations of the best interfaces out there. We don't claim to be the original creators: this is our attempt to reverse engineer, replicate and often add a few features. We credit everyone we can; if we missed someone, let us know.

Contact

Found a bug or a missing credit? Open an issue

License & usage

  • — Free to use and modify in personal and commercial projects (MIT).
  • — No attribution required, but a link back to Copia is appreciated.
  • — Demo images are not part of the license; replace them with your own.
PreviousLiquid Glass CarouselNext Cursor Trail
Scroll down
to see the card stack
Look closer01
Glass02
Contrast03
Chrome04
Detail05