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.

24.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>Shimmer Effect — Animation Handbook</title>
  <meta name="description" content="A band of light sweeps over gray placeholders. Best for loading screens.">
  <link rel="canonical" href="https://matinmonshizadeh.github.io/animation-handbook/animations/04-micro-interactions/shimmer-effect/">
  <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="Shimmer Effect — Animation Handbook">
  <meta property="og:description" content="A band of light sweeps over gray placeholders. Best for loading screens.">
  <meta property="og:url" content="https://matinmonshizadeh.github.io/animation-handbook/animations/04-micro-interactions/shimmer-effect/">
  <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="Shimmer Effect — Animation Handbook">
  <meta name="twitter:description" content="A band of light sweeps over gray placeholders. Best for loading screens.">
  <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": "Shimmer Effect", "name": "Shimmer Effect", "description": "A band of light sweeps over gray placeholders. Best for loading screens.", "url": "https://matinmonshizadeh.github.io/animation-handbook/animations/04-micro-interactions/shimmer-effect/", "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, Shimmer Effect"}</script>
  <style>
    :root{--ui-accent:#ff9d5c;--ui-bg:#111114;--ui-border:rgba(255,255,255,.09);--shim-dur:1500ms;--shim-bright:0.25;--shim-angle:90deg;--shim-color:255,255,255}
    *,*::before,*::after{box-sizing:border-box;margin:0;padding:0}
    .stage{position:relative;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:12px;padding:16px;background:#0b0b0d}
    /* On a short stage (a phone held sideways) the card and row keep their full height and use the padding instead of shrinking */
    .stage>*{flex-shrink:0}
    /* Skeleton card */
    .skel-card{width:100%;max-width:320px;background:var(--ui-bg);border:1px solid var(--ui-border);border-radius:10px;padding:14px;position:relative;overflow:hidden}
    /* The band: a translucent gradient over each placeholder, slid across by animating its background position */
    .skel-card::after,.skel-row::after{content:'';position:absolute;inset:0;background:linear-gradient(var(--shim-angle),transparent 25%,rgba(var(--shim-color),var(--shim-bright)) 50%,transparent 75%);animation:shimmer var(--shim-dur) linear infinite;background-size:200% 100%}
    @keyframes shimmer{from{background-position:200% 0}to{background-position:-200% 0}}
    .sk{border-radius:4px;background:#1a1f28}
    .sk-avatar{width:44px;height:44px;border-radius:50%}
    .sk-line{height:9px;margin-top:9px}
    .sk-line.w100{width:100%}
    .sk-line.w75{width:75%}
    .sk-line.w50{width:50%}
    .sk-img{width:100%;height:56px;border-radius:6px;margin:10px 0 2px}
    .sk-header{display:flex;align-items:center;gap:12px}
    .sk-header-text{flex:1}
    /* List row variant */
    .skel-row{width:100%;max-width:320px;background:var(--ui-bg);border:1px solid var(--ui-border);border-radius:8px;padding:14px 16px;display:flex;align-items:center;gap:12px;position:relative;overflow:hidden}
    .sk-circle{width:36px;height:36px;border-radius:50%;background:#1a1f28;flex-shrink:0}
    .sk-row-lines{flex:1;display:flex;flex-direction:column;gap:6px}
    /* See inside and Compare. What they add sits unseen in Normal, out of the flow and never display:none, so every band keeps the page's time */
    .sstrip,.shim-copy{position:absolute;visibility:hidden;pointer-events:none}
    .shim-copy::after{content:none}
    .sstrip{left:0;right:0;top:var(--cy);height:var(--ch);overflow:hidden;background:rgba(255,255,255,.04)}
    /* A band that slides by transform, with the card's own gradient: a tile twice the card's width, one band in it, one tile per half cycle */
    .sband,.bandl{position:absolute;top:0;height:100%;animation:bandslide calc(var(--shim-dur) / 2) linear infinite;background:linear-gradient(var(--shim-angle),transparent 25%,rgba(var(--shim-color),var(--shim-bright)) 50%,transparent 75%)}
    .sband{left:calc(var(--cx) - 4 * var(--cw));width:calc(8 * var(--cw));background-size:25% 100%;--slide:25%;opacity:.6}
    .bandl{left:-200%;width:400%;background-size:50% 100%}
    .bandl.rev{animation-direction:reverse}
    @keyframes bandslide{to{transform:translateX(var(--slide,50%))}}
    .dash,.cbox,.half{display:none}
    .dash{position:absolute;top:calc(var(--cy) - 7px);height:calc(var(--ch) + 14px);border-left:2px dashed #f4f4f2;pointer-events:none}
    .dl{left:calc(var(--cx) - 2px)}
    .dr{left:calc(var(--cx) + var(--cw))}
    /* an arrow beside each edge shows the way the band slides: in on one side, out on the other */
    .dash::before{content:'';position:absolute;top:calc(50% - 6px)}
    .dl::before{right:6px}
    .dr::before{left:6px}
    .lbl{padding:3px 7px;border-radius:5px;background:rgba(8,8,10,.92);color:#f4f4f2;font:600 12px/1.2 var(--hb-font);white-space:nowrap}
    .cbox{position:absolute;left:6px;right:6px;flex-wrap:wrap;justify-content:center;gap:3px 6px}
    .ctop{top:5px}
    .cbot{bottom:5px}
    /* See inside: the band's whole track behind the card, the row steps aside to make room for the captions */
    .stage[data-hb-mode="inside"] .sstrip{visibility:visible}
    .stage[data-hb-mode="inside"] .dash{display:block}
    .stage[data-hb-mode="inside"] .cbox{display:flex}
    .stage[data-hb-mode="inside"] .skel-row{position:absolute;left:0;top:0;visibility:hidden}
    @media(max-width:600px){.stage[data-hb-mode="inside"] .skel-card{width:60%}}
    /* Compare: the same card and row twice, the mistake (the row's light goes the other way) and the page's own */
    .stage[data-hb-mode="compare"]{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));align-content:center;justify-items:center;gap:8px;padding:10px}
    .stage[data-hb-mode="compare"] .half{display:block;grid-row:1}
    .stage[data-hb-mode="compare"] .h1{grid-column:1}
    .stage[data-hb-mode="compare"] .h2{grid-column:2}
    .stage[data-hb-mode="compare"] .skel-card{grid-area:2/2}
    .stage[data-hb-mode="compare"] .skel-row{grid-area:3/2}
    .stage[data-hb-mode="compare"] .shim-copy{position:relative;visibility:visible}
    .stage[data-hb-mode="compare"] .skel-card.shim-copy{grid-area:2/1}
    .stage[data-hb-mode="compare"] .skel-row.shim-copy{grid-area:3/1}
    .stage[data-hb-mode="compare"] .sk-img{height:40px}
    @media(min-width:601px) and (max-height:620px){.stage[data-hb-mode="compare"] .sk-img{display:none}}
    /* an arrow at the top edge of every placeholder shows the way its band sweeps */
    .dash::before,.stage[data-hb-mode="compare"] .skel-card::before,.stage[data-hb-mode="compare"] .skel-row::before{width:24px;height:12px;background:var(--ui-accent);clip-path:polygon(0 36%,58% 36%,58% 0,100% 50%,58% 100%,58% 64%,0 64%)}
    .stage[data-hb-mode="compare"] .skel-card::before,.stage[data-hb-mode="compare"] .skel-row::before{content:'';position:absolute;top:4px;right:6px}
    .stage[data-hb-mode="compare"] .skel-row.shim-copy::before{transform:scaleX(-1)}
    /* Reduced motion starts paused at time zero, with each band's middle on an edge: these start the bands part way in, in the modes only */
    @media(prefers-reduced-motion:reduce){
      .stage[data-hb-mode="inside"] .skel-card::after,.stage[data-hb-mode="inside"] .sband{animation-delay:calc(var(--shim-dur) * -.41)}
      .stage[data-hb-mode="compare"] .skel-card::after,.stage[data-hb-mode="compare"] .skel-row::after,.stage[data-hb-mode="compare"] .bandl{animation-delay:calc(var(--shim-dur) * -.375)}
      .stage[data-hb-mode="compare"] .bandl.rev{animation-delay:calc(var(--shim-dur) * -.125)}
    }
  </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="loop">
<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="../skeleton-loader/" rel="prev" aria-label="Previous: Skeleton Loader"><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>Skeleton Loader</span></a><a href="../loading-spinner/" rel="next" aria-label="Next: Loading Spinner"><span><span class="hb-dir">Next: </span>Loading Spinner</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.10 · Micro-Interactions</p>
    <h1>Shimmer Effect</h1>
    <p class="hb-lede">A band of light sweeps over gray placeholders. Best for loading screens.</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 moves by itself. Pause it to look closely, or 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="sstrip" aria-hidden="true" inert><div class="sband"></div></div>
      <div class="skel-card">
        <div class="sk-header">
          <div class="sk sk-avatar"></div>
          <div class="sk-header-text">
            <div class="sk sk-line w75"></div>
            <div class="sk sk-line w50" style="margin-top:6px"></div>
          </div>
        </div>
        <div class="sk sk-img"></div>
        <div class="sk sk-line w100"></div>
        <div class="sk sk-line w75"></div>
      </div>
      <div class="skel-row">
        <div class="sk sk-circle"></div>
        <div class="sk-row-lines">
          <div class="sk sk-line w100" style="margin:0"></div>
          <div class="sk sk-line w50" style="margin:0"></div>
        </div>
      </div>
      <span class="dash dl" aria-hidden="true"></span><span class="dash dr" aria-hidden="true"></span>
      <div class="cbox ctop" aria-hidden="true"><p class="lbl cap" data-hb-caption>Light slides across, again and again</p><p class="lbl cap" data-hb-caption data-cap="bright">A soft band: brightest in the middle</p></div>
      <div class="cbox cbot" aria-hidden="true"><p class="lbl cap" data-hb-caption>Cut off at the dashed edges (faint here)</p><p class="lbl cap" data-hb-caption data-cap="speed">A sweep every three quarters of a second</p></div>
      <p class="lbl cap half h1" aria-hidden="true" data-hb-caption>Mixed directions</p>
      <p class="lbl cap half h2" aria-hidden="true" data-hb-caption>One direction</p>
    </div>
    <div class="hb-player">
      <button class="hb-play" type="button" id="btn-pause" data-hb-pause="css" data-state="playing"><svg class="hb-ic hb-i-pause" viewBox="0 0 24 24" aria-hidden="true"><rect x="6" y="4" width="4" height="16" rx="1"/><rect x="14" y="4" width="4" height="16" rx="1"/></svg><svg class="hb-ic hb-i-play" viewBox="0 0 24 24" aria-hidden="true"><path d="M6 3l14 9-14 9z"/></svg><span class="hb-pause-label">Pause</span></button>
      <label class="hb-toggle"><input class="hb-switch" type="checkbox" role="switch" id="slow-tog" data-hb-slowmo="css" autocomplete="off"><span>Slow motion</span></label>
    </div>
    <div class="hb-mode-notes" aria-live="polite">
      <p data-hb-for="inside" hidden>Inside, the band of light is shown past the card too, faint: it slides across again and again, and the card's edges cut it off.</p>
      <p data-hb-for="compare" hidden>Mixed directions: the card's light and the row's cross each other, which looks restless; One direction: every placeholder sweeps the same way, like content streaming in.</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 see the difference as it moves.</p></div>
    </div>
    <div class="hb-settings">
      <div class="hb-setting">
        <p class="hb-setting-name" id="speed-lbl">Speed</p>
        <div class="seg" id="speed-seg" role="group" aria-labelledby="speed-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 sweep every half second to a second feels calm.</p>
      </div>
      <div class="hb-setting">
        <p class="hb-setting-name" id="bright-lbl">Brightness</p>
        <div class="seg" id="bright-seg" role="group" aria-labelledby="bright-lbl">
          <button type="button" data-bright="0.12" aria-pressed="false">Soft</button>
          <button type="button" data-bright="0.25" class="on" aria-pressed="true">Medium</button>
          <button type="button" data-bright="0.45" aria-pressed="false">Bright</button>
        </div>
        <p class="hb-hint">How strong the band of light is.</p>
      </div>
      <div class="hb-setting">
        <p class="hb-setting-name" id="angle-lbl">Highlight angle</p>
        <div class="seg" id="angle-seg" role="group" aria-labelledby="angle-lbl">
          <button type="button" data-angle="90" class="on" aria-pressed="true">Upright</button>
          <button type="button" data-angle="115" aria-pressed="false">Slanted</button>
          <button type="button" data-angle="135" aria-pressed="false">Diagonal</button>
        </div>
        <p class="hb-hint">The slant of the band as it sweeps across.</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="color-lbl">Highlight color</p>
          <div class="swatches" id="color-sw" role="group" aria-labelledby="color-lbl">
            <button type="button" class="on" aria-pressed="true" aria-label="White" data-c="255,255,255" style="background:#ffffff"></button>
            <button type="button" aria-pressed="false" aria-label="Blue" data-c="88,166,255" style="background:#58a6ff"></button>
            <button type="button" aria-pressed="false" aria-label="Gold" data-c="255,215,0" style="background:#ffd700"></button>
          </div>
          <p class="hb-hint">Tinted light suits a branded loading screen.</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 shimmer to [the skeleton placeholders on your loading screen]. Lay a band of light over each placeholder and sweep it across in one direction, again and again, so the gray shapes look like content streaming in. Every placeholder on the page should shimmer in the same direction, and each one must clip the band to its own edges so it never spills out. Keep the band see-through so it works on any placeholder color. If the visitor has reduced motion turned on, keep the placeholders 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>Image galleries</li></ul>
      <h3>Avoid on</h3>
      <ul class="hb-tags hb-avoid"><li>Very short waits</li><li>Busy pages</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 stage=document.querySelector('.stage');
  const vars=document.documentElement.style;
  let shimMs=1500;
  const card=stage.querySelector('.skel-card'),slow=document.getElementById('slow-tog');
  const reduceMQ=matchMedia('(prefers-reduced-motion: reduce)');
  // The notes say the markup's words while the band moves; under reduced motion the loop starts paused, and while it is paused
  // they describe the still. A note is rewritten only when its words change, as its box is read out loud.
  const notes=[...document.querySelectorAll('[data-hb-for]')],moving=notes.map(n=>n.textContent),still=[
    "Inside, shown still: the band of light is caught where it stopped, and the faint strip shows its track past the card's edges, which cut it off.",
    "Shown still: the arrows show where each band would sweep; in Mixed directions the card's and the row's go opposite ways, in One direction the same way."];
  let paused=reduceMQ.matches,held=null;
  function describe(){
    notes.forEach((n,i)=>{const words=reduceMQ.matches&&paused?still[i]:moving[i];if(n.textContent!==words)n.textContent=words});
  }
  describe();
  document.addEventListener('hb:pause',e=>{paused=e.detail.paused;if(!paused)held=null;describe()});
  reduceMQ.addEventListener('change',describe);
  // Two captions follow the settings: how often the band crosses (Speed, Slow motion) and how strong it is (Brightness)
  const sweeps={2400:['every second or so','every three and a half seconds'],1500:['every three quarters of a second','every two and a quarter seconds'],900:['about twice a second','every second and a third']};
  const strengths={'0.12':'faint','0.25':'soft','0.45':'bright'};
  let bright='0.25';
  function captions(){
    stage.querySelector('[data-cap="speed"]').textContent='A sweep '+sweeps[shimMs][+slow.checked];
    stage.querySelector('[data-cap="bright"]').textContent='A '+strengths[bright]+' band: brightest in the middle';
  }
  slow.addEventListener('change',captions);
  // Copies for Compare, made once with the page so their bands start with the page's own: no band of their own, a layer that slides by transform
  [[card,''],[stage.querySelector('.skel-row'),' rev']].forEach(([el,rev])=>{
    const copy=el.cloneNode(true),band=document.createElement('div');
    copy.classList.add('shim-copy');copy.inert=true;copy.setAttribute('aria-hidden','true');
    band.className='bandl'+rev;copy.appendChild(band);stage.appendChild(copy);
  });
  // The card's measured box, for the strip and the dashed edges
  function place(){
    const s=stage.style,c=card.getBoundingClientRect(),o=stage.getBoundingClientRect();
    s.setProperty('--cx',c.left-o.left-stage.clientLeft+card.clientLeft+'px');s.setProperty('--cy',c.top-o.top-stage.clientTop+card.clientTop+'px');
    s.setProperty('--cw',c.width-2*card.clientLeft+'px');s.setProperty('--ch',c.height-2*card.clientTop+'px');
  }
  // Every added band keeps the card's time, so they stay in step
  function syncBands(){
    const ref=card.getAnimations({subtree:true})[0];
    if(!ref||ref.currentTime==null)return;
    stage.getAnimations({subtree:true}).forEach(a=>{
      const t=a.effect&&a.effect.target;
      if(t&&(t.classList.contains('sband')||t.classList.contains('bandl')))a.currentTime=ref.currentTime;
    });
  }
  // Under reduced motion a mode pressed while the loop is paused shows its still, as on arrival (time zero, where the mode's rules
  // lay each band across its placeholder), and Normal gets back the moment the visitor paused at
  document.addEventListener('hb:mode',e=>{
    if(reduceMQ.matches&&paused){
      const all=stage.getAnimations({subtree:true});
      if(e.detail.mode!=='normal'){if(!held)held=all.map(a=>[a,a.currentTime]);all.forEach(a=>{a.currentTime=0})}
      else if(held){held.forEach(([a,t])=>{a.currentTime=t});held=null}
    }
    place();syncBands();
  });
  addEventListener('resize',place);

  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);
    }));
  }
  // A new --shim-dur keeps the time already played, so the band would jump to another point of its cycle.
  // Scaling each animation's time by the same factor as its length keeps the band where it is, moving or paused.
  choices('speed-seg',d=>{
    const next=+d.ms;
    stage.getAnimations({subtree:true}).forEach(a=>{if(a.currentTime!=null)a.currentTime=a.currentTime*next/shimMs});
    if(held)held.forEach(h=>{h[1]=h[1]*next/shimMs});
    shimMs=next;
    vars.setProperty('--shim-dur',next+'ms');
    captions();
  });
  choices('bright-seg',d=>{bright=d.bright;vars.setProperty('--shim-bright',d.bright);captions()});
  choices('angle-seg',d=>{vars.setProperty('--shim-angle',d.angle+'deg')});
  choices('color-sw',d=>{vars.setProperty('--shim-color',d.c)});
</script>
</body>
</html>