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.

feat: move Button Press Scale to the guided-steps page

matin50851134c4cd
diff --git a/animations/04-micro-interactions/button-press-scale/README.md b/animations/04-micro-interactions/button-press-scale/README.md
index ef62e813..3e60f0d3 100644
--- a/animations/04-micro-interactions/button-press-scale/README.md
+++ b/animations/04-micro-interactions/button-press-scale/README.md
@@ -1,7 +1,7 @@
# Button Press Scale
## What it is
-Button press scale is a micro-animation where a button shrinks slightly on `pointerdown` and springs back on `pointerup`. Without physical button travel, this visual shrink substitutes for the tactile sensation of pressing a real button — it confirms the press registered and creates a satisfying click-like feel.
+Button press scale makes a button shrink slightly while it is pressed and spring back when it is let go. A screen has no real button travel, so this small shrink stands in for the feel of pushing a physical button, and it confirms that the press registered.
## When to use it
- Primary action buttons (submit, confirm, pay, send)
@@ -48,20 +48,20 @@ The asymmetric timing is the key insight: pressing (80ms) mirrors the physical s
## Key parameters
| Parameter | Default | Effect |
|-----------|---------|--------|
-| Press scale | 0.95 | 0.92–0.97 is the useful range; below 0.9 looks broken |
-| Press duration | 80ms | Should feel instantaneous — 50–100ms is typical |
-| Release duration | 180ms | 1.5–2.5× the press duration for spring-back feel |
-| Release easing | `cubic-bezier(.34,1.56,.64,1)` | Overshoot creates the spring; remove overshoot for flat |
+| Press depth | Medium | How small the button gets while held down: light is 97%, medium 95% and deep 90% of its size; smaller than 90% looks broken |
+| Release speed | Normal | How long it takes to spring back: slow is 300ms, normal 180ms and fast 110ms; about twice the press time feels natural |
+| Release feel | Springy | Springy goes a little past full size, then settles; Smooth slows into place; Even keeps one steady pace |
+| Press speed | Normal | How long the shrink takes: slow is 130ms, normal 80ms and fast 50ms; a press should feel instant |
## Production notes
- **`pointercancel` handling**: always listen for `pointercancel` in addition to `pointerup`. If the user starts a scroll gesture after pressing, `pointerup` may not fire, leaving the button stuck in its pressed state.
- **`touch-action: manipulation`** on the button element suppresses the 300ms tap delay on mobile browsers without needing a separate fast-tap library.
- **Shadow pairing**: coupling a shadow-shrink to the scale change increases realism — a button that lifts slightly on hover and drops on press mirrors physical button behavior.
-- **`prefers-reduced-motion`**: users who request reduced motion should see no transform. Wrap the transition in a media query or check `matchMedia` in JS.
+- **`prefers-reduced-motion`**: switch the transitions off for users who request reduced motion, so the button changes size at once instead of animating; the demo does this.
- **GSAP**: `gsap.to(btn, { scale: 0.95, duration: 0.08, ease: "power1.in" })` on press; `gsap.to(btn, { scale: 1, duration: 0.18, ease: "back.out(1.7)" })` on release.
- **Framer Motion**: `<motion.button whileTap={{ scale: 0.95 }} />` — single prop, handles press/release automatically.
## See also
-- [Click / Tap Ripple](../click-ripple/) — complementary click-point feedback
-- [Hover State Animation](../hover-state/) — pre-click affordance
-- [Checkmark Draw](../checkmark-draw/) — post-action success confirmation
+- [Click / Tap Ripple](../click-ripple/) — a ripple spreads from the spot you press
+- [Hover State Animation](../hover-state/) — items react before they are clicked
+- [Checkmark Draw](../checkmark-draw/) — a tick draws itself once the task is done
diff --git a/animations/04-micro-interactions/button-press-scale/index.html b/animations/04-micro-interactions/button-press-scale/index.html
index 87aff214..1809072f 100644
--- a/animations/04-micro-interactions/button-press-scale/index.html
+++ b/animations/04-micro-interactions/button-press-scale/index.html
@@ -4,7 +4,7 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Button Press Scale — Animation Handbook</title>
- <meta name="description" content="Scales to 0.95 on press, springs back on release — asymmetric timing gives a tactile feel.">
+ <meta name="description" content="Shrinks as you press it and springs back as you let go. Best for main buttons.">
<link rel="canonical" href="https://matinmonshizadeh.github.io/animation-handbook/animations/04-micro-interactions/button-press-scale/">
<link rel="icon" type="image/png" sizes="96x96" href="../../../favicon.png">
<link rel="icon" type="image/svg+xml" href="../../../favicon.svg">
@@ -12,138 +12,208 @@
<meta property="og:type" content="article">
<meta property="og:site_name" content="Animation Handbook">
<meta property="og:title" content="Button Press Scale — Animation Handbook">
- <meta property="og:description" content="Scales to 0.95 on press, springs back on release — asymmetric timing gives a tactile feel.">
+ <meta property="og:description" content="Shrinks as you press it and springs back as you let go. Best for main buttons.">
<meta property="og:url" content="https://matinmonshizadeh.github.io/animation-handbook/animations/04-micro-interactions/button-press-scale/">
<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="Button Press Scale — Animation Handbook">
- <meta name="twitter:description" content="Scales to 0.95 on press, springs back on release — asymmetric timing gives a tactile feel.">
+ <meta name="twitter:description" content="Shrinks as you press it and springs back as you let go. Best for main buttons.">
<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": "Button Press Scale", "name": "Button Press Scale", "description": "Scales to 0.95 on press, springs back on release — asymmetric timing gives a tactile feel.", "url": "https://matinmonshizadeh.github.io/animation-handbook/animations/04-micro-interactions/button-press-scale/", "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, Button Press Scale"}</script>
+ <script type="application/ld+json">{"@context": "https://schema.org", "@type": "TechArticle", "headline": "Button Press Scale", "name": "Button Press Scale", "description": "Shrinks as you press it and springs back as you let go. Best for main buttons.", "url": "https://matinmonshizadeh.github.io/animation-handbook/animations/04-micro-interactions/button-press-scale/", "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, Button Press Scale"}</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;--press-scale:0.95;--press-dur:80ms;--release-dur:180ms;--release-ease:cubic-bezier(.34,1.56,.64,1)}
+ :root{--ui-accent:#ff9d5c;--ui-bg:#111114;--ui-border:rgba(255,255,255,.09);--ui-text:#f4f4f2;--press-scale:0.95;--press-dur:80ms;--release-dur:180ms;--release-ease:cubic-bezier(.34,1.56,.64,1)}
*,*::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:28px;padding:32px}
- .pbtn{border:none;border-radius:8px;font-family:monospace;font-size:14px;font-weight:bold;cursor:pointer;padding:0 36px;height:56px;min-width:200px;transform-origin:center;transition:transform var(--release-dur) var(--release-ease),box-shadow var(--release-dur) var(--release-ease);-webkit-user-select:none;user-select:none;touch-action:manipulation}
- .pbtn.pressed{transition:transform var(--press-dur) ease,box-shadow var(--press-dur) ease;transform:scale(var(--press-scale))}
- .pbtn-primary{background:var(--ui-accent);color:#000;box-shadow:0 4px 20px rgba(255,157,92,.35)}
- .pbtn-primary.pressed{box-shadow:0 1px 6px rgba(255,157,92,.2)}
- .pbtn-success{background:#56d364;color:#000;box-shadow:0 4px 20px rgba(86,211,100,.3)}
- .pbtn-success.pressed{box-shadow:0 1px 6px rgba(86,211,100,.15)}
- .pbtn-ghost{background:var(--ui-bg);border:1px solid var(--ui-border)!important;color:var(--ui-text);box-shadow:0 4px 14px rgba(0,0,0,.4)}
- .pbtn-ghost.pressed{box-shadow:0 1px 4px rgba(0,0,0,.3)}
- .cnt-row{display:flex;gap:20px;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}
- @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}:root{--stage-h:auto}.stage{width:100%;height:auto;min-height:360px}}
- @media(prefers-reduced-motion:reduce){.pbtn,.pbtn.pressed{transition:none!important}}
+ .stage{display:flex;flex-direction:column;align-items:center;justify-content:center;gap:28px;padding:24px;background:#0b0b0d}
+ /* A window this short gives the stage 260px, less than the three buttons need: the gap between them gives way, the buttons keep their size */
+ @media(min-width:601px) and (max-height:620px){.stage{gap:20px}}
+ .pbtn{position:relative;border:none;border-radius:8px;font-family:inherit;font-size:14px;font-weight:bold;cursor:pointer;padding:0 36px;height:56px;min-width:200px;transform-origin:center;transition:transform var(--release-dur) var(--release-ease);-webkit-user-select:none;user-select:none;touch-action:manipulation}
+ .pbtn.pressed{transition:transform var(--press-dur) ease;transform:scale(var(--press-scale))}
+ /* The glow is two layers that trade places by opacity: ::before is the resting shadow, ::after the pressed one, both with the same timing as the size */
+ .pbtn::before,.pbtn::after{content:'';position:absolute;inset:0;border-radius:inherit;pointer-events:none;transition:opacity var(--release-dur) var(--release-ease)}
+ .pbtn::after{opacity:0}
+ .pbtn.pressed::before,.pbtn.pressed::after{transition:opacity var(--press-dur) ease}
+ .pbtn.pressed::before{opacity:0}
+ .pbtn.pressed::after{opacity:1}
+ .pbtn-primary{background:var(--ui-accent);color:#000}
+ .pbtn-primary::before{box-shadow:0 4px 20px rgba(255,157,92,.35)}
+ .pbtn-primary::after{box-shadow:0 1px 6px rgba(255,157,92,.2)}
+ .pbtn-success{background:#56d364;color:#000}
+ .pbtn-success::before{box-shadow:0 4px 20px rgba(86,211,100,.3)}
+ .pbtn-success::after{box-shadow:0 1px 6px rgba(86,211,100,.15)}
+ .pbtn-ghost{background:var(--ui-bg);border:1px solid var(--ui-border)!important;color:var(--ui-text)}
+ .pbtn-ghost::before,.pbtn-ghost::after{inset:-1px}
+ .pbtn-ghost::before{box-shadow:0 4px 14px rgba(0,0,0,.4)}
+ .pbtn-ghost::after{box-shadow:0 1px 4px rgba(0,0,0,.3)}
+ /* The site focus ring is drawn inside the button. On the orange and green buttons it is as light as the fill, so it turns dark. */
+ .hb-page .stage .pbtn-primary:focus-visible,.hb-page .stage .pbtn-success:focus-visible{outline-color:#0b0b0d}
+ @media(prefers-reduced-motion:reduce){.pbtn,.pbtn.pressed,.pbtn::before,.pbtn::after{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="../focus-ring/" rel="prev" title="Previous">‹ Prev</a><a class="ah-hideSm" href="../magnetic-button/" 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/button-press-scale/index.html" target="_blank" rel="noopener noreferrer">Source ↗</a></span></div>
-<header>
- <h1>Button Press Scale</h1>
- <p>Scales to 0.95 on press, springs back on release — asymmetric timing gives a tactile feel.</p>
-</header>
-<div class="layout">
- <div class="stage">
- <button class="pbtn pbtn-primary" id="b0" aria-label="Confirm">Confirm</button>
- <button class="pbtn pbtn-success" id="b1" aria-label="Save">Save Draft</button>
- <button class="pbtn pbtn-ghost" id="b2" aria-label="Cancel">Cancel</button>
- <div class="cnt-row">
- <span>Confirm: <span class="cv" id="c0">0</span></span>
- <span>Save: <span class="cv" id="c1">0</span></span>
- <span>Cancel: <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="../focus-ring/" rel="prev" aria-label="Previous: Focus Ring 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>Focus Ring Animation</span></a><a href="../magnetic-button/" rel="next" aria-label="Next: Magnetic Button"><span><span class="hb-dir">Next: </span>Magnetic Button</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.04 · Micro-Interactions</p>
+ <h1>Button Press Scale</h1>
+ <p class="hb-lede">Shrinks as you press it and springs back as you let go. Best for main buttons.</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>Press and hold a button, then let go, or press Show me.</p></div>
+ </div>
+ <div class="stage hb-dots">
+ <button class="pbtn pbtn-primary" type="button">Confirm</button>
+ <button class="pbtn pbtn-success" type="button">Save Draft</button>
+ <button class="pbtn pbtn-ghost" type="button">Cancel</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="depth-lbl">Press depth</p>
+ <div class="seg" id="depth-seg" role="group" aria-labelledby="depth-lbl">
+ <button type="button" data-scale="0.97" aria-pressed="false">Light</button>
+ <button type="button" data-scale="0.95" class="on" aria-pressed="true">Medium</button>
+ <button type="button" data-scale="0.9" aria-pressed="false">Deep</button>
+ </div>
+ <p class="hb-hint">How much the button shrinks while held down.</p>
+ </div>
+ <div class="hb-setting">
+ <p class="hb-setting-name" id="release-lbl">Release speed</p>
+ <div class="seg" id="release-seg" role="group" aria-labelledby="release-lbl">
+ <button type="button" data-ms="300" aria-pressed="false">Slow</button>
+ <button type="button" data-ms="180" class="on" aria-pressed="true">Normal</button>
+ <button type="button" data-ms="110" aria-pressed="false">Fast</button>
+ </div>
+ <p class="hb-hint">How long it takes to spring back.</p>
+ </div>
+ <div class="hb-setting">
+ <p class="hb-setting-name" id="feel-lbl">Release feel</p>
+ <div class="seg" id="feel-seg" role="group" aria-labelledby="feel-lbl">
+ <button type="button" data-ease="cubic-bezier(.34,1.56,.64,1)" class="on" aria-pressed="true">Springy</button>
+ <button type="button" data-ease="ease-out" aria-pressed="false">Smooth</button>
+ <button type="button" data-ease="linear" aria-pressed="false">Even</button>
+ </div>
+ <p class="hb-hint">Springy goes a little past full size, then settles.</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="press-lbl">Press speed</p>
+ <div class="seg" id="press-seg" role="group" aria-labelledby="press-lbl">
+ <button type="button" data-ms="130" aria-pressed="false">Slow</button>
+ <button type="button" data-ms="80" class="on" aria-pressed="true">Normal</button>
+ <button type="button" data-ms="50" aria-pressed="false">Fast</button>
+ </div>
+ <p class="hb-hint">A press should feel instant, so keep it short.</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 press feedback to [the buttons you want to feel tactile]. While a button is held down it shrinks, as if pushed in, and when it is let go it returns to full size. A press that is quicker than the release feels most like a real button. Respond to mouse, touch and pen presses and to Space and Enter on the keyboard, and let go cleanly if a press turns into a scroll, so no button stays stuck down. Change only the button's size so nothing around it moves. If the visitor has reduced motion turned on, change the size at once, without animating it. 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">Press fast (80ms), release slow (180ms) — matches how real buttons feel. The spring easing on release makes the bounce satisfying without being cartoonish.</p>
- <div class="lbl">Press Scale</div>
- <div class="sr"><input type="range" id="scale-sl" min="85" max="99" value="95" step="1"><span class="sv" id="scale-v">0.95</span></div>
- <div class="lbl">Press Duration</div>
- <div class="sr"><input type="range" id="pdur-sl" min="30" max="200" value="80" step="10"><span class="sv" id="pdur-v">80ms</span></div>
- <div class="lbl">Release Duration</div>
- <div class="sr"><input type="range" id="rdur-sl" min="80" max="500" value="180" step="10"><span class="sv" id="rdur-v">180ms</span></div>
- <div class="lbl">Release Easing</div>
- <select id="ease-sel">
- <option value="cubic-bezier(.34,1.56,.64,1)" selected>Springy</option>
- <option value="ease-out">Ease out</option>
- <option value="cubic-bezier(.2,.7,.3,1)">Smooth</option>
- <option value="linear">Linear</option>
- </select>
- <div class="div"></div>
- <div class="kv"><span>Total presses</span><span class="v" id="total">0</span></div>
- </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>Main buttons</li><li>Icon buttons</li><li>Mobile apps</li></ul>
+ <h3>Avoid on</h3>
+ <ul class="hb-tags hb-avoid"><li>Links in text</li><li>Large cards</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('.pbtn');
- const counts=[0,0,0];
- let total=0;
+ const btns=[...document.querySelectorAll('.pbtn')];
+ const slowTog=document.getElementById('slow-tog');
+ const vars=document.documentElement.style;
+ let pd=80,rd=180,runTimers=[];
- btns.forEach((btn,i)=>{
+ // A press adds "pressed" (pointer down, or Space and Enter) and letting go removes it (pointer up, cancel, or the key coming up).
+ btns.forEach(btn=>{
const press=()=>btn.classList.add('pressed');
- const release=()=>{
- if(!btn.classList.contains('pressed'))return;
- btn.classList.remove('pressed');
- counts[i]++;total++;
- document.getElementById('c'+i).textContent=counts[i];
- document.getElementById('total').textContent=total;
- };
+ const release=()=>btn.classList.remove('pressed');
btn.addEventListener('pointerdown',e=>{press();btn.setPointerCapture(e.pointerId)});
btn.addEventListener('pointerup',release);
- btn.addEventListener('pointercancel',()=>btn.classList.remove('pressed'));
+ btn.addEventListener('pointercancel',release);
btn.addEventListener('keydown',e=>{if(e.key===' '||e.key==='Enter')press()});
btn.addEventListener('keyup',e=>{if(e.key===' '||e.key==='Enter')release()});
});
- document.getElementById('scale-sl').addEventListener('input',e=>{
- const v=(e.target.value/100).toFixed(2);
- document.getElementById('scale-v').textContent=v;
- document.documentElement.style.setProperty('--press-scale',v);
- });
- document.getElementById('pdur-sl').addEventListener('input',e=>{
- document.getElementById('pdur-v').textContent=e.target.value+'ms';
- document.documentElement.style.setProperty('--press-dur',e.target.value+'ms');
- });
- document.getElementById('rdur-sl').addEventListener('input',e=>{
- document.getElementById('rdur-v').textContent=e.target.value+'ms';
- document.documentElement.style.setProperty('--release-dur',e.target.value+'ms');
- });
- document.getElementById('ease-sel').addEventListener('change',e=>{
- document.documentElement.style.setProperty('--release-ease',e.target.value);
+ // 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=[];btns.forEach(b=>b.classList.remove('pressed'))}
+ // Button i goes down, shrinks for pd, is held 320ms and springs back for rd; the next one goes down 220ms after that.
+ document.getElementById('btn-demo').addEventListener('click',()=>{
+ stopRun();
+ btns.forEach((b,i)=>{
+ later(()=>b.classList.add('pressed'),i*(pd+rd),i*540);
+ later(()=>b.classList.remove('pressed'),i*(pd+rd)+pd,i*540+320);
+ });
});
+ // The visitor pressed, typed, scrolled or touched inside the stage: the run stops. The shared script sends this before the
+ // button's own pointerdown handler runs, so the visitor's own press still takes effect.
+ document.addEventListener('hb:input',()=>{if(running())stopRun()});
+
+ 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('depth-seg',d=>{vars.setProperty('--press-scale',d.scale)});
+ choices('release-seg',d=>{rd=+d.ms;vars.setProperty('--release-dur',rd+'ms')});
+ choices('feel-seg',d=>{vars.setProperty('--release-ease',d.ease)});
+ choices('press-seg',d=>{pd=+d.ms;vars.setProperty('--press-dur',pd+'ms')});
</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.html
index fdc87f67..f2c49d08 100644
--- a/index.html
+++ b/index.html
@@ -954,7 +954,7 @@ const CATS=[
['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','A ripple spreads out from the spot you press. Best for buttons and list items.'],
['focus-ring','Focus Ring Animation','A ring closes in around the item the Tab key reaches. Best for forms and menus.'],
- ['button-press-scale','Button Press Scale','Scales to 0.95 on press, springs back on release — asymmetric timing gives a tactile feel.'],
+ ['button-press-scale','Button Press Scale','Shrinks as you press it and springs back as you let go. Best for main buttons.'],
['magnetic-button','Magnetic Button','Button leans toward the cursor within a radius, label lagging for parallax — springs home on exit.'],
['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.'],