Back to library
INTERACTION_125

Page Transition Navigation.

Clicking a nav link plays an exit before the next route paints. The overlay off-screen before the trigger; wiping the overlay across, swapping the route, then wiping it away once a nav link click.

CATEGORY
Navigation
COMPLEXITY
Advanced
TECH
CSS + JS
PLATFORM
Both
PERFORMANCE
Light
LIVE PLAYGROUND
HomeWorkPricing
CSS / CSS
/* Page Transition Navigation — Clicking a nav link plays an exit before the next route paints. */
.page-transition-navigation {
  --dur: 620ms;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --stagger: 60ms;
  will-change: transform, opacity;
}

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

/* the overlay off-screen -> wiping the overlay across, swapping the route, then wiping it away */
@keyframes page-transition-navigation-in {
  to {
    opacity: 1;
    transform: none;
    filter: none;
  }
}

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

/** Page Transition Navigation — trigger: a nav link click */
export function PageTransitionNavigation({ 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="page-transition-navigation" data-state="out">
      {children}
    </div>
  );
}

IF YOU LIKE THIS, STEAL THESE TOO.

DISCOVEREFFECTSPROMPTS
INTERACTION_027CSS

Navigation Underline

Underline grows from the origin side on hover.

Navigation / LightView
Home
Work
Pricing
INTERACTION_117CSS

Animated Mobile Menu

The panel slides in and links cascade behind it.

Navigation / LightView
Home
Work
Pricing
INTERACTION_118CSS

Fullscreen Navigation Reveal

A full-screen overlay wipes down and oversized links rise in.

Navigation / LightView
HomeWorkPricing
INTERACTION_119CSS

Expanding Navigation Pill

A pill indicator glides between nav items.

Navigation / LightView