kitbash Sign in Connect agent
Components

Refracting headline

The signature piece. A glass disc and a glass tile with a lens set into it wander over a centred serif headline and magnify the text beneath them, more at the rim than in the middle. The disc follows the pointer.

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 */
@import url("https://fonts.googleapis.com/css2?family=Archivo:ital,wdth,wght@0,62..125,400..900;1,62..125,400..900&display=swap");
:root {
  --font-display: "Archivo", "Helvetica Neue", Arial, sans-serif;
  --font-text: "Archivo", "Helvetica Neue", Arial, sans-serif;
}
</style>

<section class="lens">
  <div class="lens__scene">
    <h2 class="lens__title">Every stage of the loop, under one roof</h2>
    <p class="lens__sub">Intake, treatment, storage and return.</p>
  </div>

  <div class="lens__glass lens__glass--disc" aria-hidden="true">
    <div class="lens__pane lens__pane--rim"></div>
    <div class="lens__pane lens__pane--core"></div>
    <span class="lens__sheen"></span>
  </div>
  <div class="lens__glass lens__glass--tile" aria-hidden="true">
    <div class="lens__pane lens__pane--core"></div>
    <span class="lens__sheen"></span>
  </div>
</section>

<style>
  .lens {
    position: relative;
    container-type: size;
    overflow: hidden;
    height: clamp(30rem, 75vw, 48rem);
    background: var(--deep);
    color: var(--paper);
  }

  .lens__scene {
    position: absolute;
    inset: 0;
    display: grid;
    align-content: center;
    justify-items: center;
    gap: var(--space-m);
    padding: 0 var(--gutter) 12cqh;
    background: var(--fade-dark);
    text-align: center;
  }
  .lens__title {
    max-width: 10em;
    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;
  }
  .lens__sub {
    margin: 0;
    color: var(--mist);
    font-size: var(--title-s);
    letter-spacing: var(--tracking-title);
  }

  /* A glass sits at --x, --y (fractions of the panel). Each pane inside it shows a second copy of the scene,
     pinned to the same spot and enlarged around the centre of the glass, so the headline bends as glass passes over it. */
  .lens__glass {
    --x: var(--home-x);
    --y: var(--home-y);
    --roam: 0.07;
    --half: calc(var(--size) / 2);
    position: absolute;
    top: 0;
    left: 0;
    width: var(--size);
    height: var(--size);
    transform: translate(calc(var(--x) * 100cqw - var(--half)), calc(var(--y) * 100cqh - var(--half)));
    pointer-events: none;
  }
  .lens__glass--disc {
    --size: clamp(15rem, 33cqw, 30rem);
    --home-x: 0.32;
    --home-y: 0.42;
    border-radius: 50%;
  }
  .lens__glass--tile {
    --size: clamp(15.5rem, 34.5cqw, 31rem);
    --home-x: 0.66;
    --home-y: 0.42;
    border: 1px solid var(--line-dark);
    border-radius: var(--radius-tile);
    background: var(--glass);
    box-shadow: inset 0 0 2rem var(--glass);
  }

  .lens__pane {
    --reach: calc(var(--half) - var(--inset));
    position: absolute;
    inset: var(--inset);
    overflow: hidden;
    border-radius: 50%;
  }
  .lens__pane--rim {
    --inset: 0px;
    --power: 1.24;
  }
  .lens__pane--core {
    --inset: calc(var(--size) * 0.055);
    --power: 1.1;
  }
  .lens__glass--tile .lens__pane--core {
    --inset: calc(var(--size) * 0.025);
    --power: 1.14;
    box-shadow: 0 0 0 1px var(--glass-glow);
  }
  .lens__pane .lens__scene {
    inset: 0 auto auto 0;
    width: 100cqw;
    height: 100cqh;
    transform-origin: calc(var(--x) * 100cqw) calc(var(--y) * 100cqh);
    transform: translate(calc(var(--reach) - var(--x) * 100cqw), calc(var(--reach) - var(--y) * 100cqh)) scale(var(--power));
  }

  /* Light on the glass: a pale edge, a soft glow inside it, a darker lower lip and one bright arc top left. */
  .lens__sheen {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    box-shadow:
      inset 0 0 0 1px var(--line-dark),
      inset 0 0 2.5rem var(--glass),
      inset 0 -0.75rem 1.75rem -0.75rem var(--glass-shade);
  }
  .lens__glass--tile .lens__sheen {
    inset: calc(var(--size) * 0.025);
  }
  .lens__sheen::before {
    content: "";
    position: absolute;
    inset: 0.25rem;
    border: 0.1875rem solid var(--glass-glow);
    border-radius: 50%;
    filter: blur(1px);
    -webkit-mask: conic-gradient(from 285deg, transparent, var(--ink) 25deg, var(--ink) 60deg, transparent 95deg);
    mask: conic-gradient(from 285deg, transparent, var(--ink) 25deg, var(--ink) 60deg, transparent 95deg);
  }
  .lens__glass--tile .lens__sheen::before {
    -webkit-mask: conic-gradient(from 100deg, transparent, var(--ink) 30deg, var(--ink) 50deg, transparent 80deg);
    mask: conic-gradient(from 100deg, transparent, var(--ink) 30deg, var(--ink) 50deg, transparent 80deg);
  }

  @media (max-width: 40rem) {
    .lens__glass {
      --roam: 0.03;
    }
    .lens__glass--disc {
      --size: 54cqw;
      --home-x: 0.32;
      --home-y: 0.34;
    }
    .lens__glass--tile {
      --size: 54cqw;
      --home-x: 0.64;
      --home-y: 0.6;
    }
    .lens__scene {
      padding-bottom: 0;
    }
  }
