Scroll Scene
Code
| 1 | <ScrollScene |
| 2 | enter={{ target: 'top', container: 'top' }} |
| 3 | leave={{ target: 'bottom', container: 'bottom' }} |
| 4 | scrub={0.25} |
| 5 | onFrame={(progress) => applyFrame(progress)} |
| 6 | > |
| 7 | {({ targetRef, containerRef }) => ( |
| 8 | <div ref={containerRef} style={{ height: '300vh', overflowY: 'auto' }}> |
| 9 | {/* Tall track = the observed target, measured as it travels. */} |
| 10 | <div ref={targetRef} style={{ height: '300vh' }}> |
| 11 | {/* Sticky stage holds still while the track scrolls past. */} |
| 12 | <div style={{ position: 'sticky', top: 0, height: '100vh' }}> |
| 13 | <Stage /> |
| 14 | </div> |
| 15 | </div> |
| 16 | </div> |
| 17 | )} |
| 18 | </ScrollScene> |
| 19 | |
| 20 | // One function replaces the whole tween list: per-frame writes go |
| 21 | // straight to style, never through React state. |
| 22 | function applyFrame(progress: number) { |
| 23 | const t = Math.max(0, Math.min(1, progress)) |
| 24 | card.style.transform = `rotateY(${t * 180}deg) translateZ(${t * 200}px)` |
| 25 | } |
The declarative face of useAnimeOnScroll. The scene owns the observer and hands you refs, coarse state, and an onFrame channel — so a scrubbed stage costs zero React re-renders and adds no wrapper element to your layout.
Live previewOpen Playground
Scroll SceneRefs in · scrub · onFrame out
Scroll ↓
Scroll inside the panel to scrub the stage
stageScrollScene
0%
Props
| Name | Type | Default | Description |
|---|---|---|---|
| children | ReactNode | (api: ScrollSceneRef) => ReactNode | - | Static content, or a render function receiving ref, targetRef, containerRef, controls, state, observer, isReady, isInView, isPinned, progress, scroll, velocity, and backward |
| enter / leave | string | { target, container } | - | Edges where progress starts and ends, as a pair ('top bottom') or an object |
| container / target | TargetSelector | refs | Override the refs with selectors or elements; an unattached container defaults to the page |
| scrub | boolean | number | false | true scrubs 1:1; a number is seconds-to-catch-up damping |
| onFrame | (progress, state) => void | - | Per-frame channel for transforms, canvas draws, or chrome — never route per-tick work through reactive state |
| pin / pinStart / pinEnd | boolean / string / string | false / 'top top' | Pin mode holds the target on screen instead of only observing it |
| enabled / deps | boolean / unknown[] | true / [] | Gate the scene, or rebuild the observer when layout inputs change |
| onReady | (api) => void | - | Runs once the observer is ready |