Free tutorial · about 45 minutes
Build a scroll-scrubbed video hero with Claude Code
Scroll down this page and the whisky pours. That is the effect: a film that plays forward and backward with your scroll, as if you were holding the camera. It is the heart of most templates on this shelf, and this tutorial builds it from nothing.
You need Node 20 or newer, Claude Code, ffmpeg, and one short clip. It takes about 45 minutes. Every step has the prompt to give Claude Code and the code it should end up with, so you can check its work.

Live example · scroll
Pour it with your scroll.
Scroll down and back up: the film follows you, frame by frame.
1. Get one good clip
The film carries the whole page, so it has to be one continuous shot: a slow camera move, no cuts, nothing flashing. Five to eight seconds is plenty, because scroll stretches it out. Shoot it, buy it, or generate it.
Or use ours. This is the clip in this page's example, free to download and use in your own projects. Take the original if you want to do the encode in step 2 yourself; take the ready one to skip it.
Free downloads
- pour-original.mp4The original take, 1920×1080, 8 s: use it for step 2Download · 14 MB
- pour.mp4Ready to scrub: encoded all-intra, 1600×900Download · 4.8 MB
- pour.jpgIts poster, the first frameDownload · 115 KB
Generated with Google's Veo for the Sliabh template. Free to use for learning and in your own projects; please don't resell the clip on its own.
To generate your own, describe one camera move and one subject, and say what must not happen. This is close to the script behind the pour:
Macro shot, 16:9, 8 seconds. A thin stream of amber whisky pours from above into a cut-crystal tumbler holding one large clear ice sphere, on a dark bar. The camera holds close on the glass and drifts slowly down as it fills. Warm candlelight glowing out of focus behind, deep shadows, light catching the crystal. One continuous shot, no cuts, no text, no logos, no hands entering the frame, no camera shake.
Throw away any take with a watermark, a cut, a morphing object or less than 1080p. A bad take costs you a minute now and a day later.
2. Encode it so every frame is a keyframe
A normal video stores a full picture every few seconds and only the changes in between. Scrubbing asks the browser to jump to any frame, so it has to rebuild from the last full picture every time, and the scrub judders. The fix is to make every frame a full picture: an all-intra encode.
ffmpeg -i pour-original.mp4 -an -vf scale=1600:-2 -c:v libx264 -preset slow -crf 29 \
-g 1 -pix_fmt yuv420p -movflags +faststart public/film/pour.mp4ffmpeg -i public/film/pour.mp4 -frames:v 1 -q:v 3 public/film/pour.jpg-g 1 is the one that matters: a keyframe every frame. -an drops the sound, -crf 29 keeps the file small, and +faststart lets it begin before it has fully downloaded. Expect two to five megabytes for eight seconds.
3. Start the project
Create a Next.js app (App Router, TypeScript, Tailwind v4) in this folder and add gsap. I have public/film/pour.mp4 and public/film/pour.jpg. In globals.css set overflow-x: clip on BOTH html and body (never overflow: hidden, which makes body a scroll container and breaks position: sticky). Give the page a dark background. Don't build anything else yet.
That overflow line is the most common reason a scroll site works on your laptop and dies on a phone. Check Claude Code wrote clip, not hidden.
4. Build the scrub
The section is tall (here, three screens). Inside it, a sticky stage the height of one screen holds the video, so the film stays put while you scroll through the section. ScrollTrigger turns how far you are through the section into a target time, and a ticker eases the video's clock toward that target every frame. The easing is what makes it feel weighted instead of stepped.
Write a client component components/scrub.tsx: a tall section (height prop in vh, default 300) with a sticky full-screen stage holding a muted, playsInline video and its poster image behind it. Use GSAP ScrollTrigger (start 'top top', end 'bottom bottom') to turn the section's progress into a target time, and on gsap.ticker ease video.currentTime toward the target by 0.14 of the gap each frame. Skip the tick while the duration is unknown or video.readyState < 2, because seeking while it downloads aborts the download. Respect prefers-reduced-motion with a still poster. Clean everything up on unmount.
"use client";
import { useEffect, useRef } from "react";
import gsap from "gsap";
import { ScrollTrigger } from "gsap/ScrollTrigger";
import { unlockVideo } from "@/lib/unlock-video";
gsap.registerPlugin(ScrollTrigger);
export function Scrub({ film, vh = 300, children }: { film: string; vh?: number; children?: React.ReactNode }) {
const root = useRef<HTMLElement>(null);
const ref = useRef<HTMLVideoElement>(null);
useEffect(() => {
const section = root.current!, video = ref.current!;
if (window.matchMedia("(prefers-reduced-motion: reduce)").matches) return;
let duration = 0, target = 0, current = 0;
const onMeta = () => { duration = video.duration || 0; };
video.addEventListener("loadedmetadata", onMeta);
if (video.readyState >= 1) onMeta();
const release = unlockVideo(video); // step 5: iPhone
const trigger = ScrollTrigger.create({
trigger: section, start: "top top", end: "bottom bottom",
onUpdate: (self) => { if (duration) target = self.progress * (duration - 0.05); },
});
const tick = () => {
if (!duration || video.readyState < 2) return; // don't seek while it downloads
current += (target - current) * 0.14; // the weight
if (Math.abs(video.currentTime - current) > 0.004) video.currentTime = current;
};
gsap.ticker.add(tick);
return () => { gsap.ticker.remove(tick); trigger.kill(); release(); video.removeEventListener("loadedmetadata", onMeta); };
}, []);
return (
<section ref={root} className="relative" style={{ height: `${vh}vh` }}>
<div className="sticky top-0 h-screen overflow-hidden">
<img src={`${film}.jpg`} alt="" className="absolute inset-0 h-full w-full object-cover" />
<video ref={ref} src={`${film}.mp4`} poster={`${film}.jpg`} muted playsInline preload="auto"
className="absolute inset-0 h-full w-full object-cover" />
{children}
</div>
</section>
);
}The duration - 0.05 keeps the last seek just inside the film. Seeking to the exact end makes some browsers show a black frame.
5. Make it work on an iPhone
Safari on iPhone will not paint a frame you seek to on a video that has never played. The video sits frozen on its poster and nothing tells you why. The fix: play it and pause it straight away on load. A muted inline video is allowed to do that. When the phone refuses (Low Power Mode), try again on the first touch.
export function unlockVideo(video: HTMLVideoElement): () => void {
const gestures = ["touchstart", "pointerdown", "click"] as const;
let unlocked = false;
const unlock = () => {
if (unlocked) return;
unlocked = true;
const p = video.play();
if (p && typeof p.then === "function") p.then(() => video.pause()).catch(() => { unlocked = false; });
else video.pause();
};
const onGesture = () => { unlock(); gestures.forEach((g) => window.removeEventListener(g, onGesture)); };
unlock();
gestures.forEach((g) => window.addEventListener(g, onGesture, { passive: true }));
return () => gestures.forEach((g) => window.removeEventListener(g, onGesture));
}If you ever call video.load() (to upgrade preload, say), the decoder resets: call unlockVideo again after it.
6. Put words on the film
Words should arrive as the film starts and leave as the section lets go of the screen, not at some fraction of the film. Anchor the fade-out to the section's release: from when its bottom reaches the bottom of the screen until it is just under halfway up.
Inside the Scrub stage, add a headline and one line of text at the bottom left. They rise in once when the section enters. Fade and lift them out with a ScrollTrigger on the section from 'bottom 100%' to 'bottom 45%', scrubbed, so they leave exactly as the sticky stage releases. Add a soft dark gradient behind them so they stay readable on any frame.
7. Prove it scrubs
Don't trust your eyes alone, and don't trust a preview pane that is hidden behind another window: browsers pause animation frames there. Read the video's clock at two scroll positions in a real headless browser. If the second number is bigger, it scrubs.
import { chromium } from "playwright";
const b = await chromium.launch();
const p = await b.newPage({ viewport: { width: 1440, height: 900 } });
await p.goto("http://localhost:3000", { waitUntil: "networkidle" });
const at = async (y) => { await p.mouse.wheel(0, y); await p.waitForTimeout(900); return p.$eval("video", (v) => v.currentTime.toFixed(2)); };
console.log("a third of the way:", await at(900), " two thirds:", await at(900));
await b.close();Then open it on your phone over your local network (npm run dev -- -H 0.0.0.0) and scroll. That is the test that matters.
The whole thing in one prompt
Once you understand the steps, this does them in one go. Read what Claude Code writes against the code above.
Build a Next.js (App Router, TypeScript, Tailwind v4, GSAP) page with one scroll-scrubbed video hero, using public/film/pour.mp4 (encoded all-intra) and public/film/pour.jpg. Set overflow-x: clip on html and body. The hero is a 300vh section with a sticky full-screen stage; ScrollTrigger maps the section's progress to a target time and gsap.ticker eases video.currentTime toward it by 0.14 per frame, skipping frames while video.readyState < 2. Unlock the video on iPhone with play() then pause() on mount, retrying on the first touch. Put a headline and one line on the film that rise in on entry and fade out from 'bottom 100%' to 'bottom 45%'. Respect prefers-reduced-motion. Then write a Playwright script that reads video.currentTime at two scroll depths to prove it scrubs.
Frequently asked
Do I need GSAP?
No, but it saves work: ScrollTrigger handles the scroll maths and its ticker gives you one frame loop for the whole page. The same idea works with a scroll listener and requestAnimationFrame.
How big can the video be?
Keep the whole page under about 30 MB of film. One hero of 5 to 8 seconds at 1600 pixels wide is usually 2 to 5 MB with the encode above.
Why not just play the video when it comes into view?
Then the visitor is watching, not doing. Tying the film to the scroll gives them the camera, which is what makes these pages feel expensive.
Can I use a clip with sound?
Scrubbing plays the film at any speed and in reverse, so sound would be noise. The encode drops it on purpose.
