Skip to content
IndexRequest a UIAboutContact

Pointer Parallax Layers

Stacked layers shift by different amounts as the pointer moves, creating a sense of depth.

Open alone ↗

AI prompt

PROMPT: PASTE INTO YOUR AI CODING TOOL
Create a 300x180px scene with four absolutely positioned layers: a large soft circle (back, depth 0.2), a medium rounded square (depth 0.5), a small circle (depth 0.8) and a text label "Depth" (depth 1), in a grey palette. On pointermove inside the scene compute the pointer position relative to the centre in the range -1 to 1 and store it as CSS custom properties --px and --py; each layer translates by calc(var(--px) * depth * 14px) and calc(var(--py) * depth * 14px). Batch updates with requestAnimationFrame and use a 200ms ease-out transition on the layers while tracking. On pointerleave set both variables to 0 with a 500ms cubic-bezier(.2,.7,.2,1) transition. Only enable it for pointer type mouse or pen and when hover is available. Under prefers-reduced-motion keep all layers static. The scene is decorative: aria-hidden on the layers except the label text.

About this pattern

Definition

Several layers are translated in proportion to the pointer position, with nearer layers moving more than distant ones. The difference in speed reads as depth.

Purpose & UX principles

  • Adds atmosphere to hero areas and featured objects.
  • Purely decorative: it carries no information and never hides content.
  • Movement is small (under 14px) so it stays comfortable; it is disabled for reduced motion and touch.

Interaction states

  • Rest (centred), tracking (layers follow), leaving (eases back to centre).

Motion specification

  • Layers update through CSS custom properties each animation frame; smoothing uses a 200ms transition.
  • Return to centre: 500ms cubic-bezier(.2,.7,.2,1).
  • Reduced motion: layers stay still.

Responsive behaviour

  • Offsets are percentages of the container size, so the effect scales.
  • Disabled on devices without a fine pointer.

Code

HTML
<div class="scene" id="scene"><i class="l a" style="--d:.2"></i><i class="l b" style="--d:.5"></i><i class="l c" style="--d:.8"></i><b class="l t" style="--d:1">Depth</b></div>

Related patterns

Tilt Card

↗
Tilt CardCards & Containers

Scroll Reveal

↗
Scroll RevealMotion & Transitions

Spring Follow

↗
Spring FollowMotion & Transitions