StealThis .dev

Parallax Depth Scene

A layered diorama where background, mid and foreground planes drift at different rates from pointer or scroll, each with depth-cued blur, scale and shadow for a tactile 3D feel.

Open in Lab
vanilla-js css
Targets: JS HTML

Code

A multi-layer depth scene that turns a flat card into a diorama. Five stacked planes — sky, distant hills, mid trees, a floating monolith and a foreground frame — each move at a different rate in response to input, so parallax offset scales with perceived distance. Nearer planes translate further and tilt more; farther ones stay put, gaining a touch of blur and desaturation so your eye reads them as receding.

Two drive modes share the same math. Pointer mode maps cursor position (or touch, or device tilt on mobile) to a normalized [-1, 1] vector that pushes each layer along X, Y and a subtle Z-rotation. Scroll mode maps vertical scroll progress to the same field, so the scene “cranes” as the page moves. A spring-smoothed value chases the raw target every frame via requestAnimationFrame, keeping motion buttery at 60fps and never snapping. Depth-of-field, per-layer scale and a moving key-light shadow sell the volume.

The technique is a compositor-friendly parallax: everything animates through transform: translate3d() and filter, so layers stay on the GPU and never trigger layout. Sliders expose depth intensity and DOF strength live, and the whole thing honors prefers-reduced-motion — under that setting the animation loop halts and the scene renders in a calm, centered resting pose with no drift.