kitbash Sign in Connect agent
Components

Lens hero

Teal-to-mint fade with two huge glass circles that slide together on load, form a lens with a split-light edge, then drift and lean away from the pointer. Centred serif headline, a chain of joined glass navigation pills with a pill dropdown and one coral button, a round down arrow and a frosted contact chip. On phones the links become a teal sheet with staggered bracket-ruled rows.

Part of the style

Glass Lens Calm

7 parts that belong together, with their tokens, type and rules.

Preview

Code
<style>
/* Goes after the pack's base.css */
:root {
  --night: #1f1a16;
  --frost: #b73a1e;
  --ice: #d33f1d;
  --mist: #ed5a3a;
  --paper: #ef4f2c;
  --ink: #15110d;
  --ink-soft: rgba(21, 17, 13, 0.5);
  --on-dark-soft: rgba(210, 62, 29, 0.62);
  --line: rgba(2, 1, 0, 0.12);
  --line-dark: rgba(225, 65, 28, 0.2);
  --glass: rgba(210, 62, 29, 0.12);
  --glass-pale: rgba(225, 65, 28, 0.42);
  --glass-rim: rgba(225, 65, 28, 0.85);
  --deep: #350902;
  --glass-glow: rgba(250, 176, 157, 0.5);
  --sea: #ed522b;
  --glass-shade: rgba(27, 3, 0, 0.6);
  --mint: #edb5a6;
  --haze: #c06d58;
  --coral: #fef1ee;
  --coral-press: #371f19;
  --spectrum-rose: #fff3f0;
  --spectrum-warm: #c46852;
  --spectrum-cool: #fde0d8;
}
</style>

