Back to library
INTERACTION_148

Moving Spotlight.

A slow beam sweeps across the section surface. Parked left of the section before the trigger; translating the light across the section and back once in view, looping every 12 seconds.

CATEGORY
Background
COMPLEXITY
Easy
TECH
CSS
PLATFORM
Both
PERFORMANCE
Light
LIVE PLAYGROUND
CSS / CSS
/* Moving Spotlight — A slow beam sweeps across the section surface. */
.moving-spotlight {
  --dur: 12s;
  --ease: ease-in-out;
  --stagger: 60ms;
  will-change: transform, opacity;
}

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

/* parked left of the section -> translating the light across the section and back */
@keyframes moving-spotlight-in {
  to {
    opacity: 1;
    transform: none;
    filter: none;
  }
}

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

/** Moving Spotlight — trigger: in view, looping every 12 seconds */
export function MovingSpotlight({ 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="moving-spotlight" data-state="out">
      {children}
    </div>
  );
}

IF YOU LIKE THIS, STEAL THESE TOO.

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
TEXTURE / 3%
INTERACTION_024CSS

Grain Overlay

Film grain that stops black from looking flat.

Background / LightView
INTERACTION_147CSS

Gradient Mesh

Soft overlapping gradients drift behind the content.

Background / MediumView