kitbash Sign in Connect agent
Components

Badge intro

The signature: an empty field where a huge blue oval wordmark pops in, swings away, and leaves a small green badge that drifts and bounces off the edges, changing colour on every hit. A (?) in the corner opens switches for bounce, colour, pointer follow, add one and reset.

Part of the style

Sticker Badge Studio

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

Preview

Code
<style>
/* Goes after the pack's base.css */
:root {
  --ink: #5e352b;
  --paper: #d5e8e6;
  --flood-shade: rgba(94, 53, 43, 0.82);
  --veil: rgba(213, 232, 230, 0.86);
  --signal-blue: #7c6052;
  --card-screen: #785f52;
  --card-screen-chip: #90786c;
  --card-lilac: #bcaaa1;
  --signal-red: #845a3e;
  --card-pink: #c7a898;
  --signal-green: #d0a284;
  --card-lemon: #cdac97;
  --card-mint: #b9aaa1;
  --card-moss: #796152;
}
</style>

<section class="intro" aria-label="blip, a computational design studio">
  <div class="intro__field">
    <button class="intro__mark" type="button" aria-label="skip the intro"><span class="intro__word">blip</span></button>
  </div>

  <button class="intro__help" type="button" aria-expanded="false" aria-label="badge settings">(?)</button>

  <div class="intro__panel" role="group" aria-label="badge settings">
    <button class="intro__switch" type="button" role="switch" aria-checked="true" data-option="bounce">
      <span class="intro__switch-label">bounce off edges</span><span class="intro__switch-state">on</span><span class="intro__knob" aria-hidden="true"></span>
    </button>
    <button class="intro__switch" type="button" role="switch" aria-checked="true" data-option="recolour">
      <span class="intro__switch-label">new colour on every hit</span><span class="intro__switch-state">on</span><span class="intro__knob" aria-hidden="true"></span>
    </button>
    <button class="intro__switch" type="button" role="switch" aria-checked="false" data-option="follow">
      <span class="intro__switch-label">follow the pointer</span><span class="intro__switch-state">off</span><span class="intro__knob" aria-hidden="true"></span>
    </button>
    <button class="intro__switch" type="button" role="switch" aria-checked="false" data-option="hurry">
      <span class="intro__switch-label">in a hurry</span><span class="intro__switch-state">off</span><span class="intro__knob" aria-hidden="true"></span>
    </button>
    <button class="intro__action" type="button" data-action="add">add one</button>
    <button class="intro__action" type="button" data-action="reset">start over</button>
  </div>
</section>

