Back to library
INTERACTION_107

Parallax Image.

The image drifts slower than the frame that contains it. The image scaled to 1.2 and offset upward before the trigger; translating the image at 0.2 of the scroll delta once scroll position relative to the frame.

CATEGORY
Images
COMPLEXITY
Easy
TECH
CSS
PLATFORM
Both
PERFORMANCE
Light
LIVE PLAYGROUND
Media
CSS / CSS
/* Parallax Image — The image drifts slower than the frame that contains it. */
.parallax-image {
  --dur: scroll-linked;
  --ease: linear;
  --stagger: 60ms;
  will-change: transform, opacity;
}

.parallax-image > * {
  opacity: 0;
  transform: translateY(14px);
  animation: parallax-image-in var(--dur) var(--ease) forwards;
  animation-delay: calc(var(--i, 0) * var(--stagger));
}

/* the image scaled to 1.2 and offset upward -> translating the image at 0.2 of the scroll delta */
@keyframes parallax-image-in {
  to {
    opacity: 1;
    transform: none;
    filter: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .parallax-image > * {
    opacity: 1;
    transform: none;
    animation: none;
  }
}
React / TSX
import { useEffect, useRef } from "react";

/** Parallax Image — trigger: scroll position relative to the frame */
export function ParallaxImage({ children }: { children: React.ReactNode }) {
  const ref = useRef<HTMLDivElement>(null);

  useEffect(() => {
    const el = ref.current;
    if (!el) return;
    if (window.matchMedia("(prefers-reduced-motion: reduce)").matches) {
      el.dataset["state"] = "in";
      return;
    }
    const io = new IntersectionObserver(
      ([entry]) => {
        if (entry?.isIntersecting) {
          el.dataset["state"] = "in";
          io.unobserve(el);
        }
      },
      { threshold: 0.2 },
    );
    io.observe(el);
    return () => io.disconnect();
  }, []);

  return (
    <div ref={ref} className="parallax-image" data-state="out">
      {children}
    </div>
  );
}

IF YOU LIKE THIS, STEAL THESE TOO.

INTERACTION_105CSS

Image Mask Reveal

The image uncovers behind a mask while it settles from a slow zoom.

Images / LightView
Media
INTERACTION_108CSS + JS

Cursor Zoom

The image magnifies around the exact pointer position.

Images / LightView
Media
INTERACTION_109CSS + JS

Image Trail

Thumbnails trail the cursor and fade out behind it.

Images / MediumView
Media
INTERACTION_110CSS

Image Distortion

A subtle ripple runs through the image on hover.

Images / HeavyView