<section class="hero">
  <svg class="hero__glass" viewBox="0 0 1440 900" preserveAspectRatio="xMidYMid slice" aria-hidden="true" focusable="false">
    <defs>
      <radialGradient id="hero-upper-shade">
        <stop class="hero__stop-clear" offset="0.88" />
        <stop class="hero__stop-shade-soft" offset="0.97" />
        <stop class="hero__stop-shade" offset="1" />
      </radialGradient>
      <radialGradient id="hero-lens-shade">
        <stop class="hero__stop-clear" offset="0.94" />
        <stop class="hero__stop-shade-soft" offset="0.982" />
        <stop class="hero__stop-shade-hard" offset="1" />
      </radialGradient>
      <radialGradient id="hero-lower-glow">
        <stop class="hero__stop-none" offset="0.9" />
        <stop class="hero__stop-glow" offset="1" />
      </radialGradient>
      <linearGradient id="hero-lower-body" x1="0" y1="0" x2="0" y2="1">
        <stop class="hero__stop-body-top" offset="0" />
        <stop class="hero__stop-body-low" offset="0.35" />
      </linearGradient>
      <linearGradient id="hero-lower-rim" gradientUnits="userSpaceOnUse" x1="0" y1="520" x2="0" y2="900">
        <stop class="hero__stop-rim" offset="0" />
        <stop class="hero__stop-rim-low" offset="1" />
      </linearGradient>
      <linearGradient id="hero-split-warm" gradientUnits="userSpaceOnUse" x1="380" y1="0" x2="1060" y2="0">
        <stop class="hero__stop-warm" offset="0" />
        <stop class="hero__stop-rose" offset="0.2" />
        <stop class="hero__stop-none" offset="0.42" />
        <stop class="hero__stop-none" offset="0.74" />
        <stop class="hero__stop-warm" offset="1" />
      </linearGradient>
      <linearGradient id="hero-split-cool" gradientUnits="userSpaceOnUse" x1="380" y1="0" x2="1060" y2="0">
        <stop class="hero__stop-cool" offset="0" />
        <stop class="hero__stop-none" offset="0.3" />
        <stop class="hero__stop-none" offset="0.7" />
        <stop class="hero__stop-cool" offset="0.92" />
        <stop class="hero__stop-rim" offset="1" />
      </linearGradient>
      <clipPath id="hero-inside-lower">
        <circle data-hero-ring="lower" cx="800" cy="1084" r="555" />
      </clipPath>
    </defs>

    <circle class="hero__upper" data-hero-ring="upper" cx="690" cy="119" r="621" />
    <circle class="hero__lower" data-hero-ring="lower" cx="800" cy="1084" r="555" />
    <circle class="hero__lower-glow" data-hero-ring="lower" cx="800" cy="1084" r="555" />
    <g clip-path="url(#hero-inside-lower)">
      <circle class="hero__lens-shade" data-hero-ring="upper" cx="690" cy="119" r="621" />
      <circle class="hero__split hero__split--warm" data-hero-ring="upper" cx="690" cy="119" r="619" />
      <circle class="hero__split hero__split--cool" data-hero-ring="upper" cx="690" cy="119" r="622.4" />
    </g>
    <circle class="hero__lower-rim" data-hero-ring="lower" cx="800" cy="1084" r="555" />
  </svg>

  <header class="hero__bar">
    <a class="hero__brand" href="#" aria-label="Aldermere, home">
      <svg class="hero__mark" viewBox="0 0 46 28" aria-hidden="true" focusable="false">
        <path fill-rule="evenodd" d="M14 0a14 14 0 1 0 0 28 14 14 0 0 0 0-28Zm18 0a14 14 0 1 0 0 28 14 14 0 0 0 0-28Z" />
      </svg>
      <span class="hero__name">Aldermere</span>
    </a>

    <button class="hero__toggle" type="button" aria-expanded="false" aria-label="Menu">
      <span class="hero__toggle-line"></span>
      <span class="hero__toggle-line"></span>
    </button>

    <nav class="hero__nav" aria-label="Main">
      <ul class="hero__links">
        <li class="hero__chain" aria-hidden="true">
          <span class="hero__chain-frost"></span>
          <svg class="hero__chain-edge" focusable="false"><path /></svg>
        </li>
        <li class="hero__item hero__item--group">
          <button class="hero__link hero__link--group" type="button" aria-expanded="false">
            Company
            <svg class="hero__caret" viewBox="0 0 10 6" aria-hidden="true" focusable="false"><path d="M1 1l4 4 4-4" /></svg>
          </button>
          <ul class="hero__sub">
            <li class="hero__item"><a class="hero__sublink" href="#">About us</a></li>
            <li class="hero__item"><a class="hero__sublink" href="#">How we work</a></li>
          </ul>
        </li>
        <li class="hero__item"><a class="hero__link" href="#">Plants</a></li>
        <li class="hero__item"><a class="hero__link" href="#">For cities</a></li>
        <li class="hero__item"><a class="hero__link" href="#">Field notes</a></li>
        <li class="hero__item"><a class="hero__link" href="#">Careers</a></li>
      </ul>
      <a class="hero__cta" href="#">Contact</a>
    </nav>
  </header>

  <div class="hero__copy">
    <h1 class="hero__title">Rain falls once. A city can use it five times.</h1>
    <p class="hero__lead">Water reuse plants, built to run for decades.</p>
  </div>

  <div class="hero__foot">
    <a class="hero__down" href="#" aria-label="Scroll to the next section">
      <svg viewBox="0 0 16 18" aria-hidden="true" focusable="false"><path d="M8 1v15M2 10.5 8 16.5l6-6" /></svg>
    </a>
    <a class="hero__chip" href="#">
      <span class="hero__dots" aria-hidden="true"><i></i><i></i><i></i><i></i></span>
      Talk to an engineer
    </a>
  </div>
</section>

