Skip to content
Knowns UI
Get ProSign in

Scroll Stage

A hook for scroll-driven motion without a scroll library. useScrollStage maps the scroll through a section to a progress from 0 to 1 and hands it to your render function, which writes transforms and opacity. Every stage on a page shares one frame loop that reads before it writes and skips what is off screen, and under reduced motion the final state shows at once.

On this page
Used for
  • A pinned product story
  • A self-drawing path
  • A run replayed by scroll
  • A camera pan across a floor
  • Beats inside a preview pane

Examples

Easing

Inside a scroll container

The demo above scrolls inside its own frame. Pass the container as root so the progress is measured against it and the stage listens to its scroll, not the window's.

From a smooth-scroll library

The hook never changes how the page scrolls. If your app already runs a smooth-scroll library, pass its scroll event as subscribe: a function that takes a listener and returns the unsubscribe. Keep it stable (define it once, outside the component or in a memo).

TSX
// Defined once, next to where the library starts.
const onSmoothScroll = (fn: () => void) => {
  smooth.on("scroll", fn);
  return () => smooth.off("scroll", fn);
};

useScrollStage(track, render, { subscribe: onSmoothScroll });

Pass mode

mode: "pass" measures an ordinary element from the moment its top enters at the bottom of the view (0) to the moment its bottom leaves at the top (1). Use it for a path or a figure that changes as it goes by, with nothing pinned.

Installation

npx knowns-ui@latest add scroll-stage
For Claude Code, Cursor or Codex: installs it and wires the props to your own data.

Props

refrequired
RefObject<HTMLElement>
The track (pin mode: a tall element with a sticky child) or the element (pass mode).
renderrequired
(progress, { reduced, el }) => void
Writes the stage for a progress from 0 to 1. Write transform, opacity or a CSS variable; read nothing from the layout here.
options.root
RefObject<HTMLElement>
Defaultwindow
A scroll container to measure against and listen to.
options.subscribe
(onScroll) => () => void
An outside scroll source. Must be a stable function.
options.mode
"pin" | "pass"
Default"pin"
How progress is measured.
options.disabled
boolean
Defaultfalse
Pause the stage.
useScrollStep(ref, steps, options)
number
Default0
The step index from a count or a list of thresholds; re-renders only when it changes. The last step under reduced motion.
useReducedScroll()
boolean
Defaultfalse
True after mount when reduced motion is on: switch a pinned layout to a stacked one.
beat(p, from, to, ease?)
number
0 before the window, 1 after it, eased between (SCROLL_EASE.out by default).
SCROLL_EASE
{ out, inOut, linear }
The motion tokens as easing functions. bezierEase(x1, y1, x2, y2) builds another from a cubic-bezier.
stageProgress, stepIndex, mix
functions
The pure maths, exported for tests and custom stages.

Accessibility

  • Keep the content in DOM order and visible without JavaScript: hide a beat only from the render function, never in the server markup.
  • Under reduced motion the hook renders the final state once. Unpin the stage and stack its beats with useReducedScroll, so nothing depends on scrolling.
  • A scroll container in the page needs a name and tabIndex 0, so keyboard users can scroll it.
  • Numbers written from the render function are aria-hidden; announce a step change with a polite live region at most.

What it handles

  1. 01Turns the scroll through a section into one progress number from 0 to 1, for a tall track with a pinned child or for an element passing through the view.
  2. 02Runs one animation frame loop per scroll source for every stage on it: all rects are read first, then every stage whose progress moved is rendered.
  3. 03Skips stages off screen, and gives a stage one last frame as it leaves so a fast fling still lands it on its first or last state.
  4. 04Writes beats as windows of progress, eased on the motion tokens with bezierEase, never as time.
  5. 05Steps discrete changes with useScrollStep, which re-renders only when the step changes.
  6. 06Works inside a scroll container (a docs frame, a preview pane) and from an outside scroll source, without changing how the page scrolls.

States

First render
The stage paints at its current progress, with no entrance
none
Scroll
render(progress) writes transforms and opacity in the next frame
one frame, no easing in time
Off screen
Not measured and not rendered
none
Leaving the view
One last frame at 0 or 1
one frame
Reduced motion
render(1) once with reduced: true; no listener. Unpin and stack the beats in your layout
0ms

Works with

When to use

When to use

  • A pinned section that tells a product story in beats as the visitor scrolls: a release rolling out, a run replayed, a camera moving across a floor.
  • A figure that changes as it passes through the view, such as a path drawing itself or a chart growing, inside the page or a scroll container.

When not to use

  • A section that only needs to appear once as it comes into view: a scroll reveal is enough.
  • A pinned title with a product window rising under it, ready made: use Scroll-over Hero.

Using with AI

Use Copy page for AI above to give your assistant this page, Copy prompt under the install command to have it installed and wired to your data, or connect the Knowns UI MCP server and just ask:

  • Add the Knowns UI Scroll Stage to my app and wire it to my own data.
  • I need a pinned section that tells a product story in beats as the visitor scrolls: a release rolling out, a run replayed, a camera moving across a floor. Set that up with the Knowns UI Scroll Stage.
  • Which Scroll Stage props do I need for a minimal setup? Show me a short example.

With the server connected, your assistant calls get_component({ name: "scroll-stage" }) and search_docs({ query: "scroll stage" }).

Need help?

Stuck on Scroll Stage, or found something off? We read every message.