How I built a scroll-driven head-turn hero
A build log of this site's hero, from a ten-second green-screen video to 240 keyed frames scrubbed by scroll on a canvas.
3 min read

On this page
The first thing you see on this site is me at a desk, typing. Scroll, and a lightbulb switches on, I turn to face you, and the scene ends on a thumbs-up. It looks like video, but nothing plays: every frame is a still image, and your scroll position picks which one is drawn.
This post walks through how that works, from the source clip to the canvas, and the parts that took longer than expected.
Why frames, not a video
Scrubbing a <video> element by setting currentTime on scroll sounds simpler, but browsers decode video forwards from the last keyframe. Scroll backwards, or jump, and the picture stutters while the decoder catches up. Images don't have that problem: any frame can be drawn at any time, in any order.
The trade-off is weight. Ten seconds at 24 fps is 240 frames, so the frame pipeline had two jobs: make every frame small, and load them in an order that never leaves the visitor looking at a blank canvas.
From video to frames
I didn't want ffmpeg as a project dependency, and the machine that builds the frames already has Chrome. So the extraction script opens the video in headless Chrome, seeks to each frame, draws it onto a canvas and saves the canvas as a PNG.
for (let i = 0; i < count; i += 1) {
const dataUrl = await page.evaluate(async (t) => {
video.currentTime = t; // the middle of frame i
await new Promise((resolve) => (video.onseeked = resolve));
canvas.getContext('2d').drawImage(video, 0, 0);
return canvas.toDataURL('image/png');
}, (i + 0.5) / FPS);
writeFileSync(`png/${pad(i + 1)}.png`, Buffer.from(dataUrl.split(',')[1], 'base64'));
}Seeking to the middle of each frame matters. Seek to its exact start and rounding can land on the previous frame, so you get a duplicate and a skipped frame somewhere else.
Keying the green screen
The clip was shot against green, and the site is near-black, so every frame needs a transparent background. The key runs in Node with sharp, pixel by pixel: the more a pixel's green channel exceeds its red and blue, the more transparent it becomes. Spill, the green glow that bleeds onto hair and shoulders, is pulled back towards the other channels.
Before
After
After keying, every frame gets the same small grade (a little darker, a little more contrast) so the figure sits naturally on the dark page.
Two frame sets
The script writes two sets of WebP frames:
- Desktop: all 240 frames at 1,280 px wide.
- Phones: every second frame at 640 px, 120 in all, kept under a 3 MB budget.
It also writes three stills (the first frame, the front-facing frame and the thumbs-up) and a small manifest with frame counts and the scroll marks, so the component never hard-codes them.
Scroll to frame
The hero is pinned with GSAP's ScrollTrigger while you scroll through it. Progress through the pin, from 0 to 1, maps to a frame number through a few marks, so the story can spend longer on the moments that matter:
export function frameAt(progress: number, marks: Mark[]): number {
if (progress <= marks[0]!.p) return marks[0]!.f;
for (let i = 1; i < marks.length; i += 1) {
const b = marks[i]!;
if (progress <= b.p) {
const a = marks[i - 1]!;
return Math.round(a.f + ((progress - a.p) / (b.p - a.p)) * (b.f - a.f));
}
}
return marks[marks.length - 1]!.f;
}The marks slow the frames down around the turn, which is where the text panels change.
Loading without a blank canvas
Show a still first
The first frame is a normal image, so it paints straight away and is the page's largest paint. The canvas only fades in over it once it has something to draw.
Load the first 30 frames in parallel
Six at a time. That covers the start of the scroll, and the canvas takes over when they're in.
Fill in the rest when the browser is idle
The remaining frames load a few at a time during idle periods, so they never compete with the rest of the page.
Draw the nearest frame you have
If you scroll faster than frames arrive, the canvas draws the closest loaded frame and asks for the exact one straight away.
When not to animate
Not everyone wants motion. With reduced motion on, or Save-Data, there's no pin and no canvas: the front-facing still shows, with the same text. The page is complete without the animation; the animation is an extra.