WheelScroll: a feed on a wheel
A React component for a vertical feed of videos and images that bends like the screen is curved. The middle band is flat and drawn 1:1, so what you are watching stays sharp. Past it, every row of every card is laid on a cylinder, so cards curve smoothly at the top and bottom, edges included. Scrolling faster tightens the wheel, and it eases back when you stop.
Files that come with this skill:
| File | What it is |
|---|---|
src/WheelScroll.tsx | The component. Base UI ScrollArea for native scrolling, three.js (loaded on mount) for the drawing. |
src/wheel-scroll.css | Its styles: canvas, scroller, edge fade, Base UI scrollbar, screen-reader list. |
demo/index.html | A no-build demo with drawn sample objects and an outward/inward toggle. Open it in a browser. |
preview/ | A screenshot of the demo. |
This repo is the public home of the component (MIT). The full skill also lives in the vault: https://vault.sourcetms.com/skills/curved-wheel-scroll.
Install
- Add the dependencies:
npm i @base-ui/react threeandnpm i -D @types/three. - Copy
WheelScroll.tsxandwheel-scroll.cssinto the project's components folder. Keep the CSS import at the top of the TSX, or move the styles into the project's own stylesheet. - Render it in a box with a height. Full screen is
height: 100dvh.
import { useMemo } from 'react';
import { WheelScroll, type WheelItem } from './WheelScroll';
export function Shorts() {
// Keep the array stable (useMemo or a module constant): a new array rebuilds the scene.
const items = useMemo<WheelItem[]>(() => [
{ src: '/media/launch.mp4', title: 'Launch day', meta: '27 Nov' },
{ src: '/media/a.mp4', title: 'Behind the scenes', meta: '23 Nov', span: 'half' },
{ src: '/media/b.jpg', title: 'The desk', meta: '23 Nov', span: 'half' },
], []);
return (
<div style={{ height: '100dvh' }}>
<WheelScroll items={items} direction="outward" heading={{ title: 'Shorts', subtitle: 'What I made this month.' }} />
</div>
);
}
Props
| Prop | Default | What it does |
|---|---|---|
items | { src, kind?, title?, meta?, label?, span? }[]. kind is guessed from the file extension; label is read by screen readers when there's no title. Two span: 'half' items in a row sit side by side. | |
direction | outward | outward rolls the ends away; inward leans them toward you. Changing it does not rebuild the scene. |
curve | 1 | How tight the wheel is. 0.5 is gentler, 1.5 tighter. |
idle | 0.75 | How much of the scroll tightening stays at rest, 0 to 1. |
heading | { title, subtitle? } drawn above the first card. | |
maxWidth | 520 | Width of the feed column in CSS px. |
sound | true | Tap a video to hear it; the others stay muted. |
maxPlaying | 3 | How many videos may play at once, nearest the middle first. |
onSelect | Called with the tapped item and its index. | |
onSoundChange | Called with the item whose sound is on, or null. |
How it works (so you can change it)
- Native scroll, drawn feed. An empty Base UI
ScrollArea.Viewportwith a spacer as tall as the feed sits over a three.js canvas. The browser does the scrolling and momentum; each frame the canvas draws the feed atscrollTop. - The wheel lives in the vertex shader. For a vertex at distance
efrom the middle of the view: inside the flat band (10%of the height) it stays put. Past it, anglet = (e - flat) / R, screen y= flat + R sin t, depth= R (1 - cos t)(outward goes back, inward comes forward at0.55). The camera sits at the perspective distance (1.15 x height), so the flat band is 1:1 in CSS pixels. Cards are planes with a row every 6px, which is what makes the curve smooth. - Radius. Outward
R = 0.3 x height, inward0.46 x height(wider so its edges still reach the view's edge), divided bycurveand by a scroll-speed factor that eases fromidleto 1. - Light. Brightness falls with
1 - cos t(0.75outward,0.3inward); the side tipped toward the light gets a small sheen. Edges fade out past the wheel's limit (1.5rad outward,1.05inward). - Media. Videos and images are cropped to fill in the fragment shader (a little above centre, so faces stay in), with rounded corners from a signed-distance function. Captions are drawn to a canvas at 2x and ride the same wheel.
- Phones. Only the videos nearest the middle play (
maxPlaying, default 3); the rest pause, and everything pauses when the tab is hidden. iOS only autoplays muted, inline video it considers visible, with every flag set before the source: so each<video>is laid out in a small box behind the opaque canvas (never detached, neveropacity: 0), and a card counts as ready fromreadyState >= 2, not theloadeddataevent, which iOS may never fire forpreload="metadata". Every tap retries playback, and if the browser still refuses (Low Power Mode) a "Tap to play videos" button appears. Serve video with HTTP range support and themoovatom at the front ("faststart"), ideally at 720p for phones. - Taps are mapped in the flat band, where the drawing matches the layout 1:1; drags and taps on the curved ends are ignored.
- Keyboard and screen readers. The heading and one button per item sit in the scroller, visually hidden. Focusing a button scrolls its card to the middle and rings it; activating it selects it and toggles sound. Sound changes are announced.
- Robustness. Meshes past the end of the wheel aren't drawn. Easing is frame-rate independent. A lost WebGL context is restored. Resizes are debounced.
Gotchas
- Media must be same-origin or served with CORS headers, or WebGL refuses to read it.
- Text inside the feed is drawn, not DOM: it can't be selected, and interactive controls belong outside the component. The component renders a hidden list of item titles for screen readers.
- Reduced motion keeps the curve but drops the scroll-speed tightening, and nothing autoplays: a tapped video plays.
- Very long feeds hold one texture per caption row; for hundreds of items, window the
itemsyou pass in.
Check your work
Open the page on a phone, scroll fast and slow in both directions, and confirm: the middle card is sharp and unbent, card edges curve smoothly (no straight facets), videos near the middle play, tapping one turns its sound on, and the outward ends fade into the background.