Anchored Auto Layout
npm

Hover or focus a box to measure it. Click its tag, or press ] and [, to pin one. Esc unpins.

    Legend
    • Anchor: a box with data-⚓️-name
    • Placed by anchors: out of flow
    • Gap from the anchor's edge, in px
    • Edges of the box you're inspecting

    Every tag, line and number here is itself placed by data-⚓️-* attributes. JS only measures.

    Barrel roll number counter: digits glide between anchored slots

    A live count up/count down number where every digit is a ten-numeral barrel.

    Full page
    <main class="demo">
      <header class="intro">
        <h1>Barrel roll counter</h1>
        <p>
          Every digit column is a drum of ten numerals. Underneath, each column is a grid of invisible slots, and
          the slot a numeral sits in is just its distance from the current digit. Each visible numeral is
          <code>data-⚓️-fill</code> on its slot with <code>data-⚓️-transition="glide"</code>, so when the number changes the
          slots reflow <em>instantly</em> and the numerals glide, roll and fade into their new places, up and down or left and right.
          Add a digit and the whole row reflows: the commas, the numerals and the backing lens (anchored to the row) all glide to the new layout.
          The script only writes the number and each slot's offset.
        </p>
      </header>
    
      <form class="controls" aria-label="Counter controls" onsubmit="return false">
        <label class="field">
          <span>Number</span>
          <input id="num" type="number" inputmode="numeric" min="0" max="99999999" step="1" value="1234">
        </label>
        <div class="steps" role="group" aria-label="Step the number">
          <button type="button" data-step="-100">−100</button>
          <button type="button" data-step="-10">−10</button>
          <button type="button" data-step="-1">−1</button>
          <button type="button" data-step="1">+1</button>
          <button type="button" data-step="10">+10</button>
          <button type="button" data-step="100">+100</button>
        </div>
        <button type="button" id="random">Random</button>
        <button type="button" id="live" aria-pressed="false">Live</button>
        <fieldset class="segmented">
          <legend>Roll direction</legend>
          <label><input type="radio" name="axis" value="y" checked> Up / down</label>
          <label><input type="radio" name="axis" value="x"> Left / right</label>
        </fieldset>
        <label class="xray-toggle"><input type="checkbox" name="xray"> X-ray (show the slots)</label>
      </form>
    
      <div class="stage" data-⚓️-root role="img" aria-label="1,234">
        <div class="lens" aria-hidden="true"
          data-⚓️-to="--digits" data-⚓️-fill data-⚓️-transition="glide"></div>
        <div class="cols" data-⚓️-name="--digits"></div>
      </div>
    </main>

    data-⚓️-filldata-⚓️-namedata-⚓️-rootdata-⚓️-todata-⚓️-transition

    Copied