Parallax layers

Layers move at different speeds during a camera move, so a flat scene gains depth.

Rendered video, with motion blur.

0.00 / 3.00 s

Live preview, driven by the code below. No motion blur.

What it does

During a camera move the foreground travels furthest, the middle layer less and the background least.

Curve

Ease in-out cubic

Values

S is the frame's short side, 1080 px at 1080p. Unmeasured inputs in the preview are illustrations, not rules.

FactValue
Purpose
Idle, emphasis
Acts on
Group, background
Typical length
2 to 4 s (60 to 120 frames at 30 fps), with the camera move
Caution
Three layers at most, and text sits on the foreground layer only.
PropertyValue
Layers
At most 3
Speeds
Foreground 1 times the camera move, middle 0.6 times, background 0.3 times
Gap between neighbouring layers
0.2 to 0.5 (web parallax research finds that range feels natural; beyond 0.7 can cause motion sickness)
Duration
Runs for the camera move, 2 to 4 s, ease-in-out cubic
Export samples
12; 1 when still

Starting values from research. Measure against a reference before relying on them.

Code

ts
export const seg = (t: number, a: number, b: number) => Math.max(0, Math.min(1, (t - a) / (b - a)));

export const lerp = (a: number, b: number, k: number) => a + (b - a) * k;

export const out = (k: number) => (k >= 1 ? 1 : 1 - Math.pow(2, -10 * k));

export const io = (k: number) => (k < 0.5 ? 16 * k ** 5 : 1 - Math.pow(-2 * k + 2, 5) / 2);

export const inn = (k: number) => k * k * k;

export const cubicOut = (k: number) => 1 - Math.pow(1 - k, 3);

export const h = (i: number, j: number) => { const x = Math.sin(i * 127.1 + j * 311.7) * 43758.5453; return x - Math.floor(x); };

export const phase = (t: number, start = 0, duration = 0.6) => seg(t, start, start + duration);

export const easeInOut = (p: number) => p < 0.5 ? 4 * p ** 3 : 1 - (-2 * p + 2) ** 3 / 2;

export const PARALLAX_SPEEDS = [1, 0.6, 0.3];

export const parallaxLayer = (t: number, layer: number, distance: number, duration = 3) => ({ x: -distance * (PARALLAX_SPEEDS[layer] ?? 1) * easeInOut(phase(t, 0, duration)) });

Best practices

Use it forAvoid
Giving a flat product scene depth during a pan
More than three layers
Layered illustrations and backgrounds
Text on any layer but the foreground

Reduced motion: a simple opacity fade over 0.2 s.