01.01 · Scroll-Based

Parallax Depth-of-Field

Layers move at their own speed as the focus shifts. Best for cinematic intros.

Scroll it

Scroll inside the box, or press Play and it scrolls for you.

Focus shifts

Far: the sky Near: the front ridge

Copy the prompt

Paste it into an AI assistant such as ChatGPT, Claude or Cursor to build this in your own project.

Add a parallax depth-of-field effect to [your layered scene or illustration]. Split the scene into layers from far to near and hold it in place while the visitor scrolls through a taller section. As they scroll, move each layer by an amount that grows with its nearness, and move a point of sharp focus from the farthest layer to the nearest: blur each layer by how far it sits from that focus. Ease the layers toward the scroll position on every frame by a share of the distance left, exponential in the time since the last frame, so a wheel's jumps turn into smooth movement at the same pace on every screen. If the visitor has reduced motion turned on, keep the layers still and only shift the focus.

Replace the words in brackets with your own scene.

Free and open source. If this helped, a star on GitHub helps other people find it.

Star on GitHub

What it is

The full explanation is in README.md.

Good for

  • Hero scenes
  • Story intros
  • Illustrated landscapes

Avoid on

  • Large photos
  • Text-heavy pages