<style>
  .intro {
    position: relative;
    height: var(--stage-height);
    overflow: hidden;
    background: var(--paper);
  }
  .intro__field {
    position: absolute;
    inset: 0;
    overflow: hidden;
  }

  /* The big mark: an italic word inside an oval drawn with the same stroke as its letters. */
  .intro__mark {
    position: absolute;
    top: 50%;
    left: 50%;
    padding: 0.06em 0.4em 0.14em 0.36em;
    border: var(--ring) solid currentColor;
    border-radius: 50%;
    background: none;
    color: var(--signal-blue);
    font-family: var(--font-text);
    font-size: var(--mark-size);
    font-stretch: var(--stretch-mark);
    font-style: italic;
    font-weight: var(--weight-mark);
    line-height: 0.95;
    letter-spacing: var(--tracking-mark);
    text-transform: lowercase;
    white-space: nowrap;
    cursor: pointer;
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.85);
    transition: transform 0.4s var(--ease-pop), opacity var(--time) var(--ease);
  }
  .intro__word {
    display: block;
    translate: -0.03em 0;
  }
  .intro.is-ready .intro__mark {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
  .intro.is-ready.is-shrunk .intro__mark {
    opacity: 0;
    visibility: hidden;
    transform: translate(-50%, -50%) scale(0.06) rotate(-12deg);
    transition: transform var(--time-slow) var(--ease-swing), opacity var(--time-slow) var(--ease), visibility 0s linear var(--time-slow);
  }
  .intro__mark:focus-visible {
    outline: 2px solid var(--ink);
    outline-offset: 0.1em;
  }

  /* The small badge that drifts. */
  .intro__badge {
    position: absolute;
    top: 0;
    left: 0;
    padding: 0.1em 0.5em 0.06em;
    border: 0.11em solid currentColor;
    border-radius: 50%;
    font-size: var(--badge-size);
    line-height: 1;
    text-transform: uppercase;
    white-space: nowrap;
    pointer-events: none;
    will-change: transform;
    transition: color var(--time-fast) var(--ease);
  }
  .intro__badge.is-green { color: var(--signal-green); }
  .intro__badge.is-blue { color: var(--signal-blue); }
  .intro__badge.is-red { color: var(--signal-red); }
  .intro__badge.is-ink { color: var(--ink); }

  /* The (?) in the corner and its switches. */
  .intro__help {
    position: absolute;
    bottom: 0;
    left: 0;
    z-index: 2;
    min-width: var(--tap);
    min-height: var(--tap);
    padding: 0 var(--edge);
    border: 0;
    background: none;
    color: var(--ink);
    font: inherit;
    cursor: pointer;
    transition: color var(--time) var(--ease);
  }
  .intro__help:hover { color: var(--signal-red); }
  .intro__help:focus-visible,
  .intro__switch:focus-visible,
  .intro__action:focus-visible {
    outline: 2px solid var(--signal-blue);
    outline-offset: -2px;
  }
  .intro__panel {
    position: absolute;
    right: var(--edge);
    bottom: var(--edge);
    z-index: 2;
    display: grid;
    width: min(22rem, 100% - 2 * var(--edge));
    background: var(--paper);
    font-size: var(--text-s);
    opacity: 0;
    visibility: hidden;
    translate: 0 0.75rem;
    transition: opacity var(--time) var(--ease), translate 0.4s var(--ease-pop), visibility 0s linear var(--time);
  }
  .intro.is-open .intro__panel {
    opacity: 1;
    visibility: visible;
    translate: 0 0;
    transition: opacity var(--time) var(--ease), translate 0.4s var(--ease-pop), visibility 0s;
  }
  .intro__switch,
  .intro__action {
    min-height: var(--tap);
    padding: 0;
    border: 0;
    border-bottom: var(--rule) solid var(--ink);
    background: none;
    color: var(--ink);
    font: inherit;
    cursor: pointer;
  }
  .intro__switch {
    display: grid;
    grid-template-columns: 1fr auto auto;
    align-items: end;
    gap: var(--space-s);
    padding-bottom: 0.3em;
    text-align: left;
  }
  .intro__action {
    padding-top: 0.6em;
    padding-bottom: 0.3em;
    text-align: center;
    transition: color var(--time) var(--ease);
  }
  .intro__switch:hover .intro__switch-label,
  .intro__action:hover {
    color: var(--signal-red);
  }
  .intro__knob {
    position: relative;
    width: 2em;
    height: 1em;
    border: var(--rule) solid currentColor;
    border-radius: 1em;
  }
  .intro__knob::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 0.14em;
    width: 0.56em;
    height: 0.56em;
    border: var(--rule) solid currentColor;
    border-radius: 50%;
    translate: 0 -50%;
    transition: translate var(--time-fast) var(--ease);
  }
  .intro__switch[aria-checked="true"] .intro__knob::after {
    translate: 0.98em -50%;
  }

  @media (max-width: 40rem) {
    .intro__panel {
      bottom: calc(var(--tap) + var(--edge));
    }
  }

  @media (prefers-reduced-motion: reduce) {
    .intro__mark,
    .intro.is-ready.is-shrunk .intro__mark {
      transition: none;
    }
  }
</style>