</style>

<script>
  (() => {
    const FOLLOW = 0.07;
    const reducedMotion = matchMedia("(prefers-reduced-motion: reduce)");

    function mirrorScene(root) {
      const scene = root.querySelector(".lens__scene");
      root.querySelectorAll(".lens__pane").forEach((pane) => pane.append(scene.cloneNode(true)));
    }

    function readGlass(element, index) {
      const style = getComputedStyle(element);
      const read = (name) => parseFloat(style.getPropertyValue(name));
      const home = { x: read("--home-x"), y: read("--home-y") };
      return { element, home, at: { ...home }, roam: read("--roam"), phase: index * 2.4, followsPointer: index === 0 };
    }

    function setUpDrift(root) {
      const glasses = [...root.querySelectorAll(".lens__glass")].map(readGlass);
      let pointer = null;
      let frame = 0;

      function driftSpot(glass, seconds) {
        return {
          x: glass.home.x + Math.sin(seconds / 5 + glass.phase) * glass.roam,
          y: glass.home.y + Math.cos(seconds / 3.4 + glass.phase) * glass.roam,
        };
      }
      function move(now) {
        const seconds = now / 1000;
        glasses.forEach((glass) => {
          const target = glass.followsPointer && pointer ? pointer : driftSpot(glass, seconds);
          glass.at.x += (target.x - glass.at.x) * FOLLOW;
          glass.at.y += (target.y - glass.at.y) * FOLLOW;
          glass.element.style.setProperty("--x", glass.at.x.toFixed(4));
          glass.element.style.setProperty("--y", glass.at.y.toFixed(4));
        });
        frame = requestAnimationFrame(move);
      }

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

      new IntersectionObserver(([entry]) => {
        cancelAnimationFrame(frame);
        if (entry.isIntersecting && !reducedMotion.matches) frame = requestAnimationFrame(move);
      }).observe(root);
    }

    document.querySelectorAll(".lens").forEach((root) => {
      mirrorScene(root);
      setUpDrift(root);
    });
  })();
</script>

Similar components

Statement with pictures

Statement with pictures

Lead entry

Lead entry

Text columns with small figures

Text columns with small figures

Mixed-type headline

Mixed-type headline

Scroll-lit reading

Scroll-lit reading

Essay

Essay

Profile

Profile

Project chapter

Project chapter