Skip to content

176 web animation techniques, each a live demo with plain settings and a ready-made prompt for your AI assistant. No dependencies, no build step.

30.1 KB
Raw Blame
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Skeleton Loader — Animation Handbook</title>
  <meta name="description" content="Gray shapes hold the place of content while it loads. Best for feeds and cards.">
  <link rel="canonical" href="https://matinmonshizadeh.github.io/animation-handbook/animations/04-micro-interactions/skeleton-loader/">
  <link rel="icon" type="image/png" sizes="96x96" href="../../../favicon.png">
  <link rel="icon" type="image/svg+xml" href="../../../favicon.svg">
  <link rel="apple-touch-icon" href="../../../apple-touch-icon.png">
  <meta property="og:type" content="article">
  <meta property="og:site_name" content="Animation Handbook">
  <meta property="og:title" content="Skeleton Loader — Animation Handbook">
  <meta property="og:description" content="Gray shapes hold the place of content while it loads. Best for feeds and cards.">
  <meta property="og:url" content="https://matinmonshizadeh.github.io/animation-handbook/animations/04-micro-interactions/skeleton-loader/">
  <meta property="og:image" content="https://matinmonshizadeh.github.io/animation-handbook/og-image.png">
  <meta name="twitter:card" content="summary_large_image">
  <meta name="twitter:title" content="Skeleton Loader — Animation Handbook">
  <meta name="twitter:description" content="Gray shapes hold the place of content while it loads. Best for feeds and cards.">
  <meta name="twitter:image" content="https://matinmonshizadeh.github.io/animation-handbook/og-image.png">
  <script type="application/ld+json">{"@context": "https://schema.org", "@type": "TechArticle", "headline": "Skeleton Loader", "name": "Skeleton Loader", "description": "Gray shapes hold the place of content while it loads. Best for feeds and cards.", "url": "https://matinmonshizadeh.github.io/animation-handbook/animations/04-micro-interactions/skeleton-loader/", "inLanguage": "en", "articleSection": "Micro-Interactions", "isPartOf": {"@type": "WebSite", "name": "Animation Handbook", "url": "https://matinmonshizadeh.github.io/animation-handbook/"}, "author": {"@type": "Person", "name": "matinmonshizadeh"}, "keywords": "web animation, CSS animation, Micro-Interactions, Skeleton Loader"}</script>
  <style>
    :root{--ui-accent:#ff9d5c;--ui-bg:#111114;--ui-border:rgba(255,255,255,.09);--ui-muted:#8a8a92;--skel-bg:#1a1f28;--pulse-min:0.5;--pulse-spd:1.5s;--fade-dur:400ms}
    *,*::before,*::after{box-sizing:border-box;margin:0;padding:0}
    .stage{display:flex;align-items:center;justify-content:center;background:#0b0b0d;padding:16px}
    /* Card */
    .card-wrap{width:100%;max-width:340px;background:var(--ui-bg);border:1px solid var(--ui-border);border-radius:10px;padding:16px;position:relative;display:grid}
    #skel-content,.real{grid-area:1/1}
    /* Skeleton blocks */
    .skel{border-radius:4px;background:var(--skel-bg);animation:pulse var(--pulse-spd) ease-in-out infinite}
    @keyframes pulse{0%,100%{opacity:var(--pulse-min)}50%{opacity:1}}
    .sk-avatar{width:52px;height:52px;border-radius:50%}
    .sk-line{height:10px;margin-top:10px}
    .sk-line.w100{width:100%}
    .sk-line.w80{width:80%}
    .sk-line.w60{width:60%}
    .sk-line.w40{width:40%}
    .sk-img{width:100%;height:72px;border-radius:6px;margin-top:14px}
    .skel-header{display:flex;align-items:center;gap:14px}
    .skel-header-text{flex:1}
    /* Real content — hidden initially */
    .real{opacity:0;transition:opacity var(--fade-dur) ease;pointer-events:none}
    .real.visible{opacity:1;pointer-events:auto}
    .real-header{display:flex;align-items:center;gap:14px;margin-bottom:14px}
    .avatar{width:52px;height:52px;border-radius:50%;background:linear-gradient(135deg,#1a3060,#2a5090);display:flex;align-items:center;justify-content:center;font-size:20px;flex-shrink:0}
    .real-name{font-size:13px;font-weight:bold}
    .real-meta{font-size:11px;color:var(--ui-muted);margin-top:2px}
    .real-img{width:100%;height:72px;border-radius:6px;background:linear-gradient(135deg,#0d2b5e,#1a4a8c);margin-bottom:12px;display:flex;align-items:center;justify-content:center;font-size:11px;opacity:.6}
    .real-text{font-size:11px;color:var(--ui-muted);line-height:1.6}
    @media(prefers-reduced-motion:reduce){.skel{animation:none!important;opacity:.6}}
    /* See inside and Compare. Their words sit on dark pills, and the gray blocks are lighter there or they would not show on the dark box. */
    .joins,.cap,.nxt,.twin,.full,.jump{display:none}
    .cap{position:absolute;z-index:3;width:max-content;padding:3px 8px;border-radius:6px;background:rgba(11,11,13,.92);color:#f4f4f2;font:600 13px/1.25 var(--hb-font);text-align:center;text-wrap:balance}
    .joins rect,.joins line{fill:none;stroke:rgba(244,244,242,.5);stroke-width:1.25;stroke-dasharray:5 4;vector-effect:non-scaling-stroke}
    .joins .lift{stroke:rgba(244,244,242,.3)}
    .stage[data-hb-mode="inside"],.stage[data-hb-mode="compare"]{position:relative;--skel-bg:#465269}
    /* See inside: the content stays in the dashed frame and the gray blocks lift up and to the left, each joined to the piece it stands for.
       The script sets the size (--s), the place (--tx, --ty) and the lift (--lx, --ly). While loading the content shows faint under the
       pulsing blocks; once it has faded in, the blocks hold still and faint. */
    .stage[data-hb-mode="inside"] .cap-in{display:block}
    .stage[data-hb-mode="inside"] .card-wrap{translate:var(--tx) var(--ty);scale:var(--s);border-color:transparent}
    .stage[data-hb-mode="inside"] .joins{display:block;position:absolute;inset:0;z-index:-1;overflow:visible}
    .stage[data-hb-mode="inside"] #skel-content{translate:var(--lx) var(--ly);visibility:visible!important}
    .stage[data-hb-mode="inside"] .real:not(.visible){opacity:.25}
    .stage[data-hb-mode="inside"].shown #skel-content{opacity:.65;transition:opacity var(--fade-dur) ease}
    .stage[data-hb-mode="inside"].shown .skel{animation-play-state:paused}
    /* Compare: the card twice, pinned to the top of each half with the next item on the page (a faint bar) under it. On the left a copy that
       is an empty frame until the content arrives, then grows at once; on the right the card itself. Between plays the left shows the
       frame with where it will grow (--full) and the right holds half way through loading, the blocks still at their dimmest. */
    .stage[data-hb-mode="compare"]{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:8px clamp(8px,2vw,24px);align-items:start;
      align-content:start;justify-items:center;padding:10px clamp(8px,2vw,24px)}
    .stage[data-hb-mode="compare"] .name{display:block;position:relative;grid-row:1}
    .stage[data-hb-mode="compare"] .name.a,.stage[data-hb-mode="compare"] .twin{grid-column:1}
    .stage[data-hb-mode="compare"] .name.b,.stage[data-hb-mode="compare"] #card{grid-column:2}
    .stage[data-hb-mode="compare"] .twin,.stage[data-hb-mode="compare"] #card{grid-row:2}
    .stage[data-hb-mode="compare"] .twin{display:grid;min-height:48px}
    .stage[data-hb-mode="compare"] .twin .real{display:none;opacity:1;transition:none}
    .stage[data-hb-mode="compare"] .twin.on{min-height:var(--full)}
    .stage[data-hb-mode="compare"] .twin.on .real{display:block}
    .stage[data-hb-mode="compare"] .nxt{display:block;position:absolute;left:0;top:calc(100% + 10px);width:60%;height:12px;border-radius:6px;background:rgba(244,244,242,.18)}
    .stage[data-hb-mode="compare"] .card-wrap>.cap{display:block;left:0;right:0;top:calc(100% + 28px);width:auto}
    .stage[data-hb-mode="compare"] .card-wrap>.push{left:32px;top:calc(100% + 26px);text-align:left}
    .stage[data-hb-mode="compare"] .twin.on>.cap{display:none}
    .stage[data-hb-mode="compare"] .twin:not(.on) .full{display:block;position:absolute;left:-1px;right:-1px;top:calc(100% - 1px);height:calc(var(--full) - 47px);
      border:1.5px dashed rgba(244,244,242,.4);border-top:0;border-radius:0 0 10px 10px}
    .stage[data-hb-mode="compare"] .twin:not(.on) .jump{display:block;position:absolute;left:20px;top:calc(100% + 22px);width:2px;height:calc(var(--full) - 48px);background:rgba(244,244,242,.7)}
    .jump::after{content:'';position:absolute;left:-4px;bottom:-1px;border:5px solid transparent;border-top:8px solid rgba(244,244,242,.7);border-bottom:0}
    .stage[data-hb-mode="compare"].posed #skel-content{visibility:visible!important}
    .stage[data-hb-mode="compare"].posed .skel{animation:none!important;opacity:var(--pulse-min)}
    .stage[data-hb-mode="compare"].posed .real{opacity:0!important;transition:none!important}
    .stage[data-hb-mode="inside"].tight .sk-img,.stage[data-hb-mode="inside"].tight .real-img,
    .stage[data-hb-mode="compare"].tight .sk-img,.stage[data-hb-mode="compare"].tight .real-img{display:none}
    .stage[data-hb-mode="compare"].tight .card-wrap{padding:12px}
    .stage[data-hb-mode="compare"].tight .sk-avatar,.stage[data-hb-mode="compare"].tight .avatar{width:44px;height:44px}
    .stage[data-hb-mode="compare"].tight .real-header{margin-bottom:10px}
    @media(max-width:600px){
      .stage[data-hb-mode="compare"].tight .card-wrap{padding:8px}
      .stage[data-hb-mode="compare"].tight .sk-avatar,.stage[data-hb-mode="compare"].tight .avatar{width:36px;height:36px;font-size:16px}
      .stage[data-hb-mode="compare"].tight .skel-header,.stage[data-hb-mode="compare"].tight .real-header{gap:10px}
      .stage[data-hb-mode="compare"].tight .real-header{margin-bottom:8px}
      .stage[data-hb-mode="compare"].tight .real-text{line-height:1.4}
      .stage[data-hb-mode="compare"]{row-gap:6px;padding-top:8px}
      .cap{font-size:12px}
    }
    @media(prefers-reduced-motion:reduce){.stage[data-hb-mode="compare"].posed .skel{opacity:.6}}
  </style>
  <link rel="stylesheet" href="../../../assets/css/demo-page.css?v=11">
  <script src="../../../assets/js/demo-page.js?v=11" defer></script>
</head>
<body class="hb" data-hb-kind="once" data-hb-autoplay>
<nav class="hb-bar" aria-label="Animation Handbook">
  <a class="hb-home" href="../../../"><svg class="hb-mark" viewBox="0 0 32 32" aria-hidden="true"><g class="g"><circle cx="11.16" cy="20.84" r="6.1"/><circle cx="15.12" cy="16.88" r="6.1"/><circle cx="18.51" cy="13.49" r="6.1"/></g><circle class="b" cx="21.2" cy="10.8" r="6.6"/></svg><span>Animation Handbook</span></a>
  <span class="hb-pager"><a href="../success-confetti/" rel="prev" aria-label="Previous: Success Confetti"><svg class="hb-ic" viewBox="0 0 24 24" aria-hidden="true"><path d="m15 18-6-6 6-6"/></svg><span><span class="hb-dir">Previous: </span>Success Confetti</span></a><a href="../shimmer-effect/" rel="next" aria-label="Next: Shimmer Effect"><span><span class="hb-dir">Next: </span>Shimmer Effect</span><svg class="hb-ic" viewBox="0 0 24 24" aria-hidden="true"><path d="m9 18 6-6-6-6"/></svg></a></span>
  <a class="hb-star" href="https://github.com/matinmonshizadeh/animation-handbook" target="_blank" rel="noopener" aria-label="Star on GitHub"><svg class="hb-ic" viewBox="0 0 24 24" aria-hidden="true"><path d="M12 3l2.7 5.6 6.1.9-4.4 4.3 1 6.1L12 17l-5.4 2.9 1-6.1-4.4-4.3 6.1-.9z"/></svg><span>Star on GitHub</span></a>
</nav>
<main class="hb-page">
  <header class="hb-head">
    <p class="hb-cat">04.09 · Micro-Interactions</p>
    <h1>Skeleton Loader</h1>
    <p class="hb-lede">Gray shapes hold the place of content while it loads. Best for feeds and cards.</p>
  </header>

  <section class="hb-step hb-watch" aria-labelledby="hb-watch-title">
    <div class="hb-step-head">
      <span class="hb-num" aria-hidden="true">1</span>
      <div><h2 id="hb-watch-title">Watch it</h2><p>It plays by itself. Turn on slow motion to see each part of the movement.</p></div>
    </div>
    <div class="seg hb-modes" role="group" aria-label="What the box shows" data-hb-modes>
      <button type="button" data-hb-mode="normal" class="on" aria-pressed="true">Normal</button>
      <button type="button" data-hb-mode="inside" aria-pressed="false">See inside</button>
      <button type="button" data-hb-mode="compare" aria-pressed="false">Compare</button>
    </div>
    <div class="stage hb-dots">
      <div class="card-wrap" id="card">
        <svg class="joins" aria-hidden="true"><rect class="lift" rx="10"/><rect rx="10"/><line/><line/><line/><line/><line/></svg>
        <!-- Skeleton -->
        <div id="skel-content">
          <div class="skel-header">
            <div class="skel sk-avatar"></div>
            <div class="skel-header-text"><div class="skel sk-line w80"></div><div class="skel sk-line w40" style="margin-top:6px"></div></div>
          </div>
          <div class="skel sk-img"></div>
          <div class="skel sk-line w100"></div>
          <div class="skel sk-line w80"></div>
          <div class="skel sk-line w60"></div>
        </div>
        <!-- Real content -->
        <div class="real" id="real-content" aria-hidden="true">
          <div class="real-header">
            <div class="avatar">🌊</div>
            <div><div class="real-name">Atlas Studio</div><div class="real-meta">2 hours ago · Design</div></div>
          </div>
          <div class="real-img">[ Landscape Photography ]</div>
          <div class="real-text">New coastal landscapes, shot where the light meets the water.</div>
        </div>
        <span class="nxt" aria-hidden="true"></span>
        <p class="cap hold" aria-hidden="true" data-hb-caption></p>
      </div>
      <p class="cap cap-in" aria-hidden="true" data-hb-caption>Gray blocks shaped like the content</p>
      <p class="cap cap-in" aria-hidden="true" data-hb-caption>The content arrives in the same place</p>
      <p class="cap cap-in" aria-hidden="true" data-hb-caption></p>
      <p class="cap cap-in" aria-hidden="true" data-hb-caption></p>
      <p class="cap name a" aria-hidden="true" data-hb-caption>Blank, then jumps</p>
      <p class="cap name b" aria-hidden="true" data-hb-caption>Holds the space</p>
    </div>
    <div class="hb-player">
      <button class="hb-play" type="button" id="btn-play" data-hb-replay><svg class="hb-ic" viewBox="0 0 24 24" aria-hidden="true"><path d="M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"/><path d="M3 3v5h5"/></svg>Replay</button>
      <label class="hb-toggle"><input class="hb-switch" type="checkbox" role="switch" id="loop-tog" data-hb-loop autocomplete="off"><span>Loop</span></label>
      <label class="hb-toggle"><input class="hb-switch" type="checkbox" role="switch" id="slow-tog" data-hb-slowmo autocomplete="off"><span>Slow motion</span></label>
    </div>
    <div class="hb-mode-notes" aria-live="polite">
      <p data-hb-for="inside" hidden>Inside, the gray blocks are lifted off the card: each is shaped like a piece of the content, which fades in underneath, in the same place.</p>
      <p data-hb-for="compare" hidden>Blank, then jumps: the empty card grows when the content arrives and pushes the next item down; Holds the space: gray blocks keep its size, so nothing moves.</p>
    </div>
  </section>

  <section class="hb-step hb-try" aria-labelledby="hb-try-title">
    <div class="hb-step-head">
      <span class="hb-num" aria-hidden="true">2</span>
      <div><h2 id="hb-try-title">Try it</h2><p>Change a setting and the animation plays again.</p></div>
    </div>
    <div class="hb-settings">
      <div class="hb-setting">
        <p class="hb-setting-name" id="pulse-lbl">Pulse speed</p>
        <div class="seg" id="pulse-seg" role="group" aria-labelledby="pulse-lbl">
          <button type="button" data-ms="2400" aria-pressed="false">Slow</button>
          <button type="button" data-ms="1500" class="on" aria-pressed="true">Normal</button>
          <button type="button" data-ms="900" aria-pressed="false">Fast</button>
        </div>
        <p class="hb-hint">One to two seconds a pulse feels calm.</p>
      </div>
      <div class="hb-setting">
        <p class="hb-setting-name" id="strength-lbl">Pulse strength</p>
        <div class="seg" id="strength-seg" role="group" aria-labelledby="strength-lbl">
          <button type="button" data-min="0.7" aria-pressed="false">Soft</button>
          <button type="button" data-min="0.5" class="on" aria-pressed="true">Medium</button>
          <button type="button" data-min="0.3" aria-pressed="false">Strong</button>
        </div>
        <p class="hb-hint">How far the blocks fade between pulses.</p>
      </div>
    </div>
    <details class="hb-options">
      <summary><span class="hb-more-label">More options</span><span class="hb-less">Fewer options</span><svg class="hb-ic" viewBox="0 0 24 24" aria-hidden="true"><path d="m6 9 6 6 6-6"/></svg></summary>
      <div class="hb-settings">
        <div class="hb-setting">
          <p class="hb-setting-name" id="load-lbl">Loading time</p>
          <div class="seg" id="load-seg" role="group" aria-labelledby="load-lbl">
            <button type="button" data-ms="1000" aria-pressed="false">Short</button>
            <button type="button" data-ms="2000" class="on" aria-pressed="true">Medium</button>
            <button type="button" data-ms="3500" aria-pressed="false">Long</button>
          </div>
          <p class="hb-hint">How long the placeholders show before the content.</p>
        </div>
      </div>
    </details>
  </section>

  <section class="hb-step hb-prompt-step" aria-labelledby="hb-prompt-title">
    <div class="hb-step-head">
      <span class="hb-num" aria-hidden="true">3</span>
      <div><h2 id="hb-prompt-title">Copy the prompt</h2><p>Paste it into an AI assistant such as ChatGPT, Claude or Cursor to build this in your own project.</p></div>
    </div>
    <div class="hb-card">
      <p class="hb-prompt">Add a skeleton loading state to [the card, list or panel whose content loads]. While it loads, show gray blocks in the shapes and sizes of the content that is coming, such as a round avatar, lines of text and an image, and let them pulse between dimmer and brighter. When the content is ready, swap the blocks for it and fade it in. Match the shapes closely, because a skeleton that does not fit the content makes the page jump when it arrives. If the visitor has reduced motion turned on, keep the blocks still. Match the settings listed below.</p>
      <div class="hb-chips-box" hidden>
        <p class="hb-chips-title">Your settings</p>
        <ul class="hb-chips"></ul>
      </div>
      <div class="hb-copy-row">
        <button class="hb-copy" type="button"><svg class="hb-ic hb-i-copy" viewBox="0 0 24 24" aria-hidden="true"><rect x="9" y="9" width="13" height="13" rx="2"/><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/></svg><svg class="hb-ic hb-i-done" viewBox="0 0 24 24" aria-hidden="true"><path d="M20 6 9 17l-5-5"/></svg><span class="hb-copy-label" aria-live="polite">Copy prompt</span></button>
        <p class="hb-hint">Replace the words in brackets with your own element. Your settings are added at the end.</p>
      </div>
    </div>
    <div class="hb-star-row"><p>Free and open source. If this helped, a star on GitHub helps other people find it.</p><a class="hb-star-btn" href="https://github.com/matinmonshizadeh/animation-handbook" target="_blank" rel="noopener"><svg class="hb-ic" viewBox="0 0 24 24" aria-hidden="true"><path d="M12 3l2.7 5.6 6.1.9-4.4 4.3 1 6.1L12 17l-5.4 2.9 1-6.1-4.4-4.3 6.1-.9z"/></svg>Star on GitHub</a></div>
  </section>

  <section class="hb-about" aria-labelledby="hb-what-title">
    <div class="hb-what">
      <h2 id="hb-what-title">What it is</h2>
      <div class="hb-what-text"><p>The full explanation is in <a href="README.md">README.md</a>.</p></div>
    </div>
    <div class="hb-fit">
      <h2>Good for</h2>
      <ul class="hb-tags hb-good"><li>Feeds</li><li>Cards</li><li>Lists</li><li>Dashboards</li></ul>
      <h3>Avoid on</h3>
      <ul class="hb-tags hb-avoid"><li>Very short waits</li><li>Unknown layouts</li></ul>
    </div>
  </section>

  <section class="hb-related" aria-labelledby="hb-related-title" hidden>
    <h2 id="hb-related-title">Similar animations</h2>
    <div class="hb-rel-list"></div>
  </section>
</main>
<footer class="hb-foot"><span>Animation Handbook</span><a href="https://github.com/matinmonshizadeh/animation-handbook" target="_blank" rel="noopener">Source on GitHub</a><a href="#top">Back to top ↑</a></footer>
<script>
  const card=document.getElementById('card'),stage=card.parentElement;
  const skelEl=document.getElementById('skel-content'),realEl=document.getElementById('real-content');
  const vars=document.documentElement.style;
  const loopTog=document.getElementById('loop-tog'),slowTog=document.getElementById('slow-tog');
  const motionOk=!window.matchMedia('(prefers-reduced-motion:reduce)').matches;
  let pulseMs=1500,pulseMin='0.5',loadDur=2000,timers=[];
  // See inside and Compare: which one shows, whether the content is shown now, and whether a play is under way
  let mode='normal',revealed=false,running=false;

  // Slow motion triples the movements (the pulse and the fade), never Loading time or the hold.
  function mult(){return slowTog.checked?3:1}
  function apply(){
    vars.setProperty('--pulse-spd',pulseMs*mult()/1000+'s');
    vars.setProperty('--pulse-min',pulseMin);
    vars.setProperty('--fade-dur',400*mult()+'ms');
  }
  // Drops a timer's id once it fires, so `timers` only ever holds ones still pending.
  function later(fn,wait){
    const id=setTimeout(()=>{
      const i=timers.indexOf(id);
      if(i>-1)timers.splice(i,1);
      fn();
    },wait);
    timers.push(id);
  }
  // Brings the placeholders back and hides the content at once, from screen readers too (aria-hidden): the content's
  // fade is switched off for the change, a reflow makes it stick, then the fade is switched back on for the reveal.
  function showPlaceholders(){
    skelEl.style.visibility='';
    shown(false);
    realEl.style.transition='none';
    realEl.classList.remove('visible');
    realEl.setAttribute('aria-hidden','true');
    void realEl.offsetWidth;
    realEl.style.transition='';
  }
  function reveal(){
    skelEl.style.visibility='hidden';
    shown(true);
    realEl.classList.add('visible');
    realEl.removeAttribute('aria-hidden');
  }
  // One play shows the placeholders for Loading time, then fades the content in. While Loop is on, the content
  // holds 1600ms after its fade ends; Loop is checked then, so switching it off leaves the content shown.
  // Slow motion stretches the pulse and the fade, not Loading time or the hold.
  function cycle(){
    running=true;
    apply();
    setPose(false);
    showPlaceholders();
    const fade=400*mult();
    later(()=>{
      reveal();
      later(()=>{
        if(!loopTog.checked||!motionOk){running=false;if(mode==='compare')setPose(true);return}
        cycle();
      },fade+1600);
    },loadDur);
  }
  function play(){timers.forEach(clearTimeout);timers=[];cycle()}

  // ── See inside and Compare ──
  const $$=q=>[...stage.querySelectorAll(q)];
  const [cBlocks,cContent,cPulse,cLoad]=$$('.cap-in'),cHold=card.querySelector('.hold');
  const P=10,G=8; // how far captions keep from the box's edge and from each other
  // Compare's left card: a copy that stays an empty frame until the content arrives, then shows it at once, so the card grows
  // and pushes the next item down. It has no ids and is out of reach of the keyboard and screen readers.
  const twin=card.cloneNode(true);
  twin.querySelector('#skel-content').remove();twin.querySelector('.joins').remove();
  twin.querySelectorAll('[id]').forEach(e=>e.removeAttribute('id'));
  twin.removeAttribute('id');twin.classList.add('twin');twin.inert=true;twin.setAttribute('aria-hidden','true');
  const push=twin.querySelector('.hold');push.className='cap push';push.textContent='Will be pushed down';
  twin.insertAdjacentHTML('beforeend','<i class="full"></i><i class="jump"></i>');
  card.before(twin);
  if(!motionOk)document.querySelector('[data-hb-for="inside"]').textContent=
    'Inside, the gray blocks are lifted off the card, shown still: each is shaped like a piece of the content, which appears underneath, in the same place.';

  function shown(on){revealed=on;stage.classList.toggle('shown',on);syncTwin()}
  function syncTwin(){twin.classList.toggle('on',revealed&&!stage.classList.contains('posed'))}
  // Compare's rest pose: half way through loading. Leaving it shows the card as it now is, at once.
  function setPose(on){
    if(stage.classList.contains('posed')!==on){
      realEl.style.transition='none';
      stage.classList.toggle('posed',on);
      void realEl.offsetWidth;realEl.style.transition='';
    }
    syncTwin();
  }

  const NUM=['','a','two','three','four','five','six','seven','eight','nine'];
  // Seconds as a beginner says them, to the nearest half ("every" drops the "a")
  function secs(ms,every){
    const n=Math.max(1,Math.round(ms/500)),w=n>>1,t=!w?'half a second':n&1?(w>1?NUM[w]+' and a half seconds':'a second and a half'):w>1?NUM[w]+' seconds':'a second';
    return (Math.abs(ms-n*500)>60?'about ':'')+(every?'every '+t.replace(/^a /,''):t);
  }
  // The captions that depend on the settings, in the page's own numbers (Slow motion triples the pulse)
  function words(){
    const dim=+pulseMin>.6?'a little':+pulseMin>.4?'to half':'a lot',wait=secs(loadDur),beat=secs(pulseMs*mult(),1);
    cPulse.textContent=motionOk?'Pulses '+beat+', dimming '+dim:'With reduced motion on, the blocks hold still';
    cLoad.textContent='After '+wait+' the content fades in';
    cHold.textContent=(motionOk?'Pulses '+beat:'The blocks hold still')+'; '+(stage.clientWidth<560?'content':'the content comes')+' after '+wait;
  }
  // Puts a band of captions at an edge: side by side when the box is wide, else one above the other. Returns its height.
  function band(list,edge,up){
    const W=stage.clientWidth,two=W>=560,each=two?(W-2*P-G)/2:W-2*P;
    list.forEach(c=>{c.style.left=c.style.top='0px';c.style.maxWidth=each+'px';c.style.textAlign='center'});
    const h=two?Math.max(...list.map(c=>c.offsetHeight)):list.reduce((t,c)=>t+c.offsetHeight+G,-G);
    let y=up?edge:edge-h;
    list.forEach((c,i)=>{
      c.style.left=(two?P+i*(each+G)+(each-c.offsetWidth)/2:(W-c.offsetWidth)/2)+'px';c.style.top=y+'px';
      if(!two)y+=c.offsetHeight+G;
    });
    return h;
  }
  // A column of captions from y down, their left edges at x or their right edges at x
  function stack(list,x,y,w,align){
    list.forEach(c=>{c.style.left=c.style.top='0px';c.style.maxWidth=w+'px';c.style.textAlign=align});
    list.forEach(c=>{c.style.left=(align==='left'?x:x-c.offsetWidth)+'px';c.style.top=y+'px';y+=c.offsetHeight+G});
  }
  // See inside: the card at the size that fits, its blocks lifted up and to the left. A wide box puts the blocks' two captions to the
  // left of them and the content's two to the right of the card; a narrower one puts them in bands above and below.
  function placeInside(){
    stage.classList.toggle('tight',stage.clientWidth<560); // a narrow box leaves out the picture, to give the rest more room
    const W=stage.clientWidth,H=stage.clientHeight,cw=card.offsetWidth,ch=card.offsetHeight,lx=Math.round(cw*.24),ly=Math.round(ch*.28);
    const sH=Math.min(1,(H-2*P)/(ch+ly)),col=(W-sH*(cw+lx))/2-P-G;
    let s=sH,gx=(W-s*(cw+lx))/2,gy=(H-s*(ch+ly))/2;
    if(col>=170){
      stack([cBlocks,cPulse],gx-G,gy,col,'right');stack([cContent,cLoad],gx+s*(lx+cw)+G,gy+s*ly,col,'left');
    }else{
      const top=band([cBlocks,cPulse],P,true),bot=band([cContent,cLoad],H-P,false),y0=P+top+G,room=H-P-bot-G-y0;
      s=Math.max(.25,Math.min(1,room/(ch+ly),(W-2*P)/(cw+lx)));gx=(W-s*(cw+lx))/2;gy=y0+(room-s*(ch+ly))/2;
    }
    const v=(k,x)=>stage.style.setProperty(k,x);
    v('--s',s);v('--tx',gx+s*(lx+cw/2)-W/2+'px');v('--ty',gy+s*(ly+ch/2)-H/2+'px');v('--lx',-lx+'px');v('--ly',-ly+'px');
    // The dashed frames and the joins, in the card's own pixels: block to piece, left edge to left edge
    const cr=card.getBoundingClientRect(),at=e=>{const r=e.getBoundingClientRect();return{x:(r.left-cr.left)/s,y:(r.top-cr.top)/s,w:r.width/s,h:r.height/s}};
    const [f1,f2]=$$('.joins rect'),blocks=[...skelEl.querySelectorAll('.sk-avatar,.sk-line,.sk-img')].map(at);
    const rows=blocks.splice(4),text={x:rows[0].x,y:rows[0].y,h:rows[2].y+rows[2].h-rows[0].y};
    f1.setAttribute('x',-1-lx);f1.setAttribute('y',-1-ly);f2.setAttribute('x',-1);f2.setAttribute('y',-1);
    [f1,f2].forEach(f=>{f.setAttribute('width',cw);f.setAttribute('height',ch)});
    blocks.push(text);
    $$('.joins line').forEach((l,i)=>{
      const b=blocks[i],p=at(realEl.querySelector(['.avatar','.real-name','.real-meta','.real-img','.real-text'][i]));
      l.style.display=b.w?'':'none'; // the picture's join goes with the picture
      l.setAttribute('x1',b.x);l.setAttribute('y1',b.y+b.h/2);l.setAttribute('x2',p.x);l.setAttribute('y2',p.y+p.h/2);
    });
  }
  // Compare: a short box or a phone leaves out the picture (and its gray block) in both cards; --full is the card's height
  function placeCompare(){
    stage.classList.toggle('tight',matchMedia('(max-width:600px),(max-height:500px)').matches||stage.clientHeight<360);
    stage.style.setProperty('--full',card.offsetHeight+'px');
  }
  function drawMode(){
    if(mode==='normal')return setPose(false);
    apply();words();
    setPose(mode==='compare'&&!running);
    if(mode==='inside')placeInside();else placeCompare();
  }
  document.addEventListener('hb:mode',e=>{
    const was=mode;mode=e.detail.mode;
    // Entering or leaving See inside shows its picture at once: the content see-through (or hidden) while it is still to come,
    // and the blocks faint once it has arrived; the page's own fades run only in a play
    const snap=el=>{el.style.transition='none';void el.offsetWidth;el.style.transition=''};
    if((was==='inside'||mode==='inside')&&!realEl.classList.contains('visible'))snap(realEl);
    if(was!=='inside'&&mode==='inside'&&revealed)snap(skelEl);
    drawMode();
  });
  new ResizeObserver(()=>{if(mode!=='normal')drawMode()}).observe(stage);
  document.fonts.ready.then(drawMode);

  document.getElementById('btn-play').addEventListener('click',play);
  loopTog.addEventListener('change',()=>{if(loopTog.checked)play()});
  slowTog.addEventListener('change',drawMode);
  function choices(id,pick){
    const buttons=document.querySelectorAll('#'+id+' button');
    buttons.forEach(b=>b.addEventListener('click',()=>{
      buttons.forEach(x=>{x.classList.toggle('on',x===b);x.setAttribute('aria-pressed',String(x===b))});
      pick(b.dataset);
      drawMode();
    }));
  }
  choices('pulse-seg',d=>{pulseMs=+d.ms});
  choices('strength-seg',d=>{pulseMin=d.min});
  choices('load-seg',d=>{loadDur=+d.ms});
  apply();
</script>
</body>
</html>