[Lab 03]AWAIS MALIK

Letter roll

Each letter slides up and a coloured copy rolls in behind it, one after another. Used in the full-screen menu and pixel buttons.

  • Pure CSS hover
  • Tiny JS splitter

Jump to the code ↓03 / 04

index.html1 line
<a href="#" data-roll>Start a project</a>
roll.css21 lines
.roll-char {
  position: relative;
  display: inline-block;
  overflow: clip;
  padding-block: 0.04em; /* keeps glyph tops and bottoms out of the clip */
}
.roll-char > span {
  display: block;
  transition: transform 0.65s cubic-bezier(0.16, 1, 0.3, 1);
  transition-delay: calc(var(--i) * 22ms);
}
.roll-char > span + span {
  position: absolute;
  inset: 0.04em 0;
  transform: translateY(110%);
  color: var(--roll-color, #d6ff3b);
}
a:hover .roll-char > span:first-child,
a:focus-visible .roll-char > span:first-child { transform: translateY(-110%); }
a:hover .roll-char > span + span,
a:focus-visible .roll-char > span + span { transform: translateY(0); }
roll.js11 lines
// Wraps every letter in two stacked copies; screen readers get the plain text.
document.querySelectorAll("[data-roll]").forEach((el) => {
  const text = el.textContent;
  el.setAttribute("aria-label", text);
  el.innerHTML = [...text]
    .map((ch, i) => {
      const c = ch === " " ? "&nbsp;" : ch;
      return `<span class="roll-char" aria-hidden="true" style="--i:${i}"><span>${c}</span><span>${c}</span></span>`;
    })
    .join("");
});

Next experiment

Spotlight card →