A landing hero usually puts a picture behind some text. This one lets you scroll into it: the camera moves through the subject, a light under the pointer shows a second view of the film, and past the subject three cards come out of the depth.
It is plain HTML, CSS and one small script. No WebGL, no animation library. In headless Chrome on our machine, requestAnimationFrame ran 60–61 times per second at each of the seven scroll positions we measured (one second at each), on a 1440×900 and a 390×844 viewport.
Here is how it is built, and the one mistake that cost me an hour.
1. Three layers, one perspective
<div class="stage"> <!-- position: sticky; perspective: 1000px -->
<div class="scene"> <!-- transform-style: preserve-3d -->
<video class="L" data-z="-900" …></video> <!-- the film -->
<div class="L" data-z="-150">…headline…</div>
<img class="L" data-z="-220" src="cutout.png"> <!-- the subject, cut out -->
</div>
</div>
Every layer is a full-bleed box of the same size. The film and the cut-out share the same object-fit: cover and object-position, and the cut-out was made from the same still as the film's first frame; the headline is a positioned container in a box of the same size. Each layer gets translateZ(z). A layer pushed back by z is drawn smaller by P / (P - z) (with P the perspective), so each one is also scaled by the inverse:
el.style.transform = `translateZ(${z}px) scale(${(P - z) / P})`;
With the perspective origin at the centre of the box and those shared settings, the layers line up at rest. The moment the camera moves, the near layers move more than the far ones — that difference is the depth you feel.
2. The camera is the scene's transform
The section is 460svh tall and the stage is position: sticky, so scrolling gives a progress from 0 to 1 without hijacking the scroll. The script smooths it with exponential easing (prog += (target - prog) * 0.085 per frame — not a true spring; with a fixed factor it follows faster on a 120 Hz screen, so use 1 - Math.pow(1 - 0.085, dt * 60) if you need the same feel everywhere) and turns it into a camera:
const cz = ease(prog / 0.74) * 960; // move in
const k = (P - zSubject - cz) / P; // how far the subject layer shifts per pixel
const tx = (W / 2 - focusX) * aim * k; // aim at the focus point (a visor, a headlight)
scene.style.transform = `translate3d(${tx}px, ${ty}px, ${cz}px) rotateX(${rx}deg) rotateY(${ry}deg)`;
The pointer adds a small tilt that fades as you scroll in. When the system setting asks for reduced motion, the idle drift and the tilt stop and the scroll still works.
3. A light that shows a second view
Under the pointer there is a circle where the film looks different — a filtered "AI view" with thin outlines and names on what the picture shows. Three things make it:
-
The film drawn again. Each frame, the
<video>is drawn into a canvas at 60% size with the same cover maths. Drawing a video from another origin (or from a local file) into a canvas is allowed; it marks the canvas as tainted, which only blocks reading the pixels back (getImageData,toDataURL). The canvas still displays, and we never read it. -
A CSS filter on the canvas —
grayscale(1) brightness(1.9) contrast(1.5) sepia(1) hue-rotate(205deg) saturate(5)turns it into a duotone. - A CSS mask that follows the pointer:
.ai { mask-image: radial-gradient(circle at var(--rx) var(--ry), #000 0, #000 calc(var(--r) * .55), transparent var(--r)); }
The variables are set on the scene, so the canvas, a grid layer and an outline layer share one mask. Past the focus point the radius grows to the whole screen, and the second view becomes the next scene.
4. The mistake: the light was behind the subject
My first version put the "AI view" at the depth of the film. Everything computed correctly — the mask position, the radius, the canvas had pixels — and nothing showed.
The reason: the visor I wanted to light up is part of the subject, and the subject is a cut-out layer in front of the film. The light was being drawn, then covered. Moving the three light layers to just in front of the subject (-219…-217, right in front of -220) fixed it. If your reveal layer seems to do nothing, check what is in front of it before you check your maths.
5. Numbers, and what they mean
- 60–61
requestAnimationFramecallbacks per second, counted for one second at each of seven scroll positions (not during continuous scrolling), desktop and phone viewports, headless Chrome with the GPU on, our machine. Your machine will differ. - Its Content-Security-Policy is
default-src 'none'with images and media from'self'only andconnect-src 'none', so the page does not load from or talk to another host. - The video in the posts that go with this article is a screen recording made frame by frame, so it plays about two to three times faster than the page.
Try it
I put one of these up as a free download — KAZE, a rainy-night car launch page where you scroll into the headlight and the light shows a "sensor view". It is a ZIP with the page, the cut-out, the loop, a groove and an EDIT block at the top for every word. It is near the top of forma-zero.com, along with the other works built this way.
This article was written with the help of an AI assistant; the code was run and the numbers were measured on our machine before publishing. The pictures and films in the demo pages were generated with AI; the brands are fictional.
Top comments (0)