Components / KATAYABURI / Bounce Letters

Bounce Letters beta

A headline whose letters hop when touched — and do the wave when you click.

Preview

THANK YOU!

Touch a letter. Click for the wave.

<p class="k-bnc" data-bounce style="font-size:29px;font-weight:700;letter-spacing:-.01em">THANK YOU!</p>
<p style="font-size:12.5px;color:var(--k-ink-3);margin-top:8px">Touch a letter. Click for the wave.</p>
/* KATA Bounce Letters — KATAYABURI. A headline with springs. */
.k-bnc{font-family:var(--k-font);cursor:pointer}
.k-bnc .ch{display:inline-block;transition:transform .34s cubic-bezier(.3,2.3,.4,1)}
.k-bnc .ch:hover{transform:translateY(-11px)}
.k-bnc.waving .ch{transform:translateY(-12px)}
@media (prefers-reduced-motion:reduce){.k-bnc .ch{transition:none}.k-bnc .ch:hover,.k-bnc.waving .ch{transform:none}}
// KATA Bounce Letters — splits the line; the click sends a wave.
document.querySelectorAll('[data-bounce]').forEach(function (el) {
  var text = el.textContent.trim();
  el.setAttribute('aria-label', text);
  el.textContent = '';
  var wrap = document.createElement('span');
  wrap.setAttribute('aria-hidden', 'true');
  text.split('').forEach(function (ch) {
    var s = document.createElement('span');
    s.className = 'ch';
    s.textContent = ch === ' ' ? ' ' : ch;
    wrap.appendChild(s);
  });
  el.appendChild(wrap);
  var letters = wrap.querySelectorAll('.ch');
  el.addEventListener('click', function () {
    letters.forEach(function (s, i) { s.style.transitionDelay = (i * 26) + 'ms'; });
    el.classList.add('waving');
    setTimeout(function () {
      el.classList.remove('waving');
      setTimeout(function () { letters.forEach(function (s) { s.style.transitionDelay = ''; }); }, 420);
    }, 340 + letters.length * 26);
  });
});

Installation

CLI

node kata-ui.mjs add bounce-letters

Writes the part’s CSS and JS into your project. New to the CLI? See the CLI doc.

Manual

  1. Load tokens.css once, before any part.
  2. Copy the CSS tab into your stylesheet.
  3. Copy the HTML where it belongs. The part has a script — include it after the markup; it initializes itself.

Usage

The script splits the headline into letter spans; a hover hops one letter on a spring curve, and a click sends a staggered wave down the line. For the one headline a page is allowed to show off with — a launch name, a thank-you, a very confident 404.

Accessibility

The unsplit sentence lives in an aria-label and the letters are aria-hidden confetti — screen readers get the headline, not forty separate hops. Under prefers-reduced-motion the letters stand still and take their bow as text.

Anatomy

The public surface of this part, read from its own source. Class names are the API — the CSS tab above is the full contract.

.k-bncclass
.chclass
.wavingclass
data-bouncedata hook

Related parts