<style>
  .hero {
    position: relative;
    isolation: isolate;
    overflow: hidden;
    display: grid;
    grid-template-rows: auto 1fr auto;
    min-height: clamp(40rem, 75vw, 56.25rem);
    background: var(--night) var(--fade);
    color: var(--paper);
  }

  /* Two huge glass circles. Where the upper one dips into the lower one a lens appears, with a dark inner edge and a thread of split light. */
  .hero__glass {
    position: absolute;
    inset: 0;
    z-index: -1;
    width: 100%;
    height: 100%;
    pointer-events: none;
  }
  .hero__upper {
    fill: url(#hero-upper-shade);
    stroke: var(--glass-glow);
    stroke-opacity: 0.35;
    stroke-width: 1.5;
  }
  .hero__lower {
    fill: url(#hero-lower-body);
  }
  .hero__lower-glow {
    fill: url(#hero-lower-glow);
  }
  .hero__lower-rim {
    fill: none;
    stroke: url(#hero-lower-rim);
    stroke-width: 2.5;
  }
  .hero__lens-shade {
    fill: url(#hero-lens-shade);
  }
  .hero__split {
    fill: none;
    stroke-width: 2.6;
  }
  .hero__split--warm {
    stroke: url(#hero-split-warm);
  }
  .hero__split--cool {
    stroke: url(#hero-split-cool);
  }
  .hero__stop-clear {
    stop-color: var(--night);
    stop-opacity: 0;
  }
  .hero__stop-shade-soft {
    stop-color: var(--glass-shade);
    stop-opacity: 0.3;
  }
  .hero__stop-shade {
    stop-color: var(--glass-shade);
  }
  .hero__stop-shade-hard {
    stop-color: var(--night);
    stop-opacity: 0.75;
  }
  .hero__stop-none {
    stop-color: var(--paper);
    stop-opacity: 0;
  }
  .hero__stop-glow {
    stop-color: var(--paper);
    stop-opacity: 0.4;
  }
  .hero__stop-body-top {
    stop-color: var(--ice);
    stop-opacity: 0.16;
  }
  .hero__stop-body-low {
    stop-color: var(--paper);
    stop-opacity: 0.3;
  }
  .hero__stop-rim {
    stop-color: var(--glass-rim);
  }
  .hero__stop-rim-low {
    stop-color: var(--glass-rim);
    stop-opacity: 0.45;
  }
  .hero__stop-warm {
    stop-color: var(--spectrum-warm);
  }
  .hero__stop-rose {
    stop-color: var(--spectrum-rose);
    stop-opacity: 0.7;
  }
  .hero__stop-cool {
    stop-color: var(--spectrum-cool);
  }

  .hero__bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-m);
    padding: var(--space-m) var(--gutter);
  }
  .hero__brand {
    position: relative;
    z-index: 2;
    display: inline-flex;
    align-items: center;
    gap: 0.75rem;
    min-height: var(--control);
    color: inherit;
    text-decoration: none;
  }
  .hero__mark {
    width: 2.875rem;
    height: 1.75rem;
    fill: currentColor;
  }
  .hero__name {
    font-size: 1.375rem;
    font-weight: 500;
    letter-spacing: var(--tracking-title);
  }

  .hero__nav {
    display: flex;
    align-items: center;
    gap: var(--pill-gap);
  }
  .hero__links,
  .hero__sub {
    margin: 0;
    padding: 0;
    list-style: none;
  }
  .hero__links {
    position: relative;
    display: flex;
    gap: var(--pill-gap);
  }
  .hero__item--group {
    position: relative;
  }

  /* Each link is its own milky pill until the script joins them into one chain with a narrow waist between neighbours. */
  .hero__link,
  .hero__sublink {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: var(--space-xs);
    min-height: var(--control);
    padding: 0 1.25rem;
    border: 0;
    border-radius: var(--radius-pill);
    background: var(--glass);
    box-shadow: inset -1px 1px 2px var(--line-dark);
    color: inherit;
    font: inherit;
    font-size: var(--text-s);
    font-weight: 500;
    text-decoration: none;
    white-space: nowrap;
    cursor: pointer;
    transition: color var(--time) ease, opacity var(--time) ease;
  }
  .hero__chain {
    position: absolute;
    inset: 0;
    display: none;
    pointer-events: none;
  }
  .hero__chain-frost,
  .hero__chain-edge {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
  }
  .hero__chain-frost {
    background: var(--glass);
    -webkit-backdrop-filter: blur(12px);
    backdrop-filter: blur(12px);
  }
  .hero__chain-edge {
    overflow: visible;
    fill: none;
    stroke: var(--line-dark);
    stroke-width: 1;
  }
  .hero__links.is-joined .hero__chain {
    display: block;
  }
  .hero__links.is-joined .hero__link {
    background: none;
    box-shadow: none;
  }
  .hero__links:hover .hero__link:not(:hover),
  .hero__links:focus-within .hero__link:not(:focus-visible):not([aria-expanded="true"]) {
    opacity: 0.55;
  }
  .hero__link:focus-visible,
  .hero__sublink:focus-visible,
  .hero__cta:focus-visible,
  .hero__brand:focus-visible,
  .hero__toggle:focus-visible,
  .hero__down:focus-visible,
  .hero__chip:focus-visible {
    outline: 2px solid var(--paper);
    outline-offset: 3px;
  }
  .hero__caret {
    width: 0.625rem;
    height: 0.375rem;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.5;
    stroke-linecap: round;
    stroke-linejoin: round;
    transition: transform var(--time) ease;
  }
  .hero__item--group.is-open .hero__caret {
    transform: scaleY(-1);
  }

  /* The dropdown is more pills hanging under the first one. They drop in one after another. */
  .hero__sub {
    position: absolute;
    top: calc(100% + var(--pill-gap));
    left: 0;
    z-index: 3;
    display: grid;
    justify-items: start;
    gap: var(--pill-gap);
    visibility: hidden;
    transition: visibility 0s linear var(--time);
  }
  .hero__sublink {
    -webkit-backdrop-filter: blur(12px);
    backdrop-filter: blur(12px);
    opacity: 0;
    transform: translateY(-0.5rem);
    transition: opacity var(--time-fast) ease, transform var(--time-fast) ease, background-color var(--time) ease;
  }
  .hero__sublink:hover {
    background: var(--line-dark);
  }
  .hero__item--group.is-open .hero__sub {
    visibility: visible;
    transition-delay: 0s;
  }
  .hero__item--group.is-open .hero__sublink {
    opacity: 1;
    transform: none;
  }
  .hero__item--group.is-open .hero__item + .hero__item .hero__sublink {
    transition-delay: var(--stagger);
  }

  .hero__cta {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: var(--control);
    padding: 0 1.375rem;
    border-radius: var(--radius-pill);
    background: var(--coral);
    color: var(--paper);
    font-weight: 500;
    text-decoration: none;
    transition: background-color var(--time) ease;
  }
  .hero__cta:hover {
    background: var(--coral-press);
  }

  .hero__toggle {
    position: relative;
    z-index: 2;
    display: none;
    place-content: center;
    gap: 0.3125rem;
    width: 3.75rem;
    height: var(--control);
    padding: 0;
    border: 0;
    border-radius: var(--radius-pill);
    background: var(--coral);
    color: var(--paper);
    cursor: pointer;
    transition: background-color var(--time) ease, color var(--time) ease;
  }
  .hero__toggle-line {
    display: block;
    width: 1.375rem;
    height: 1.5px;
    background: currentColor;
    transition: transform var(--time) var(--ease-out);
  }

  .hero__copy {
    display: grid;
    align-content: start;
    justify-items: center;
    gap: var(--space-m);
    padding: clamp(1.5rem, 3.4vw, 3.25rem) var(--gutter) 0;
    text-align: center;
  }
  .hero__title {
    max-width: 6.6em;
    margin: 0;
    font-family: var(--font-display);
    font-size: var(--display-xl);
    font-weight: var(--display-weight);
    font-variation-settings: var(--display-cut);
    line-height: 1;
    letter-spacing: var(--tracking-display);
    text-wrap: balance;
  }
  .hero__lead {
    margin: 0;
    color: var(--mist);
    font-size: var(--title-s);
    letter-spacing: var(--tracking-title);
  }

  .hero__foot {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: end;
    padding: var(--space-l) var(--gutter);
  }
  .hero__down,
  .hero__chip {
    border: 1px solid var(--glass-rim);
    background: var(--glass-pale);
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
    color: var(--deep);
    text-decoration: none;
  }
  .hero__down {
    grid-column: 2;
    display: grid;
    place-items: center;
    width: 3.75rem;
    height: 3.75rem;
    border-radius: 50%;
    transition: transform var(--time) ease;
  }
  .hero__down:hover {
    transform: translateY(0.25rem);
  }
  .hero__down svg {
    width: 1rem;
    height: 1.125rem;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.5;
    stroke-linecap: round;
    stroke-linejoin: round;
  }
  .hero__chip {
    grid-column: 3;
    justify-self: end;
    display: inline-flex;
    align-items: center;
    gap: 0.625rem;
    min-height: var(--control);
    padding: 0 1rem;
    border-radius: var(--radius-pill);
    font-weight: 500;
    transition: background-color var(--time) ease;
  }
  .hero__chip:hover {
    background: var(--glass-rim);
  }

  /* Four coral dots that take turns going faint. */
  .hero__dots {
    display: grid;
    grid-template-columns: repeat(2, 0.25rem);
    gap: 0.1875rem;
  }
  .hero__dots i {
    width: 0.25rem;
    height: 0.25rem;
    border-radius: 50%;
    background: var(--coral);
    animation: hero-pulse var(--time-pulse) linear infinite;
  }
  .hero__dots i:nth-child(2) {
    animation-delay: calc(var(--time-pulse) * 0.25);
  }
  .hero__dots i:nth-child(4) {
    animation-delay: calc(var(--time-pulse) * 0.5);
  }
  .hero__dots i:nth-child(3) {
    animation-delay: calc(var(--time-pulse) * 0.75);
  }
  @keyframes hero-pulse {
    0%,
    100% {
      opacity: 1;
    }
    50% {
      opacity: 0.25;
    }
  }
  .hero.is-resting .hero__dots i {
    animation-play-state: paused;
  }

  /* Below this width the links leave the bar and become a teal sheet over the hero. */
  @media (max-width: 58rem) {
    .hero__glass {
      left: -80%;
      width: 190%;
    }
    .hero__toggle {
      display: grid;
    }
    .hero__nav {
      position: absolute;
      inset: 0;
      z-index: 1;
      flex-direction: column;
      align-items: stretch;
      justify-content: space-between;
      gap: var(--space-l);
      padding: 6.5rem var(--gutter) var(--space-l);
      overflow-y: auto;
      background: var(--deep);
      opacity: 0;
      visibility: hidden;
      transition: opacity var(--time) ease, visibility 0s linear var(--time);
    }
    .hero.is-menu-open .hero__nav {
      opacity: 1;
      visibility: visible;
      transition-delay: 0s;
    }
    .hero.is-menu-open .hero__toggle {
      background: var(--paper);
      color: var(--deep);
    }
    .hero.is-menu-open .hero__toggle-line:first-child {
      transform: translateY(0.2rem) rotate(45deg);
    }
    .hero.is-menu-open .hero__toggle-line:last-child {
      transform: translateY(-0.2rem) rotate(-45deg);
    }
    .hero__links,
    .hero__sub {
      position: static;
      display: block;
      justify-items: stretch;
      visibility: inherit;
    }
    /* Every row opens with a hairline that turns down at its right end. */
    .hero__links .hero__link,
    .hero__sublink {
      display: flex;
      min-height: 3.75rem;
      padding: 0;
      border-top: 1px solid var(--line-dark);
      border-right: 1px solid var(--line-dark);
      border-radius: 0 var(--radius-tick) 0 0;
      background: none;
      box-shadow: none;
      -webkit-backdrop-filter: none;
      backdrop-filter: none;
      -webkit-mask: linear-gradient(var(--ink) var(--tick), transparent var(--tick)) border-box, linear-gradient(var(--ink) 0 0) padding-box;
      mask: linear-gradient(var(--ink) var(--tick), transparent var(--tick)) border-box, linear-gradient(var(--ink) 0 0) padding-box;
      font-size: var(--title-m);
      font-weight: 400;
      letter-spacing: var(--tracking-title);
      opacity: 0;
      transform: translateY(1rem);
      transition: opacity var(--time-slow) var(--ease-out), transform var(--time-slow) var(--ease-out);
    }
    .hero.is-menu-open .hero__link,
    .hero.is-menu-open .hero__sublink {
      opacity: 1;
      transform: none;
      transition-delay: calc(var(--stagger) * var(--hero-row, 0));
    }
    .hero__links .hero__chain,
    .hero__links .hero__link--group {
      display: none;
    }
    .hero__cta {
      min-height: 3.5rem;
    }

    .hero__copy {
      justify-items: start;
      padding-top: var(--space-s);
      text-align: left;
    }
    .hero__foot {
      grid-template-columns: 1fr;
      justify-items: start;
      gap: var(--space-l);
    }
    .hero__down,
    .hero__chip {
      grid-column: 1;
      justify-self: start;
    }
    .hero__chip {
      grid-row: 1;
    }
  }

  @media (prefers-reduced-motion: reduce) {
    .hero__dots i {
      animation: none;
    }
    .hero__link,
    .hero__sublink,
    .hero__nav,
    .hero__down,
    .hero__toggle-line {
      transition-duration: 0s;
      transition-delay: 0s;
    }
  }
</style>

<script>
  (() => {
    const INTRO_SECONDS = 1.4;
    const POINTER_EASE = 0.05;
    const reducedMotion = matchMedia("(prefers-reduced-motion: reduce)");

    /* Where a small circle of radius `neck` touches two pill ends whose centres are `span` apart. */
    function waist(leftCentre, rightCentre, radius, neck) {
      const half = (rightCentre - leftCentre) / 2;
      const reach = radius + neck;
      const drop = Math.sqrt(Math.max(reach * reach - half * half, 0));
      const inset = (radius * half) / reach;
      const lift = (radius * drop) / reach;
      return { from: leftCentre + inset, to: rightCentre - inset, top: radius - lift, bottom: radius + lift };
    }

    function chainPath(pills, height, neck) {
      const r = height / 2;
      const arc = (radius, sweep, x, y) => `A${radius},${radius} 0 0 ${sweep} ${x},${y}`;
      let path = `M${pills[0].left + r},0`;
      pills.forEach((pill, index) => {
        const next = pills[index + 1];
        path += `H${pill.right - r}`;
        if (!next) {
          path += arc(r, 1, pill.right - r, height);
          return;
        }
        const join = waist(pill.right - r, next.left + r, r, neck);
        path += arc(r, 1, join.from, join.top) + arc(neck, 0, join.to, join.top) + arc(r, 1, next.left + r, 0);
      });
      [...pills].reverse().forEach((pill, index, reversed) => {
        const previous = reversed[index + 1];
        path += `H${pill.left + r}`;
        if (!previous) {
          path += arc(r, 1, pill.left + r, 0) + "Z";
          return;
        }
        const join = waist(previous.right - r, pill.left + r, r, neck);
        path += arc(r, 1, join.to, join.bottom) + arc(neck, 0, join.from, join.bottom) + arc(r, 1, previous.right - r, height);
      });
      return path;
    }

    function setUpChain(root) {
      const list = root.querySelector(".hero__links");
      const frost = root.querySelector(".hero__chain-frost");
      const edge = root.querySelector(".hero__chain-edge path");
      const links = [...list.querySelectorAll(".hero__link")];

      function draw() {
        const box = list.getBoundingClientRect();
        const pills = links
          .map((link) => link.getBoundingClientRect())
          .filter((rect) => rect.width > 0)
          .map((rect) => ({ left: rect.left - box.left, right: rect.right - box.left }));
        const joined = pills.length > 1 && getComputedStyle(list).display === "flex";
        list.classList.toggle("is-joined", joined);
        if (!joined) return;
        const neck = parseFloat(getComputedStyle(list).getPropertyValue("--neck")) * parseFloat(getComputedStyle(list).fontSize);
        const path = chainPath(pills, box.height, neck);
        frost.style.clipPath = `path("${path}")`;
        edge.setAttribute("d", path);
      }

      new ResizeObserver(draw).observe(list);
      document.fonts.ready.then(draw);
      draw();
    }

    function setUpMenu(root) {
      const toggle = root.querySelector(".hero__toggle");
      const group = root.querySelector(".hero__item--group");
      const groupButton = group.querySelector(".hero__link--group");
      const rows = root.querySelectorAll(".hero__sublink, .hero__link:not(.hero__link--group)");
      rows.forEach((row, index) => row.style.setProperty("--hero-row", index));

      function showMenu(open) {
        root.classList.toggle("is-menu-open", open);
        toggle.setAttribute("aria-expanded", open);
      }
      function showGroup(open) {
        group.classList.toggle("is-open", open);
        groupButton.setAttribute("aria-expanded", open);
      }

      toggle.addEventListener("click", () => showMenu(!root.classList.contains("is-menu-open")));
      groupButton.addEventListener("click", () => showGroup(!group.classList.contains("is-open")));
      group.addEventListener("pointerenter", (event) => event.pointerType === "mouse" && showGroup(true));
      group.addEventListener("pointerleave", (event) => event.pointerType === "mouse" && showGroup(false));
      group.addEventListener("focusout", (event) => group.contains(event.relatedTarget) || showGroup(false));
      root.addEventListener("keydown", (event) => {
        if (event.key !== "Escape") return;
        showGroup(false);
        showMenu(false);
      });
    }

    /* The two circles slide into place, then drift a few pixels and lean away from the pointer. */
    function setUpGlass(root) {
      const rings = [...root.querySelectorAll("[data-hero-ring]")].map((circle) => ({
        circle,
        upper: circle.dataset.heroRing === "upper",
        home: { x: Number(circle.getAttribute("cx")), y: Number(circle.getAttribute("cy")) },
      }));
      const pointer = { x: 0, y: 0 };
      const lean = { x: 0, y: 0 };
      let started = 0;
      let frame = 0;

      function place(now) {
        started ||= now;
        const seconds = (now - started) / 1000;
        const apart = (1 - Math.min(seconds / INTRO_SECONDS, 1)) ** 3;
        lean.x += (pointer.x - lean.x) * POINTER_EASE;
        lean.y += (pointer.y - lean.y) * POINTER_EASE;
        const upper = { x: Math.sin(seconds / 7) * 10 + lean.x * 10, y: Math.cos(seconds / 9) * 8 + lean.y * 8 - apart * 150 };
        const lower = { x: -Math.sin(seconds / 8) * 14 - lean.x * 16, y: Math.sin(seconds / 6) * 10 - lean.y * 12 + apart * 190 };
        rings.forEach(({ circle, upper: isUpper, home }) => {
          const shift = isUpper ? upper : lower;
          circle.setAttribute("cx", home.x + shift.x);
          circle.setAttribute("cy", home.y + shift.y);
        });
        frame = requestAnimationFrame(place);
      }

      root.addEventListener("pointermove", (event) => {
        const box = root.getBoundingClientRect();
        pointer.x = (event.clientX - box.left) / box.width - 0.5;
        pointer.y = (event.clientY - box.top) / box.height - 0.5;
      });
      root.addEventListener("pointerleave", () => Object.assign(pointer, { x: 0, y: 0 }));

      new IntersectionObserver(([entry]) => {
        const moving = entry.isIntersecting && !reducedMotion.matches;
        root.classList.toggle("is-resting", !entry.isIntersecting);
        cancelAnimationFrame(frame);
        if (moving) frame = requestAnimationFrame(place);
      }).observe(root);
    }

    document.querySelectorAll(".hero").forEach((root) => {
      setUpChain(root);
      setUpMenu(root);
      setUpGlass(root);
    });
  })();
</script>

Similar components

Sky hero

Sky hero

Split hero

Split hero

Haze hero

Haze hero

Masthead

Masthead

Glass word with falling stickers

Glass word with falling stickers

Masthead

Masthead

Cover

Cover

Hero with device panel

Hero with device panel