Scroll Scene
import { ScrollScene, ScrollBeat, useSceneProgress, createTimeline, easings, range } from "pleate/effects/scroll-scene";Lisbon to Porto
Scroll the page: three cues pin the train at each station and the distance reads off the scroll. Scroll back up and it runs backwards.
The scroll moves the train
Each point of the scroll is one point of the line, so the train covers the same distance however fast you scroll.
Three cues
Lisbon, Coimbra and Porto pin where the train is. Everything in between is blended from them.
Back is backwards
Scroll up and the train runs back the way it came. Nothing here runs on a timer.
Props
- ScrollScene stage
The pinned layer, as wide and tall as the viewport: a ThreeScene, a video, a drawing.
ReactNode- ScrollScene children
Laid over the stage, usually ScrollBeats.
ReactNode- ScrollScene length / offset / label
Viewport heights of scrolling the pin lasts, the sticky header above it, and the section's name.
number / number (px) / stringdefault 3 / 0- ScrollBeat from / to
The stretch of the scene where the beat shows.
number (0..1)- ScrollBeat fade / distance
Share of the scene spent fading in and out, and how far it rises.
number / number (px)default 0.04 / 16- useSceneProgress()
The enclosing scene's progress. Read it with useTransform for the DOM, or .get() in a render loop.
MotionValue<number>- createTimeline(base, cues, { ease })
Pins values (numbers or lists of numbers) at points from 0 to 1. Values a cue leaves out carry over. sample(t) returns one reused object and allocates nothing.
{ at, values?, ease? }[]- easings / range(t, from, to)
Curves for the stretches between cues, and a helper that splits one progress into chapters.
linear, smooth, smoother, out, in / number
Accessibility
- The section can be named with label. Every beat stays in the reading order.
- Focusing a link or button inside a hidden beat scrolls the page to the stretch where it shows.
- Hidden beats ignore the pointer, so they never block the stage.
- Reduced motion keeps the scene, since the scroll is the reader's own movement, and the beats only fade.