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.

fix: Hold to Confirm (04.36): input during Show me's last press stops the run; Show me back at rest in 4 s; the line has a subject, the prompt fits the ring, no tap highlight

matin2dd50828104c
diff --git a/README.md b/README.md
index 86e42c31..3d69f6ba 100644
--- a/README.md
+++ b/README.md
@@ -155,7 +155,7 @@ All 129 techniques, each linked to its live demo.
- **[Toast Notification](animations/04-micro-interactions/toast-notification/)** — Short messages slide into a corner, then leave on their own. Best for updates.
- **[Segmented Control](animations/04-micro-interactions/segmented-control/)** — A highlight slides to the option you pick. Best for switching views.
- **[Pull to Refresh](animations/04-micro-interactions/pull-to-refresh/)** — Pulling a list down shows a spinner, then new items. Best for feeds.
-- **[Hold to Confirm](animations/04-micro-interactions/hold-to-confirm/)** — Fills up while you hold it and acts only once it is full. Best for delete buttons.
+- **[Hold to Confirm](animations/04-micro-interactions/hold-to-confirm/)** — A button fills up while you hold it and acts only once it is full. Best for delete buttons.
- **[Expanding Search](animations/04-micro-interactions/expanding-search/)** — A search icon opens into a field you can type in, and closes when done. Best for toolbars.
- **[Button Loading States](animations/04-micro-interactions/button-loading-states/)** — The button turns into a spinner while it works, then a tick or a cross. Best for Save buttons.
diff --git a/animations/04-micro-interactions/README.md b/animations/04-micro-interactions/README.md
index 636253ea..7f3ab0b4 100644
--- a/animations/04-micro-interactions/README.md
+++ b/animations/04-micro-interactions/README.md
@@ -35,7 +35,7 @@ Short, user-triggered animations that provide feedback, confirm actions, and com
| [Toast Notification](toast-notification/) | Short messages slide into a corner, then leave on their own. Best for updates. |
| [Segmented Control](segmented-control/) | A highlight slides to the option you pick. Best for switching views. |
| [Pull to Refresh](pull-to-refresh/) | Pulling a list down shows a spinner, then new items. Best for feeds. |
-| [Hold to Confirm](hold-to-confirm/) | Fills up while you hold it and acts only once it is full. Best for delete buttons. |
+| [Hold to Confirm](hold-to-confirm/) | A button fills up while you hold it and acts only once it is full. Best for delete buttons. |
| [Expanding Search](expanding-search/) | A search icon opens into a field you can type in, and closes when done. Best for toolbars. |
| [Button Loading States](button-loading-states/) | The button turns into a spinner while it works, then a tick or a cross. Best for Save buttons. |
diff --git a/animations/04-micro-interactions/hold-to-confirm/README.md b/animations/04-micro-interactions/hold-to-confirm/README.md
index 870d1bfb..df8a02e1 100644
--- a/animations/04-micro-interactions/hold-to-confirm/README.md
+++ b/animations/04-micro-interactions/hold-to-confirm/README.md
@@ -5,7 +5,7 @@ Hold to confirm is a button that acts only after it has been held down for a mom
## When to use it
- Deleting files, projects or messages that cannot be restored
-- Closing an account or cancelling a plan
+- Closing an account or canceling a plan
- Sending money or confirming a payment on a phone
- Emergency and alert buttons that must not go off by accident
- Places where a confirm dialog would interrupt too much, but a single tap is too easy
@@ -32,7 +32,7 @@ function frame(ts) {
.ring .rf { stroke-dasharray: 1; stroke-dashoffset: 1; }
```
-Pressing and letting go come from the pointer and from the keyboard. The pointer is captured on `pointerdown`, so the press continues if the finger slides off the button, and `pointerup`, `pointercancel` and `lostpointercapture` all count as letting go. Space and Enter start a hold on `keydown` (ignoring the repeats a held key sends) and end it on `keyup` or `blur`. Letting go before the fill is full restarts a short shake animation on the button's wrapper (so it never fights the press scale on the button itself) and fades in a hint to keep holding. When the fill is full the trash icon and label crossfade to a tick and Drafts deleted, and a `role="status"` region says so; in the demo everything drains back 1.2 seconds later so it can be tried again. Under reduced motion the fill is drawn in quarters (`Math.floor(p * 4) / 4`), so it steps instead of sliding, and the shake is skipped.
+Pressing and letting go come from the pointer and from the keyboard. The pointer is captured on `pointerdown`, so the press continues if the finger slides off the button, and `pointerup`, `pointercancel` and `lostpointercapture` all count as letting go. Space and Enter start a hold on `keydown` (ignoring the repeats a held key sends) and end it on `keyup` or `blur`. Letting go before the fill is full restarts a short shake animation on the button's wrapper (so it never fights the press scale on the button itself) and fades in a hint to keep holding. When the fill is full the trash icon and label crossfade to a tick and Drafts deleted, and a `role="status"` region says so; in the demo everything drains back a second later so it can be tried again. Under reduced motion the fill is drawn in quarters (`Math.floor(p * 4) / 4`), so it steps instead of sliding, and the shake is skipped.
## Key parameters
| Parameter | Default | Effect |
diff --git a/animations/04-micro-interactions/hold-to-confirm/index.html b/animations/04-micro-interactions/hold-to-confirm/index.html
index 1210f301..c88d4d79 100644
--- a/animations/04-micro-interactions/hold-to-confirm/index.html
+++ b/animations/04-micro-interactions/hold-to-confirm/index.html
@@ -4,7 +4,7 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Hold to Confirm — Animation Handbook</title>
- <meta name="description" content="Fills up while you hold it and acts only once it is full. Best for delete buttons.">
+ <meta name="description" content="A button fills up while you hold it and acts only once it is full. Best for delete buttons.">
<link rel="canonical" href="https://matinmonshizadeh.github.io/animation-handbook/animations/04-micro-interactions/hold-to-confirm/">
<link rel="icon" type="image/png" sizes="96x96" href="../../../favicon.png">
<link rel="icon" type="image/svg+xml" href="../../../favicon.svg">
@@ -12,14 +12,14 @@
<meta property="og:type" content="article">
<meta property="og:site_name" content="Animation Handbook">
<meta property="og:title" content="Hold to Confirm — Animation Handbook">
- <meta property="og:description" content="Fills up while you hold it and acts only once it is full. Best for delete buttons.">
+ <meta property="og:description" content="A button fills up while you hold it and acts only once it is full. Best for delete buttons.">
<meta property="og:url" content="https://matinmonshizadeh.github.io/animation-handbook/animations/04-micro-interactions/hold-to-confirm/">
<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="Hold to Confirm — Animation Handbook">
- <meta name="twitter:description" content="Fills up while you hold it and acts only once it is full. Best for delete buttons.">
+ <meta name="twitter:description" content="A button fills up while you hold it and acts only once it is full. Best for delete 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": "Hold to Confirm", "name": "Hold to Confirm", "description": "Fills up while you hold it and acts only once it is full. Best for delete buttons.", "url": "https://matinmonshizadeh.github.io/animation-handbook/animations/04-micro-interactions/hold-to-confirm/", "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, Hold to Confirm"}</script>
+ <script type="application/ld+json">{"@context": "https://schema.org", "@type": "TechArticle", "headline": "Hold to Confirm", "name": "Hold to Confirm", "description": "A button fills up while you hold it and acts only once it is full. Best for delete buttons.", "url": "https://matinmonshizadeh.github.io/animation-handbook/animations/04-micro-interactions/hold-to-confirm/", "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, Hold to Confirm"}</script>
<style>
:root{--ui-accent:#ff9d5c;--ui-bg:#111114;--ui-border:rgba(255,255,255,.09);--ui-muted:#9a9aa2;--red:#c43a36;--red-dim:#2a1416;--red-edge:#6b2a2a;--ring:#ff6b63}
*,*::before,*::after{box-sizing:border-box;margin:0;padding:0}
@@ -35,7 +35,7 @@
.shaker.shake{animation:shake .4s cubic-bezier(.36,.07,.19,.97)}
@keyframes shake{20%{transform:translateX(-7px)}40%{transform:translateX(6px)}60%{transform:translateX(-4px)}80%{transform:translateX(2px)}}
/* Bar: a pill whose fill grows from the left with scaleX. touch-action and the callout rules keep a long press a press. */
- .hold{position:relative;display:flex;align-items:center;justify-content:center;gap:10px;width:100%;min-height:52px;padding:0 20px;border:1px solid var(--red-edge);border-radius:999px;background:var(--red-dim);color:#fff;font:inherit;font-size:15px;font-weight:700;cursor:pointer;overflow:hidden;touch-action:none;-webkit-user-select:none;user-select:none;-webkit-touch-callout:none;transition:transform .12s ease}
+ .hold{position:relative;display:flex;align-items:center;justify-content:center;gap:10px;width:100%;min-height:52px;padding:0 20px;border:1px solid var(--red-edge);border-radius:999px;background:var(--red-dim);color:#fff;font:inherit;font-size:15px;font-weight:700;cursor:pointer;overflow:hidden;touch-action:none;-webkit-user-select:none;user-select:none;-webkit-touch-callout:none;-webkit-tap-highlight-color:transparent;transition:transform .12s ease}
.hold.down{transform:scale(.97)}
/* The fill would cover the site's inward ring, so this button keeps its ring outside (the card leaves room for it) */
.hb-page .stage .hold:focus-visible{outline-color:#f4f4f2;outline-offset:3px}
@@ -74,7 +74,7 @@
<header class="hb-head">
<p class="hb-cat">04.36 · Micro-Interactions</p>
<h1>Hold to Confirm</h1>
- <p class="hb-lede">Fills up while you hold it and acts only once it is full. Best for delete buttons.</p>
+ <p class="hb-lede">A button fills up while you hold it and acts only once it is full. Best for delete buttons.</p>
</header>
<section class="hb-step hb-watch" aria-labelledby="hb-watch-title">
@@ -157,7 +157,7 @@
<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 hold to confirm to [the button for a risky action, such as Delete]. While the visitor holds it down, a fill grows steadily, and the action runs only once it is full, when a tick shows. If they let go early, the fill drains back, nothing happens and a short hint says to keep holding; when the settings ask for it, the button also shakes. Holding Space or Enter works the same way, and on touch a long press must not open the browser's menu. Grow the fill with a transform by elapsed time, and announce the result to screen readers. If the visitor has reduced motion turned on, fill in a few steps without the shake. Match the settings listed below.</p>
+ <p class="hb-prompt">Add hold to confirm to [the button for a risky action, such as Delete]. While the visitor holds it down, a fill grows steadily, and the action runs only once it is full, when a tick shows. If they let go early, the fill drains back, nothing happens and a short hint says to keep holding; when the settings ask for it, the button also shakes. Holding Space or Enter works the same way, and on touch a long press must not open the browser's menu. Grow the fill smoothly by the time held, not per frame, and announce the result to screen readers. If the visitor has reduced motion turned on, fill in a few steps without the shake. 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>
@@ -234,12 +234,12 @@
run();
}
shaker.addEventListener('animationend',()=>shaker.classList.remove('shake'));
- // Full: the press is used up (letting go now changes nothing), the tick shows and the file fades; 1.2 s later it all drains back.
+ // Full: the press is used up (letting go now changes nothing), the tick shows and the file fades; a second later it all drains back.
function full(){
holding=false;done=true;
hold.classList.remove('down');hold.classList.add('done');card.classList.add('gone');
if(byVisitor)statusEl.textContent='Old drafts deleted.';
- doneTimer=setTimeout(()=>{done=false;hold.classList.remove('done');card.classList.remove('gone');statusEl.textContent='';run()},1200);
+ doneTimer=setTimeout(()=>{done=false;hold.classList.remove('done');card.classList.remove('gone');statusEl.textContent='';run()},1000);
}
hold.addEventListener('pointerdown',e=>{
@@ -272,18 +272,18 @@
easing.forEach(el=>{el.style.transition=''});
}
// A press let go at 30% of How long to hold (the drain, the hint and the shake), then a press held until it is full. At the defaults
- // the tick shows at 2.7 s and the button is empty again at 4.3 s. The arrival press leaves a visitor's own hold alone.
+ // the tick shows at 2.6 s and the button is empty again at 4 s. The arrival press leaves a visitor's own hold alone.
$('btn-demo').addEventListener('click',e=>{
if(!e.isTrusted&&(holding||done||p>0))return;
stopRun();toRest();
const early=.3*holdMs;
later(()=>press(false),150);
later(release,150+early);
- later(()=>press(false),750+early);
+ later(()=>press(false),600+early);
});
- // The visitor pressed, typed, scrolled or touched inside the stage: the run stops. The shared script sends this before the button's
- // own pointerdown, so a press on the button takes over the fill where it is.
- document.addEventListener('hb:input',()=>{if(running())stopRun()});
+ // The visitor pressed, typed, scrolled or touched inside the stage: the run stops, also while its last press is held (no timer is left
+ // then). This comes before the button's own pointerdown, so a press on the button takes over the fill where it is.
+ document.addEventListener('hb:input',()=>{if(running()||(holding&&!byVisitor))stopRun()});
function choices(id,pick){
const buttons=document.querySelectorAll('#'+id+' button');
diff --git a/index.html b/index.html
index 406e570a..3651ba9a 100644
--- a/index.html
+++ b/index.html
@@ -1244,7 +1244,7 @@ const CATS=[
['toast-notification','Toast Notification','Short messages slide into a corner, then leave on their own. Best for updates.'],
['segmented-control','Segmented Control','A highlight slides to the option you pick. Best for switching views.'],
['pull-to-refresh','Pull to Refresh','Pulling a list down shows a spinner, then new items. Best for feeds.'],
- ['hold-to-confirm','Hold to Confirm','Fills up while you hold it and acts only once it is full. Best for delete buttons.'],
+ ['hold-to-confirm','Hold to Confirm','A button fills up while you hold it and acts only once it is full. Best for delete buttons.'],
['expanding-search','Expanding Search','A search icon opens into a field you can type in, and closes when done. Best for toolbars.'],
['button-loading-states','Button Loading States','The button turns into a spinner while it works, then a tick or a cross. Best for Save buttons.'],
]