Scroll story
Scroll story
A how-it-works section that tells itself as you scroll: steps light up at the middle, a rail fills, and one card reshapes into each step’s picture.
Dependencies
Interaction states
- reading line — The middle of the view (wide), or 42% down what the sticky picture leaves (narrow). The last step whose top has crossed it is the active one.
- rail — A 1px track from the first dot to the last; the fill follows the reading line on every scroll frame (written straight to the DOM, no re-render). Dots fill and the active one grows to 1.15× with a slight overshoot.
- steps — Inactive steps at 35% opacity, the active one at full (400ms).
- picture — The card eases its width and height to the new picture (460ms); the old one blurs out and shrinks to 0.97 (240ms) while the new one rises 10px out of a 4px blur (420ms, 90ms in). The counter rolls.
- narrow — Under 520px of width the picture sticks to the top at 46% of the view with a thin line under it, and the steps scroll beneath.
Installation
Add this component with your preferred package manager.
pnpm dlx shadcn@4.21.5 add @cavemio/scroll-storyFirst install? Configure @cavemio once
Run npx shadcn@4.21.5 init if shadcn is not set up, then merge this entry into the registries field in your existing components.json. Keep your other settings and registries.
{
"registries": {
"@cavemio": "https://registry.cavemio.dev/r/cavemio-{name}.json"
}
}Where it’s used
How-it-works sections
Explain a product in steps on a landing page.
Product tours
A sticky picture that changes as each step comes into view.
Long-form explainers
Case studies and feature write-ups with a picture for each part.
Onboarding and docs pages
Walk through a setup in the order it should happen.
What it handles
- The step in the middle lights up — Whichever step crosses the middle of the view is at full strength, and the others wait at about a third.
- A rail that fills — A thin line down the side fills with the scroll and each step’s dot fills as the line reaches it.
- One picture that reshapes — The card eases to the size of each step’s picture while the old one blurs out and the new one rises in.
- Pictures that play when their step arrives — Each picture mounts when its step becomes active, so a switch flipping or a count rolling plays right then.
- A phone layout — On narrow screens the picture sticks to the top and the steps scroll beneath it.
- Tap a step to go there — Titles are buttons that scroll their step into place, and all the words stay in the page for reading and search.
Usage
Interactive local fixture. Data and async results are simulated in the preview; the caller supplies application services.
import { ScrollStory } from "@/components/scroll-story";
<ScrollStory
steps={[
{ title: "Pick a template", body: "Start from a page that already moves.", visual: <PickTemplate /> },
{ title: "Make it yours", body: "Your name, your colour.", visual: <MakeYours /> },
{ title: "Go live", body: "Push it and watch the first visitors arrive.", visual: <GoLive /> },
]}
/>Props
| Prop | Type | Description |
|---|---|---|
| steps | { title: string; body?: ReactNode; visual: ReactNode }[] | – · In order. Give visuals a set width (the card sizes itself to them); keep them under about 280px wide for phones. |
| side | "start" | "end" | "end" · Which side the picture sits on when there’s room for two columns. |
| onStepChange | (index: number) => void | – · Runs when a different step becomes active. |
Accessibility & motion
- It finds the nearest scrolling box itself, so it works in the page or inside a scrolling panel; give the box a height. - The active step has aria-current="step"; each title is a button that scrolls its step into place. - Every step’s words stay in the page for reading and search; only the pictures come and go. - Installs Number roll. With reduced motion the pictures swap in place and jumps don’t smooth-scroll.
pnpm dlx shadcn@4.21.5 add @cavemio/scroll-story