Back to library
INTERACTION_158

Cinematic Gradient Drift.

A wide dark gradient shifts imperceptibly across the page. At background-position 0% 50% before the trigger; moving the background position across the gradient and back once always while the page is visible.

CATEGORY
Background
COMPLEXITY
Easy
TECH
CSS
PLATFORM
Both
PERFORMANCE
Light
LIVE PLAYGROUND
CSS / CSS
/* Cinematic Gradient Drift — A wide dark gradient shifts imperceptibly across the page. */
.cinematic-gradient-drift {
  --dur: 26s;
  --ease: ease-in-out;
  --stagger: 60ms;
  will-change: transform, opacity;
}

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

/* at background-position 0% 50% -> moving the background position across the gradient and back */
@keyframes cinematic-gradient-drift-in {
  to {
    opacity: 1;
    transform: none;
    filter: none;
  }
}

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

/** Cinematic Gradient Drift — trigger: always while the page is visible */
export function CinematicGradientDrift({ 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="cinematic-gradient-drift" data-state="out">
      {children}
    </div>
  );
}

IF YOU LIKE THIS, STEAL THESE TOO.

INTERACTION_147CSS

Gradient Mesh

Soft overlapping gradients drift behind the content.

Background / MediumView
INTERACTION_151CSS

Aurora Gradient

Long ribbons of light fold slowly across the top of the section.

Background / MediumView
LOVABLECURSORBOLTV0REPLITWINDSURFLOVABLECURSORBOLTV0REPLITWINDSURF
INTERACTION_022CSS

Logo Marquee

Infinite horizontal scroll with edge fades.

Background / LightView
STRUCTURE / 56PX
INTERACTION_023CSS

Tech Grid

Faint technical grid with a radial fade.

Background / LightView