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 Click / Tap Ripple to the guided-steps page
matin925e823026c9
diff --git a/animations/04-micro-interactions/click-ripple/README.md b/animations/04-micro-interactions/click-ripple/README.mdindex 3540c997..42c84b24 100644--- a/animations/04-micro-interactions/click-ripple/README.md+++ b/animations/04-micro-interactions/click-ripple/README.md@@ -1,7 +1,7 @@# Click / Tap Ripple## What it is-A ripple is a circle that expands from the point of click or tap, fading as it grows. Popularized by Material Design, it gives users haptic-substitute feedback: the visual expansion communicates that the press registered, and the origin point confirms exactly where contact was made.+A ripple is a soft circle that grows out from the spot you press and fades away. It confirms that the press registered and shows exactly where it landed, which helps most on touch screens, where nothing reacts to hovering. Material Design, Google's design system, made it popular.## When to use it- Primary action buttons (submit, confirm, purchase)@@ -46,20 +46,22 @@ The button needs `position: relative; overflow: hidden` to contain the ripple.## Key parameters| Parameter | Default | Effect ||-----------|---------|--------|-| Duration | 600ms | Longer than a hover animation — the user has already committed the click |-| Max scale | 2.5× | Must be large enough to reach all button corners from any click point |-| Start opacity | 0.4 | Controls visibility of the highlight without washing out button content |-| Origin | Click point | Material default; "from center" is simpler but less accurate |+| Starts from | Where you press | Where you press shows exactly where the press landed; the middle is simpler but less exact |+| Speed | Normal | How long the ripple takes to spread and fade: slow is 1000ms, normal 600ms and fast 350ms; a little longer than a hover change, because the click is already made |+| Ripple size | Medium | How far the circle grows before it fades: small, medium or large; even small reaches every corner of the button |+| Ripple strength | Medium | How visible the ripple is at the start: faint is 20%, medium 40% and strong 60% |+| Ripple color | White | White suits colored buttons, orange matches the accent, black suits light buttons |## Production notes- **`overflow: hidden`** on the button is required — without it the ripple extends beyond the button boundary.- **`pointer-events: none`** on the ripple element prevents it from interfering with subsequent clicks fired in quick succession.- **Touch events**: `pointerdown` works for both mouse and touch. Avoid `mousedown` — it doesn't fire on touch.- **Cleanup**: always remove the element in `animationend`. In stress tests (rapid clicking) DOM nodes accumulate quickly without cleanup.+- **Reduced motion**: skip the growing circle and fade a flat highlight over the button instead, so the press still shows. The demo does this.- **GSAP**: `gsap.fromTo(el, { scale: 0 }, { scale: 2.5, opacity: 0, duration: 0.6, ease: "power2.out", onComplete: () => el.remove() })`.- **Material Web Components**: the `<md-ripple>` component handles all of this automatically including touch and keyboard activation.## See also-- [Button Press Scale](../button-press-scale/) — scale-based feedback complementing the ripple-- [Hover State Animation](../hover-state/) — pre-click affordance signaling-- [Checkmark Draw](../checkmark-draw/) — post-click confirmation feedback+- [Button Press Scale](../button-press-scale/) — the button shrinks while it is pressed+- [Hover State Animation](../hover-state/) — items react before they are clicked+- [Checkmark Draw](../checkmark-draw/) — a tick draws itself once the task is donediff --git a/animations/04-micro-interactions/click-ripple/index.html b/animations/04-micro-interactions/click-ripple/index.htmlindex c165b84c..dd29e167 100644--- a/animations/04-micro-interactions/click-ripple/index.html+++ b/animations/04-micro-interactions/click-ripple/index.html@@ -4,7 +4,7 @@<meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Click / Tap Ripple — Animation Handbook</title>- <meta name="description" content="Ripple emanates from the exact click point — Material Design's tactile confirmation pattern.">+ <meta name="description" content="A ripple spreads out from the spot you press. Best for buttons and list items."><link rel="canonical" href="https://matinmonshizadeh.github.io/animation-handbook/animations/04-micro-interactions/click-ripple/"><link rel="icon" type="image/png" sizes="96x96" href="../../../favicon.png"><link rel="icon" type="image/svg+xml" href="../../../favicon.svg">@@ -12,113 +12,168 @@<meta property="og:type" content="article"><meta property="og:site_name" content="Animation Handbook"><meta property="og:title" content="Click / Tap Ripple — Animation Handbook">- <meta property="og:description" content="Ripple emanates from the exact click point — Material Design's tactile confirmation pattern.">+ <meta property="og:description" content="A ripple spreads out from the spot you press. Best for buttons and list items."><meta property="og:url" content="https://matinmonshizadeh.github.io/animation-handbook/animations/04-micro-interactions/click-ripple/"><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="Click / Tap Ripple — Animation Handbook">- <meta name="twitter:description" content="Ripple emanates from the exact click point — Material Design's tactile confirmation pattern.">+ <meta name="twitter:description" content="A ripple spreads out from the spot you press. Best for buttons and list items."><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": "Click / Tap Ripple", "name": "Click / Tap Ripple", "description": "Ripple emanates from the exact click point — Material Design's tactile confirmation pattern.", "url": "https://matinmonshizadeh.github.io/animation-handbook/animations/04-micro-interactions/click-ripple/", "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, Click / Tap Ripple"}</script>+ <script type="application/ld+json">{"@context": "https://schema.org", "@type": "TechArticle", "headline": "Click / Tap Ripple", "name": "Click / Tap Ripple", "description": "A ripple spreads out from the spot you press. Best for buttons and list items.", "url": "https://matinmonshizadeh.github.io/animation-handbook/animations/04-micro-interactions/click-ripple/", "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, Click / Tap Ripple"}</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;--ripple-dur:600ms;--ripple-scale:2.5;--ripple-op:0.4}+ :root{--ui-accent:#ff9d5c;--ui-bg:#111114;--ui-border:rgba(255,255,255,.09);--ui-text:#f4f4f2;--ripple-dur:600ms;--ripple-scale:2.5}*,*::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;flex-direction:column;align-items:center;justify-content:center;gap:24px;padding:32px}- .rbtn{position:relative;overflow:hidden;border-radius:6px;font-family:monospace;font-size:13px;font-weight:bold;cursor:pointer;padding:0 32px;height:52px;border:none;transition:filter .15s;-webkit-user-select:none;user-select:none;min-width:180px}+ .stage{display:flex;flex-direction:column;align-items:center;justify-content:center;gap:20px;padding:24px;background:#0b0b0d}+ .rbtn{position:relative;overflow:hidden;border-radius:6px;font-family:inherit;font-size:13px;font-weight:bold;cursor:pointer;padding:0 32px;height:52px;border:none;transition:filter .15s;-webkit-user-select:none;user-select:none;min-width:180px}.rbtn-primary{background:var(--ui-accent);color:#000}.rbtn-secondary{background:transparent;border:2px solid var(--ui-accent)!important;color:var(--ui-accent)}.rbtn-ghost{background:var(--ui-bg);border:1px solid var(--ui-border)!important;color:var(--ui-text)}+ /* The site focus ring is drawn inside the button. On the Primary button it has the same orange as the fill, so it turns dark; on the Secondary button it would land on the button's own orange border, so it sits further in. */+ .hb-page .stage .rbtn-primary:focus-visible{outline-color:#0b0b0d}+ .hb-page .stage .rbtn-secondary:focus-visible{outline-offset:-6px}@media(hover:hover){.rbtn:hover{filter:brightness(1.1)}}.ripple{position:absolute;border-radius:50%;pointer-events:none;transform:scale(0);animation:ripple-go var(--ripple-dur) ease-out forwards}@keyframes ripple-go{to{transform:scale(var(--ripple-scale));opacity:0}}- .cnt-row{display:flex;gap:16px;font-size:10px;color:var(--ui-muted)}- .cv{color:var(--ui-text)}- 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)}- .kv{display:flex;justify-content:space-between;font-size:10px;color:var(--ui-muted)}- .kv .v{color:var(--ui-text)}- .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)}- select{background:var(--ui-bg);border:1px solid var(--ui-border);color:var(--ui-text);font-family:monospace;font-size:10px;padding:8px 6px;border-radius:4px;width:100%;min-height:44px}- .tog{display:flex;align-items:center;gap:8px;font-size:10px;cursor:pointer;min-height:44px}- .tog input{accent-color:var(--ui-accent);width:16px;height:16px;flex-shrink:0}- @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}:root{--stage-h:auto}.stage{width:100%;height:auto;min-height:380px}}- /* Reduced motion: collapse the ripple to near-instant (keep animationend cleanup firing) */- @media(prefers-reduced-motion:reduce){.ripple{animation-duration:1ms!important}.rbtn{transition:none!important}}+ /* Reduced motion: the circle does not grow; it appears at full size and only fades out */+ @keyframes ripple-fade{from{transform:scale(var(--ripple-scale))}to{transform:scale(var(--ripple-scale));opacity:0}}+ @media(prefers-reduced-motion:reduce){.ripple{animation-name:ripple-fade}.rbtn{transition:none!important}}</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=4">+ <script src="../../../assets/js/demo-page.js?v=4" 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="../hover-state/" rel="prev" title="Previous">‹ Prev</a><a class="ah-hideSm" href="../focus-ring/" 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/click-ripple/index.html" target="_blank" rel="noopener noreferrer">Source ↗</a></span></div>-<header>- <h1>Click / Tap Ripple</h1>- <p>Ripple emanates from the exact click point — Material Design's tactile confirmation pattern.</p>-</header>-<div class="layout">- <div class="stage">- <button class="rbtn rbtn-primary" id="b0">Primary Action</button>- <button class="rbtn rbtn-secondary" id="b1">Secondary Action</button>- <button class="rbtn rbtn-ghost" id="b2">Ghost / Outline</button>- <div class="cnt-row">- <span>Primary: <span class="cv" id="c0">0</span></span>- <span>Secondary: <span class="cv" id="c1">0</span></span>- <span>Ghost: <span class="cv" id="c2">0</span></span>+<body class="hb" data-hb-kind="do" 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="../hover-state/" rel="prev" aria-label="Previous: Hover State Animation"><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>Hover State Animation</span></a><a href="../focus-ring/" rel="next" aria-label="Next: Focus Ring Animation"><span><span class="hb-dir">Next: </span>Focus Ring Animation</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.02 · Micro-Interactions</p>+ <h1>Click / Tap Ripple</h1>+ <p class="hb-lede">A ripple spreads out from the spot you press. Best for buttons and list items.</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">Click it</h2><p>Click or tap anywhere on a button, or press Show me.</p></div>+ </div>+ <div class="stage hb-dots">+ <button class="rbtn rbtn-primary" type="button">Primary button</button>+ <button class="rbtn rbtn-secondary" type="button">Secondary button</button>+ <button class="rbtn rbtn-ghost" type="button">Outline button</button>+ </div>+ <div class="hb-player">+ <button class="hb-play" type="button" id="btn-demo" data-hb-demo><svg class="hb-ic" viewBox="0 0 24 24" aria-hidden="true"><path d="M4.037 4.688a.495.495 0 0 1 .651-.651l16 6.5a.5.5 0 0 1-.063.947l-6.124 1.58a2 2 0 0 0-1.438 1.435l-1.579 6.126a.5.5 0 0 1-.947.063z"/></svg>Show me</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>+ </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, then try it again or press Show me.</p></div>+ </div>+ <div class="hb-settings">+ <div class="hb-setting">+ <p class="hb-setting-name" id="from-lbl">Starts from</p>+ <div class="seg" id="from-seg" role="group" aria-labelledby="from-lbl">+ <button type="button" data-center="false" class="on" aria-pressed="true">Where you press</button>+ <button type="button" data-center="true" aria-pressed="false">The middle</button>+ </div>+ <p class="hb-hint">Where you press shows exactly where it landed.</p>+ </div>+ <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="1000" aria-pressed="false">Slow</button>+ <button type="button" data-ms="600" class="on" aria-pressed="true">Normal</button>+ <button type="button" data-ms="350" aria-pressed="false">Fast</button>+ </div>+ <p class="hb-hint">How long the ripple takes to spread and fade.</p>+ </div>+ <div class="hb-setting">+ <p class="hb-setting-name" id="size-lbl">Ripple size</p>+ <div class="seg" id="size-seg" role="group" aria-labelledby="size-lbl">+ <button type="button" data-scale="1.5" aria-pressed="false">Small</button>+ <button type="button" data-scale="2.5" class="on" aria-pressed="true">Medium</button>+ <button type="button" data-scale="4" aria-pressed="false">Large</button>+ </div>+ <p class="hb-hint">How far the circle grows before it fades.</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="str-lbl">Ripple strength</p>+ <div class="seg" id="str-seg" role="group" aria-labelledby="str-lbl">+ <button type="button" data-op="0.2" aria-pressed="false">Faint</button>+ <button type="button" data-op="0.4" class="on" aria-pressed="true">Medium</button>+ <button type="button" data-op="0.6" aria-pressed="false">Strong</button>+ </div>+ <p class="hb-hint">How visible the ripple is when it starts.</p>+ </div>+ <div class="hb-setting">+ <p class="hb-setting-name" id="color-lbl">Ripple 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="Orange" data-c="255,157,92" style="background:#ff9d5c"></button>+ <button type="button" aria-pressed="false" aria-label="Black" data-c="0,0,0" style="background:#000000"></button>+ </div>+ <p class="hb-hint">Pick a color that shows up on your buttons.</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>- <aside>- <p class="note">The ripple originates from the click point. getBoundingClientRect() gives the button's position, then subtract to get local click coordinates.</p>- <div class="lbl">Duration</div>- <div class="sr"><input type="range" id="dur-sl" min="300" max="1000" value="600" step="50"><span class="sv" id="dur-v">600ms</span></div>- <div class="lbl">Max Scale</div>- <div class="sr"><input type="range" id="scale-sl" min="15" max="40" value="25" step="1"><span class="sv" id="scale-v">2.5×</span></div>- <div class="lbl">Start Opacity</div>- <div class="sr"><input type="range" id="op-sl" min="2" max="7" value="4" step="1"><span class="sv" id="op-v">0.4</span></div>- <div class="lbl">Ripple Color</div>- <select id="color-sel">- <option value="255,255,255" selected>White</option>- <option value="255,157,92">Accent</option>- <option value="0,0,0">Dark</option>- </select>- <label class="tog"><input type="checkbox" id="center-tog"><span>From center (not click point)</span></label>- <div class="div"></div>- <div class="kv"><span>Total clicks</span><span class="v" id="total">0</span></div>- </aside>-</div>+ <div class="hb-card">+ <p class="hb-prompt">Add a ripple to [the buttons or list items you want to respond to presses]. When the visitor presses one, a soft circle appears where they pressed, or in the middle when the settings say so, then grows outward and fades away. Clip it to the button's shape so it never spills outside, start it as soon as the press begins so the feedback feels instant, and remove each ripple once it has faded so quick taps do not pile up. It should work the same for mouse, touch and pen. If the visitor has reduced motion turned on, fade a flat highlight over the button instead of a growing circle. 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>+ </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>Buttons</li><li>List items</li><li>Menu items</li><li>Icon buttons</li></ul>+ <h3>Avoid on</h3>+ <ul class="hb-tags hb-avoid"><li>Links in text</li><li>Large panels</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>- const btns=document.querySelectorAll('.rbtn');- const counts=[0,0,0];- let total=0,dur=600,scale=2.5,opacity=0.4,color='255,255,255',fromCenter=false;+ const btns=[...document.querySelectorAll('.rbtn')];+ const slowTog=document.getElementById('slow-tog');+ let dur=600,scale=2.5,opacity=0.4,color='255,255,255',fromCenter=false,runTimers=[];function spawnRipple(btn,e){const r=btn.getBoundingClientRect();const size=Math.max(r.width,r.height)*2;- let x,y;- if(fromCenter){x=r.width/2;y=r.height/2;}- else{const src=e.touches?e.touches[0]:e;x=src.clientX-r.left;y=src.clientY-r.top;}+ const x=fromCenter?r.width/2:e.clientX-r.left;+ const y=fromCenter?r.height/2:e.clientY-r.top;const el=document.createElement('span');el.className='ripple';el.style.cssText=`width:${size}px;height:${size}px;left:${x-size/2}px;top:${y-size/2}px;background:rgba(${color},${opacity});animation-duration:${dur}ms`;@@ -126,22 +181,42 @@ body{padding-top:46px}btn.appendChild(el);el.addEventListener('animationend',()=>el.remove(),{once:true});}+ btns.forEach(btn=>btn.addEventListener('pointerdown',e=>spawnRipple(btn,e)));- btns.forEach((btn,i)=>{- btn.addEventListener('pointerdown',e=>{- spawnRipple(btn,e);- counts[i]++;total++;- document.getElementById('c'+i).textContent=counts[i];- document.getElementById('total').textContent=total;+ // Show me: one run at a time. Every timer of the run goes through later(); stopRun() cancels the whole run.+ // later(fn, move, hold) waits move*(slow?3:1) + hold ms: Slow motion triples the movement, never the hold.+ function later(fn,move,hold){+ const id=setTimeout(()=>{runTimers=runTimers.filter(t=>t!==id);fn()},move*(slowTog.checked?3:1)+(hold||0));+ runTimers.push(id);+ }+ function running(){return runTimers.length>0}+ function stopRun(){runTimers.forEach(clearTimeout);runTimers=[]}+ // Each button is pressed once, at a different spot: a quarter across, three quarters across and the middle, all at half height.+ // A press waits for the ripple before it (its whole time) plus 100ms.+ document.getElementById('btn-demo').addEventListener('click',()=>{+ stopRun();+ [0.25,0.75,0.5].forEach((across,i)=>{+ later(()=>{+ const r=btns[i].getBoundingClientRect();+ spawnRipple(btns[i],{clientX:r.left+r.width*across,clientY:r.top+r.height/2});+ },i*dur,i*100);});});+ // The visitor pressed, typed, scrolled or touched inside the stage: the run stops. Ripples already spreading finish by themselves.+ document.addEventListener('hb:input',()=>{if(running())stopRun()});- document.getElementById('dur-sl').addEventListener('input',e=>{dur=+e.target.value;document.getElementById('dur-v').textContent=dur+'ms'});- document.getElementById('scale-sl').addEventListener('input',e=>{scale=e.target.value/10;document.getElementById('scale-v').textContent=scale.toFixed(1)+'×'});- document.getElementById('op-sl').addEventListener('input',e=>{opacity=e.target.value/10;document.getElementById('op-v').textContent=opacity.toFixed(1)});- document.getElementById('color-sel').addEventListener('change',e=>{color=e.target.value});- document.getElementById('center-tog').addEventListener('change',e=>{fromCenter=e.target.checked});+ 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('from-seg',d=>{fromCenter=d.center==='true'});+ choices('speed-seg',d=>{dur=+d.ms});+ choices('size-seg',d=>{scale=+d.scale});+ choices('str-seg',d=>{opacity=+d.op});+ choices('color-sw',d=>{color=d.c});</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 f1939b04..3a59ac9d 100644--- a/index.html+++ b/index.html@@ -952,7 +952,7 @@ const CATS=[folder:'animations/04-micro-interactions',entries:[['hover-state','Hover State Animation','Six ways a card can react when you point at it. Best for buttons and cards.'],- ['click-ripple','Click / Tap Ripple','Ripple emanates from the exact click point — Material Design\'s tactile confirmation pattern.'],+ ['click-ripple','Click / Tap Ripple','A ripple spreads out from the spot you press. Best for buttons and list items.'],['focus-ring','Focus Ring Animation','Animated outline on keyboard Tab — :focus-visible ensures mouse users see no ring.'],['button-press-scale','Button Press Scale','Scales to 0.95 on press, springs back on release — asymmetric timing gives a tactile feel.'],['magnetic-button','Magnetic Button','Button leans toward the cursor within a radius, label lagging for parallax — springs home on exit.'],