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.
HTML ai-promptsanimationcss-animationsfrontendgithub-pagesjavascriptmicrointeractionsmotion-designno-dependenciesreferencescroll-animationui-animationweb-animationweb-developmentwebgl
feat: move Skeleton Loader to the guided-steps page
matinff681c5e87bb
diff --git a/animations/04-micro-interactions/skeleton-loader/README.md b/animations/04-micro-interactions/skeleton-loader/README.mdindex 6aee9f21..665f693e 100644--- a/animations/04-micro-interactions/skeleton-loader/README.md+++ b/animations/04-micro-interactions/skeleton-loader/README.md@@ -1,7 +1,7 @@# Skeleton Loader## What it is-A skeleton loader is a set of placeholder shapes — gray blocks matching the layout of real content — displayed while data loads. The blocks pulse subtly to signal active loading. Unlike a spinner, a skeleton tells the user what shape of content is coming, which measurably reduces perceived wait time even when actual load time is identical.+A skeleton loader shows gray placeholder shapes in the layout of the content that is on its way. The blocks pulse gently to show that loading is going on, and the real content fades in over them when it arrives. Because people see the shape of what is coming, the wait feels shorter than it does with a blank area or a spinner.## When to use it- Social feeds, cards, and lists where content arrives from an API@@ -46,10 +46,9 @@ The content element needs `opacity: 0; transition: opacity 400ms ease` to fade i## Key parameters| Parameter | Default | Effect ||-----------|---------|--------|-| Pulse speed | 1.5s | 1–2s is the natural breathing range; faster feels anxious |-| Min opacity | 0.5 | Lower = more dramatic pulse; 0.4–0.6 is subtle |-| Shape fidelity | Medium | Match line heights, avatar sizes, image ratios exactly for best effect |-| Content fade | 400ms | Instant swap feels jarring; 300–500ms is smooth |+| Pulse speed | Normal | How long one pulse takes: slow is 2.4s, normal 1.5s and fast 0.9s; one to two seconds feels calm, faster feels anxious |+| Pulse strength | Medium | How far the blocks fade between pulses: soft, medium or strong; a soft pulse is enough |+| Loading time | Medium | How long the placeholders show before the content fades in: short is 1s, medium 2s and long 3.5s |## Production notes- **Shape matching matters**: a skeleton that doesn't match the incoming content causes layout shift and undermines the effect. Measure real content dimensions and match them.@@ -60,6 +59,6 @@ The content element needs `opacity: 0; transition: opacity 400ms ease` to fade i- **Pairing**: skeleton + shimmer (see [Shimmer Effect](../shimmer-effect/)) is the most polished loading state — pulse for structure, shimmer for motion.## See also-- [Shimmer Effect](../shimmer-effect/) — gradient sweep enhancement for skeleton loaders-- [Loading Spinner](../loading-spinner/) — alternative for unknown-duration loads-- [Progress Animation](../progress-animation/) — alternative when total progress is known+- [Shimmer Effect](../shimmer-effect/) — a band of light sweeps across the placeholders+- [Loading Spinner](../loading-spinner/) — a spinner for waits of unknown length+- [Progress Animation](../progress-animation/) — a bar that shows how much is donediff --git a/animations/04-micro-interactions/skeleton-loader/index.html b/animations/04-micro-interactions/skeleton-loader/index.htmlindex 22670cfa..15130985 100644--- a/animations/04-micro-interactions/skeleton-loader/index.html+++ b/animations/04-micro-interactions/skeleton-loader/index.html@@ -4,7 +4,7 @@<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="Pulsing placeholder blocks match the shape of real content — reduces perceived wait time.">+ <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">@@ -12,29 +12,20 @@<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="Pulsing placeholder blocks match the shape of real content — reduces perceived wait time.">+ <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="Pulsing placeholder blocks match the shape of real content — reduces perceived wait time.">+ <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": "Pulsing placeholder blocks match the shape of real content — reduces perceived wait time.", "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>+ <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>- @font-face{font-family:'Bricolage';src:url('../../../assets/fonts/brico-700.woff2') format('woff2');font-weight:700;font-display:swap}- @font-face{font-family:'Bricolage';src:url('../../../assets/fonts/brico-800.woff2') format('woff2');font-weight:800;font-display:swap}- @font-face{font-family:'PlexMono';src:url('../../../assets/fonts/plex-400.woff2') format('woff2');font-weight:400;font-display:swap}- @font-face{font-family:'PlexMono';src:url('../../../assets/fonts/plex-500.woff2') format('woff2');font-weight:500;font-display:swap}- :root{--bg:#0b0b0d;--ui-bg:#111114;--ui-border:rgba(255,255,255,.09);--ui-accent:#ff9d5c;--ui-text:#f4f4f2;--ui-muted:#77777e;--disp:'Bricolage','Arial Narrow',sans-serif;--mono:'PlexMono',ui-monospace,Menlo,Consolas,monospace;--stage-h:620px;--skel-bg:#1a1f28;--pulse-min:0.5;--pulse-spd:1.5s;--load-dur:2000}+ :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}- body{background:var(--bg);color:var(--ui-text);font-family:var(--mono);-webkit-font-smoothing:antialiased;padding:clamp(12px,3vw,24px)}- header{margin-bottom:20px}- header h1{font-family:var(--disp);font-weight:700;font-size:clamp(11px,1.8vw,15px);letter-spacing:-.01em}- header p{font-size:clamp(10px,1.2vw,12px);color:var(--ui-muted);margin-top:4px}- .layout{display:flex;gap:clamp(12px,2vw,24px);align-items:flex-start}- .stage{flex:1;min-width:0;height:var(--stage-h);border:1px solid var(--ui-border);border-radius:8px;background:var(--bg);display:flex;align-items:center;justify-content:center;padding:24px}+ .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:20px;position:relative;min-height:260px;display:grid}+ .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}@@ -45,65 +36,47 @@.sk-line.w80{width:80%}.sk-line.w60{width:60%}.sk-line.w40{width:40%}- .sk-img{width:100%;height:120px;border-radius:6px;margin-top:14px}+ .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 400ms ease;pointer-events:none}+ .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:10px;color:var(--ui-muted);margin-top:2px}- .real-img{width:100%;height:120px;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-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}- /* Progress bar */- .load-bar-wrap{width:100%;max-width:340px;margin-top:16px}- .load-bar-track{height:2px;background:var(--ui-border);border-radius:1px;overflow:hidden}- .load-bar-fill{height:100%;background:var(--ui-accent);transform:scaleX(0);transform-origin:left;transition:transform 100ms linear;border-radius:1px}- .load-label{font-size:10px;color:var(--ui-muted);margin-top:6px;text-align:center}- /* Panel */- aside{width:clamp(200px,22vw,240px);flex-shrink:0;background:var(--ui-bg);border:1px solid var(--ui-border);border-radius:8px;padding:16px;display:flex;flex-direction:column;gap:10px}- .note{font-size:10px;color:var(--ui-muted);line-height:1.6;border-left:2px solid var(--ui-accent);padding-left:8px}- .lbl{font-size:10px;text-transform:uppercase;letter-spacing:1px;color:var(--ui-accent)}- .div{height:1px;background:var(--ui-border)}- .sr{display:flex;align-items:center;gap:6px;font-size:10px}- .sr input[type=range]{flex:1;accent-color:var(--ui-accent);min-height:44px}- .sv{width:44px;text-align:right;color:var(--ui-text)}- button.rst{background:transparent;border:1px solid var(--ui-border);color:var(--ui-text);font-family:var(--mono);font-size:10px;padding:14px 8px;min-height:44px;border-radius:4px;cursor:pointer;width:100%}- @media(hover:hover){button.rst:hover{border-color:var(--ui-accent);color:var(--ui-accent)}}- @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}:root{--stage-h:auto}.stage{width:100%;height:auto;min-height:400px}}@media(prefers-reduced-motion:reduce){.skel{animation:none!important;opacity:.6}}</style>-<style id="ah-inject">-:root{--ah-bg:rgba(17,17,20,.82);--ah-line:rgba(255,255,255,.1);--ah-ink:#f4f4f2;--ah-muted:#9a9aa2;--ah-accent:#6ea8ff}-body{padding-top:46px}-.ah-bar{position:fixed;top:0;left:0;right:0;height:46px;z-index:2147483000;display:flex;align-items:center;justify-content:space-between;gap:10px;padding:0 clamp(10px,3vw,18px);background:var(--ah-bg);backdrop-filter:blur(10px);-webkit-backdrop-filter:blur(10px);border-bottom:1px solid var(--ah-line);font-family:ui-monospace,Menlo,Consolas,monospace;font-size:12px;box-sizing:border-box}-.ah-bar a,.ah-bar button{color:var(--ah-muted);text-decoration:none;background:none;border:0;font:inherit;cursor:pointer;display:inline-flex;align-items:center;gap:6px;min-height:34px;padding:0 7px;border-radius:6px;transition:color .18s,background .18s;white-space:nowrap}-.ah-bar a:hover,.ah-bar button:hover{color:var(--ah-ink)}-.ah-home{color:var(--ah-ink);font-weight:600}-.ah-actions{display:flex;align-items:center;gap:2px}-.ah-sep{width:1px;height:16px;background:var(--ah-line);margin:0 4px}-.ah-copied{color:var(--ah-accent)!important}-@media(max-width:600px){.ah-bar .ah-hideSm{display:none}}-@media print{.ah-bar{display:none}body{padding-top:0}}-</style>+ <link rel="stylesheet" href="../../../assets/css/demo-page.css?v=3">+ <script src="../../../assets/js/demo-page.js?v=3" defer></script></head>-<body>-<div class="ah-bar" role="navigation" aria-label="Animation Handbook"><a class="ah-home" href="../../../">← Animation Handbook</a><span class="ah-actions"><a class="ah-hideSm" href="../success-confetti/" rel="prev" title="Previous">‹ Prev</a><a class="ah-hideSm" href="../shimmer-effect/" rel="next" title="Next">Next ›</a><span class="ah-sep ah-hideSm"></span><button type="button" id="ah-copy" class="ah-hideSm">Copy source</button><a class="ah-hideSm" href="https://github.com/matinmonshizadeh/animation-handbook/blob/main/animations/04-micro-interactions/skeleton-loader/index.html" target="_blank" rel="noopener noreferrer">Source ↗</a></span></div>-<header>- <h1>Skeleton Loader</h1>- <p>Pulsing placeholder blocks match the shape of real content — reduces perceived wait time.</p>-</header>-<div class="layout">- <div class="stage">- <div style="width:100%;max-width:340px">+<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>+</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="stage hb-dots"><div class="card-wrap" id="card"><!-- Skeleton --><div id="skel-content"><div class="skel-header"><div class="skel sk-avatar"></div>- <div style="flex:1"><div class="skel sk-line w80"></div><div class="skel sk-line w40" style="margin-top:6px"></div></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>@@ -117,71 +90,161 @@ body{padding-top:46px}<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">A new collection of coastal landscapes — shot at the edge of the Pacific where light meets water and everything else disappears.</div>+ <div class="real-text">New coastal landscapes, shot where the light meets the water.</div>+ </div>+ </div>+ </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>+ </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>- <div class="load-bar-wrap">- <div class="load-bar-track"><div class="load-bar-fill" id="load-fill"></div></div>- <div class="load-label" id="load-label">Loading…</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>- <aside>- <p class="note">Skeleton loaders reduce perceived wait time — users see the shape of what's coming. A spinner gives no information; a skeleton tells them what's arriving.</p>- <div class="lbl">Load Duration</div>- <div class="sr"><input type="range" id="dur-sl" min="500" max="5000" value="2000" step="100"><span class="sv" id="dur-v">2.0s</span></div>- <div class="lbl">Pulse Speed</div>- <div class="sr"><input type="range" id="pulse-sl" min="10" max="30" value="15" step="1"><span class="sv" id="pulse-v">1.5s</span></div>- <div class="lbl">Pulse Intensity</div>- <div class="sr"><input type="range" id="int-sl" min="3" max="9" value="5" step="1"><span class="sv" id="int-v">0.5</span></div>- <div class="div"></div>- <button class="rst" id="reload-btn">↺ Reload sequence</button>- </aside>-</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="#top">Back to top ↑</a></footer><script>- let loadDur=2000,timer=null,rafId=null;- const skelEl=document.getElementById('skel-content');- const realEl=document.getElementById('real-content');- const fill=document.getElementById('load-fill');- const label=document.getElementById('load-label');+ 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=[];- function startLoad(){- if(timer)clearTimeout(timer);if(rafId)cancelAnimationFrame(rafId);- skelEl.style.visibility='';realEl.classList.remove('visible');- fill.style.transform='scaleX(0)';label.textContent='Loading…';- const start=performance.now();- function tick(now){- const p=Math.min((now-start)/loadDur,1);- fill.style.transform='scaleX('+p.toFixed(3)+')';- if(p<1){rafId=requestAnimationFrame(tick);}- else{reveal();}- }- rafId=requestAnimationFrame(tick);+ // 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: 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='';+ realEl.style.transition='none';+ realEl.classList.remove('visible');+ void realEl.offsetWidth;+ realEl.style.transition='';}-function reveal(){- label.textContent='Loaded';skelEl.style.visibility='hidden';realEl.classList.add('visible');}+ // 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(){+ apply();+ showPlaceholders();+ const fade=400*mult();+ later(()=>{+ reveal();+ later(()=>{+ if(!loopTog.checked||!motionOk)return;+ cycle();+ },fade+1600);+ },loadDur);+ }+ function play(){timers.forEach(clearTimeout);timers=[];cycle()}- document.getElementById('dur-sl').addEventListener('input',e=>{- loadDur=+e.target.value;- document.getElementById('dur-v').textContent=(loadDur/1000).toFixed(1)+'s';- });- document.getElementById('pulse-sl').addEventListener('input',e=>{- const v=(e.target.value/10).toFixed(1);- document.getElementById('pulse-v').textContent=v+'s';- document.documentElement.style.setProperty('--pulse-spd',v+'s');- });- document.getElementById('int-sl').addEventListener('input',e=>{- const v=(e.target.value/10).toFixed(1);- document.getElementById('int-v').textContent=v;- document.documentElement.style.setProperty('--pulse-min',v);- });- document.getElementById('reload-btn').addEventListener('click',startLoad);- startLoad();+ document.getElementById('btn-play').addEventListener('click',play);+ loopTog.addEventListener('change',()=>{if(loopTog.checked)play()});+ 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);+ }));+ }+ choices('pulse-seg',d=>{pulseMs=+d.ms});+ choices('strength-seg',d=>{pulseMin=d.min});+ choices('load-seg',d=>{loadDur=+d.ms});+ apply();</script>-<script>(function(){var b=document.getElementById("ah-copy");if(!b)return;b.addEventListener("click",function(){fetch(location.href).then(function(r){return r.text();}).catch(function(){return document.documentElement.outerHTML;}).then(function(t){return navigator.clipboard.writeText(t);}).then(function(){b.textContent="Copied!";b.classList.add("ah-copied");setTimeout(function(){b.textContent="Copy source";b.classList.remove("ah-copied");},1500);}).catch(function(){b.textContent="Copy failed";setTimeout(function(){b.textContent="Copy source";},1500);});});})();</script></body></html>diff --git a/index.html b/index.htmlindex 4d518cf1..2db568c2 100644--- a/index.html+++ b/index.html@@ -959,7 +959,7 @@ const CATS=[['toggle-switch','Toggle / Switch Slide','Pill slides left/right for on/off — smooth cubic-bezier gives a weighted, physical feel.'],['heart-burst','Heart / Like Burst','Tap pops and fills the heart while small hearts burst outward on canvas — Twitter-style like.'],['success-confetti','Success Confetti','Completing an action fires a canvas confetti burst — rotating rectangles with gravity and spin.'],- ['skeleton-loader','Skeleton Loader','Pulsing placeholder blocks match the shape of real content — reduces perceived wait time.'],+ ['skeleton-loader','Skeleton Loader','Gray shapes hold the place of content while it loads. Best for feeds and cards.'],['shimmer-effect','Shimmer Effect','Gradient sweep over skeleton placeholders — gives the impression of data streaming in.'],['loading-spinner','Loading Spinner','Six spinner variants from a single CSS color and speed — ring, orbit, arc, bounce, pulse, square.'],['progress-animation','Progress Animation','Linear bar, circular ring, and stepped segments — all driven by a single percentage value.'],