<script>
(() => {
  const COLOURS = ['is-green', 'is-blue', 'is-red', 'is-ink'];
  const MOST_BADGES = 30;
  const FIRST_BADGE_AT = 600;
  const MARK_LEAVES_AT = 2600;
  const HURRY = 4;
  const FOLLOW = 3;
  const STILL = window.matchMedia('(prefers-reduced-motion: reduce)');

  function speedOf(root) {
    return parseFloat(getComputedStyle(root).getPropertyValue('--drift-speed')) || 26;
  }

  function setUp(root) {
    const field = root.querySelector('.intro__field');
    const mark = root.querySelector('.intro__mark');
    const help = root.querySelector('.intro__help');
    const options = { bounce: true, recolour: true, follow: false, hurry: false };
    const badges = [];
    const timers = [];
    let pointer = null;
    let visible = false;
    let frame = 0;
    let last = 0;

    const cruise = () => speedOf(root) * (options.hurry ? HURRY : 1);
    const size = () => ({ width: field.clientWidth, height: field.clientHeight });

    function paint(badge) {
      badge.el.style.transform = `translate(${badge.x}px, ${badge.y}px)`;
    }

    function recolour(badge) {
      badge.el.classList.remove(COLOURS[badge.colour]);
      badge.colour = (badge.colour + 1) % COLOURS.length;
      badge.el.classList.add(COLOURS[badge.colour]);
    }

    function addBadge(x, y, colour) {
      if (badges.length >= MOST_BADGES) badges.shift().el.remove();
      const el = document.createElement('span');
      el.className = `intro__badge ${COLOURS[colour]}`;
      el.textContent = 'blip';
      el.setAttribute('aria-hidden', 'true');
      field.append(el);
      const angle = (Math.floor(Math.random() * 4) + 0.5) * (Math.PI / 2) + (Math.random() - 0.5) * 0.5;
      const badge = { el, x, y, colour, vx: Math.cos(angle) * cruise(), vy: Math.sin(angle) * cruise(), w: el.offsetWidth, h: el.offsetHeight };
      badge.x = Math.min(Math.max(0, x - badge.w / 2), size().width - badge.w);
      badge.y = Math.min(Math.max(0, y - badge.h / 2), size().height - badge.h);
      badges.push(badge);
      paint(badge);
      return badge;
    }

    function addRandomBadge() {
      const { width, height } = size();
      addBadge(Math.random() * width, Math.random() * height, Math.floor(Math.random() * COLOURS.length));
    }

    function bounce(badge, width, height) {
      let hit = false;
      if (badge.x < 0) { badge.x = 0; badge.vx = Math.abs(badge.vx); hit = true; }
      if (badge.x > width - badge.w) { badge.x = width - badge.w; badge.vx = -Math.abs(badge.vx); hit = true; }
      if (badge.y < 0) { badge.y = 0; badge.vy = Math.abs(badge.vy); hit = true; }
      if (badge.y > height - badge.h) { badge.y = height - badge.h; badge.vy = -Math.abs(badge.vy); hit = true; }
      if (hit && options.recolour) recolour(badge);
    }

    function wrap(badge, width, height) {
      if (badge.x > width) badge.x = -badge.w;
      if (badge.x < -badge.w) badge.x = width;
      if (badge.y > height) badge.y = -badge.h;
      if (badge.y < -badge.h) badge.y = height;
    }

    function steer(badge, dt) {
      const speed = Math.hypot(badge.vx, badge.vy) || 1;
      let targetX = (badge.vx / speed) * cruise();
      let targetY = (badge.vy / speed) * cruise();
      if (options.follow && pointer) {
        const dx = pointer.x - (badge.x + badge.w / 2);
        const dy = pointer.y - (badge.y + badge.h / 2);
        const distance = Math.hypot(dx, dy) || 1;
        targetX = (dx / distance) * cruise() * FOLLOW;
        targetY = (dy / distance) * cruise() * FOLLOW;
      }
      const pull = Math.min(1, dt * 2.5);
      badge.vx += (targetX - badge.vx) * pull;
      badge.vy += (targetY - badge.vy) * pull;
    }

    function move(badge, dt, width, height) {
      steer(badge, dt);
      badge.x += badge.vx * dt;
      badge.y += badge.vy * dt;
      if (options.bounce) bounce(badge, width, height);
      else wrap(badge, width, height);
      paint(badge);
    }

    function tick(now) {
      const dt = Math.min(0.05, (now - last) / 1000 || 0);
      last = now;
      const { width, height } = size();
      for (const badge of badges) move(badge, dt, width, height);
      frame = requestAnimationFrame(tick);
    }

    function play() {
      if (frame || !visible || STILL.matches) return;
      last = performance.now();
      frame = requestAnimationFrame(tick);
    }

    function pause() {
      cancelAnimationFrame(frame);
      frame = 0;
    }

    function shrinkMark() {
      root.classList.add('is-shrunk');
    }

    function startIntro() {
      timers.splice(0).forEach(clearTimeout);
      badges.splice(0).forEach((badge) => badge.el.remove());
      root.classList.remove('is-ready', 'is-shrunk');
      requestAnimationFrame(() => requestAnimationFrame(() => root.classList.add('is-ready')));
      timers.push(setTimeout(() => {
        const { width, height } = size();
        addBadge(width * 0.2, height * 0.42, 0);
      }, FIRST_BADGE_AT));
      timers.push(setTimeout(shrinkMark, MARK_LEAVES_AT));
    }

    function setOption(button) {
      const on = button.getAttribute('aria-checked') !== 'true';
      button.setAttribute('aria-checked', String(on));
      button.querySelector('.intro__switch-state').textContent = on ? 'on' : 'off';
      options[button.dataset.option] = on;
    }

    function setPanelOpen(open) {
      root.classList.toggle('is-open', open);
      help.setAttribute('aria-expanded', String(open));
      help.textContent = open ? '(×)' : '(?)';
      root.querySelector('.intro__panel').inert = !open;
    }

    mark.addEventListener('click', shrinkMark);
    help.addEventListener('click', () => setPanelOpen(!root.classList.contains('is-open')));
    root.querySelectorAll('.intro__switch').forEach((button) => button.addEventListener('click', () => setOption(button)));
    root.querySelector('[data-action="add"]').addEventListener('click', addRandomBadge);
    root.querySelector('[data-action="reset"]').addEventListener('click', startIntro);
    root.addEventListener('keydown', (event) => {
      if (event.key === 'Escape' && root.classList.contains('is-open')) { setPanelOpen(false); help.focus(); }
    });
    root.addEventListener('pointermove', (event) => {
      const box = field.getBoundingClientRect();
      pointer = { x: event.clientX - box.left, y: event.clientY - box.top };
    });
    root.addEventListener('pointerleave', () => { pointer = null; });

    new ResizeObserver(() => {
      const { width, height } = size();
      for (const badge of badges) {
        badge.x = Math.min(badge.x, Math.max(0, width - badge.w));
        badge.y = Math.min(badge.y, Math.max(0, height - badge.h));
        paint(badge);
      }
    }).observe(field);

    new IntersectionObserver(([entry]) => {
      visible = entry.isIntersecting;
      if (visible) play(); else pause();
    }).observe(root);

    STILL.addEventListener('change', () => (STILL.matches ? pause() : play()));
    setPanelOpen(false);
    startIntro();
  }

  document.querySelectorAll('.intro').forEach(setUp);
})();
</script>

Similar components

Wordmark intro

Wordmark intro

Greeting loader

Greeting loader

Counter loader

Counter loader

Wordmark intro

Wordmark intro

Boot screen

Boot screen

Loading screen

Loading screen

Intro loader

Intro loader

Film reel

Film reel