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: Hold to Confirm (04.36)
matin35436a30f511
diff --git a/README.md b/README.mdindex 60328023..cfb2a241 100644--- a/README.md+++ b/README.md@@ -155,6 +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.</details>diff --git a/animations/04-micro-interactions/README.md b/animations/04-micro-interactions/README.mdindex d2320f7e..058a265d 100644--- a/animations/04-micro-interactions/README.md+++ b/animations/04-micro-interactions/README.md@@ -35,6 +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. |## Key conceptsdiff --git a/animations/04-micro-interactions/hold-to-confirm/README.md b/animations/04-micro-interactions/hold-to-confirm/README.mdnew file mode 100644index 00000000..870d1bfb--- /dev/null+++ b/animations/04-micro-interactions/hold-to-confirm/README.md@@ -0,0 +1,58 @@+# Hold to Confirm++## What it is+Hold to confirm is a button that acts only after it has been held down for a moment. While it is held, a fill grows across it or around it; when the fill is full, the action runs and a tick shows. Letting go early drains the fill and nothing happens, so a stray tap or click can never delete anything.++## When to use it+- Deleting files, projects or messages that cannot be restored+- Closing an account or cancelling 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++## How it works+One number, `p`, says how full the button is, from 0 to 1. A frame loop moves it by the time that has passed: up while the button is held, down while it is not. The same number drives both looks, so the Fill style setting only changes which one is shown:++```js+let p = 0, holding = false, last = null;+function frame(ts) {+ const dt = last === null ? 0 : Math.min(ts - last, 50); // elapsed time: 60 Hz and 120 Hz screens fill alike+ last = ts;+ p = holding ? Math.min(1, p + dt / holdMs) : Math.max(0, p - dt / drainMs);+ fill.style.transform = `scaleX(${p})`; // Bar: grows from the left edge+ ring.style.strokeDashoffset = 1 - p; // Ring: a <circle pathLength="1">, turned -90deg to start at the top+ if (p >= 1) return confirm(); // the press is used up; letting go now changes nothing+ if (holding || p > 0) requestAnimationFrame(frame);+}+```++```css+.hold { position: relative; overflow: hidden; touch-action: none; user-select: none; -webkit-touch-callout: none; }+.fill { position: absolute; inset: 0; transform: scaleX(0); transform-origin: left center; }+.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.++## Key parameters+| Parameter | Default | Effect |+|-----------|---------|--------|+| How long to hold | Medium | How long the button must be held before it acts: short is 0.8 seconds, medium 1.5 and long 2.5; under about half a second it no longer guards against a stray tap, over three seconds it feels stuck |+| Fill style | Bar | Bar fills the whole button from left to right; Ring fills a ring around a round button, clockwise from the top |+| Shakes if let go early | On | A short side-to-side shake when the button is let go before it is full; the hint to keep holding shows either way |+| How fast it drains | Quickly | How long a full fill takes to run back out when it is let go: quickly is 0.4 seconds, slowly 1.5 |++## Production notes+- **Offer a second way**: some people cannot hold a press steadily, and some assistive technology sends a click with no press at all. Keep another path to the same action, such as a confirm dialog or an undo, and say in the button's label or description that it needs a press and hold.+- **Keyboard**: a held key repeats `keydown`, so ignore events with `e.repeat`, and treat `keyup` and `blur` as letting go, or Tab pressed during a hold leaves the button filling with nothing held.+- **Touch**: `touch-action: none` stops the browser from turning a finger that drifts a little into a scroll, which would cancel the pointer. `-webkit-touch-callout: none`, `user-select: none` and a `contextmenu` handler that calls `preventDefault()` keep a long press from opening the callout, selecting text or showing the menu. Always listen for `pointercancel`.+- **Time, not frames**: move the fill by elapsed time. A loop that adds a fixed amount each frame fills twice as fast on a 120 Hz screen and half as fast on a phone that drops to 30 Hz.+- **Say what happened**: announce the result in a `role="status"` live region ("Old drafts deleted"), and the early let-go too, since the hint and the shake are visual.+- **GSAP**: `const t = gsap.to(fill, { scaleX: 1, duration: 1.5, ease: "none", paused: true, onComplete: confirm })`, then `t.timeScale(1).play()` on press and `t.timeScale(4).reverse()` on release.+- **Framer Motion**: with `useAnimate()`, call `animate(fill, { scaleX: 1 }, { duration: 1.5, ease: "linear" })` on press and keep its controls; on release stop them and animate `scaleX` back to 0, and run the action in the first animation's `.then()` only if it was not stopped.++## See also+- [Button Press Scale](../button-press-scale/) — the button shrinks while it is pressed+- [Progress Animation](../progress-animation/) — bars and rings that fill to show progress+- [Error Shake](../error-shake/) — a shake that says the input was wrong+- [Checkmark Draw](../checkmark-draw/) — a tick that draws itself once a task is donediff --git a/animations/04-micro-interactions/hold-to-confirm/index.html b/animations/04-micro-interactions/hold-to-confirm/index.htmlnew file mode 100644index 00000000..b94554dd--- /dev/null+++ b/animations/04-micro-interactions/hold-to-confirm/index.html@@ -0,0 +1,300 @@+<!DOCTYPE html>+<html lang="en">+<head>+ <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.">+ <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">+ <link rel="apple-touch-icon" href="../../../apple-touch-icon.png">+ <meta property="og:type" content="article">+ <meta property="og:site_name" content="Animation Handbook">+ <meta property="og:title" content="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: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: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>+ <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}+ .stage{display:flex;align-items:center;justify-content:center;padding:16px;background:#0b0b0d}+ .card{width:100%;max-width:320px;display:flex;flex-direction:column;gap:18px;padding:20px;border:1px solid var(--ui-border);border-radius:12px;background:var(--ui-bg)}+ .file{display:flex;align-items:center;gap:12px;transition:opacity .3s}+ .file svg{flex:none;width:40px;height:40px;padding:9px;border-radius:8px;background:#1c1c21;fill:none;stroke:#adadb2;stroke-width:2;stroke-linecap:round;stroke-linejoin:round}+ .name{font-size:15px;font-weight:700}+ .meta{margin-top:2px;font-size:13px;color:var(--ui-muted)}+ .card.gone .file{opacity:.35}+ /* Let go early: the button gives a short shake (on its wrapper, so it never fights the press scale) */+ .shaker{display:flex;justify-content:center}+ .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.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}+ .fill{position:absolute;inset:0;background:var(--red);transform:scaleX(0);transform-origin:left center}+ .dial{position:relative;display:grid;place-items:center;width:20px;height:20px;transition:transform .12s ease}+ .ic{grid-area:1/1;width:20px;height:20px;fill:none;stroke:currentColor;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;transition:opacity .2s,transform .2s}+ .words{position:relative;display:grid}+ .words span{grid-area:1/1;white-space:nowrap;transition:opacity .2s}+ .w-done{opacity:0}.tick{opacity:0;transform:scale(.5)}+ .hold.done .trash,.hold.done .w-hold{opacity:0}+ .hold.done .tick,.hold.done .w-done{opacity:1;transform:none}+ /* Ring: a round dial beside the words, and a ring around it that fills clockwise from the top */+ .ring,.ring-mode .fill{display:none}+ .ring-mode .hold{width:auto;gap:14px;padding:0 8px 0 0;border:0;background:none;overflow:visible}+ .ring-mode .hold.down{transform:none}+ .ring-mode .hold.down .dial{transform:scale(.94)}+ .ring-mode .dial{width:64px;height:64px;border-radius:50%;background:var(--red-dim)}+ .ring-mode .ring{display:block;position:absolute;inset:0;width:100%;height:100%;transform:rotate(-90deg)}+ .ring circle{fill:none;stroke-width:4}+ .ring .rt{stroke:var(--red-edge)}+ .ring .rf{stroke:var(--ring);stroke-dasharray:1;stroke-dashoffset:1}+ .tip{font-size:13px;line-height:1.4;color:var(--ui-muted);text-align:center;opacity:0;transition:opacity .2s}+ .tip.on{opacity:1}+ .sr-only{position:absolute;width:1px;height:1px;overflow:hidden;clip-path:inset(50%);white-space:nowrap}+ @media(prefers-reduced-motion:reduce){.file,.hold,.dial,.ic,.words span,.tip{transition:none!important}.shaker.shake{animation:none}}+ </style>+ <link rel="stylesheet" href="../../../assets/css/demo-page.css?v=6">+ <script src="../../../assets/js/demo-page.js?v=6" defer></script>+</head>+<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="../pull-to-refresh/" rel="prev" aria-label="Previous: Pull to Refresh"><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>Pull to Refresh</span></a></span>+</nav>+<main class="hb-page">+ <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>+ </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 the button until it fills (or hold Space or Enter on it), or press Show me.</p></div>+ </div>+ <div class="stage hb-dots">+ <div class="card" id="card">+ <div class="file">+ <svg viewBox="0 0 24 24" aria-hidden="true"><path d="M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z"/></svg>+ <div><p class="name">Old drafts</p><p class="meta">12 files · 48 MB</p></div>+ </div>+ <div class="shaker" id="shaker">+ <button class="hold" id="hold" type="button">+ <span class="fill" id="fill" aria-hidden="true"></span>+ <span class="dial" aria-hidden="true">+ <svg class="ring" viewBox="0 0 64 64"><circle class="rt" cx="32" cy="32" r="30"/><circle class="rf" id="rf" cx="32" cy="32" r="30" pathLength="1"/></svg>+ <svg class="ic trash" viewBox="0 0 24 24"><path d="M3 6h18"/><path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6"/><path d="M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"/></svg>+ <svg class="ic tick" viewBox="0 0 24 24"><path d="M20 6 9 17l-5-5"/></svg>+ </span>+ <span class="words"><span class="w-hold">Hold to delete</span><span class="w-done" aria-hidden="true">Drafts deleted</span></span>+ </button>+ </div>+ <p class="tip" id="tip" aria-hidden="true">Keep holding until it fills</p>+ </div>+ <p class="sr-only" id="status" role="status" aria-live="polite"></p>+ </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>+ </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="time-lbl">How long to hold</p>+ <div class="seg" id="time-seg" role="group" aria-labelledby="time-lbl">+ <button type="button" data-ms="800" aria-pressed="false">Short</button>+ <button type="button" data-ms="1500" class="on" aria-pressed="true">Medium</button>+ <button type="button" data-ms="2500" aria-pressed="false">Long</button>+ </div>+ <p class="hb-hint">How long the button must be held before it acts.</p>+ </div>+ <div class="hb-setting">+ <p class="hb-setting-name" id="style-lbl">Fill style</p>+ <div class="seg" id="style-seg" role="group" aria-labelledby="style-lbl">+ <button type="button" data-s="bar" class="on" aria-pressed="true">Bar</button>+ <button type="button" data-s="ring" aria-pressed="false">Ring</button>+ </div>+ <p class="hb-hint">A bar fills the button; a ring fills around a round button.</p>+ </div>+ <div class="hb-setting">+ <label class="hb-switch-row"><span>Shakes if let go early</span><input class="hb-switch" type="checkbox" role="switch" id="shake-tog" checked autocomplete="off"></label>+ <p class="hb-hint">A small shake says the hold was too short.</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="drain-lbl">How fast it drains</p>+ <div class="seg" id="drain-seg" role="group" aria-labelledby="drain-lbl">+ <button type="button" data-ms="400" class="on" aria-pressed="true">Quickly</button>+ <button type="button" data-ms="1500" aria-pressed="false">Slowly</button>+ </div>+ <p class="hb-hint">How the fill runs back out when you let go early.</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 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>+ <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>Delete buttons</li><li>Closing an account</li><li>Sending money</li><li>Emergency alerts</li></ul>+ <h3>Avoid on</h3>+ <ul class="hb-tags hb-avoid"><li>Everyday actions</li><li>Actions with Undo</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 $=id=>document.getElementById(id);+ const stage=document.querySelector('.stage'),card=$('card'),hold=$('hold'),fill=$('fill'),rf=$('rf'),tip=$('tip'),shaker=$('shaker'),statusEl=$('status'),shakeTog=$('shake-tog');+ const reduceMq=matchMedia('(prefers-reduced-motion:reduce)');+ // Everything that eases between two looks; toRest() switches these transitions off for a moment+ const easing=[hold,tip,card.querySelector('.file'),...hold.querySelectorAll('.dial,.ic,.words span')];+ let holdMs=1500,drainMs=400,p=0,holding=false,done=false,byVisitor=false,raf=0,lastT=null,doneTimer=0,tipTimer=0,runTimers=[];++ // p is how full it is (0 to 1). Under reduced motion the fill shows it in quarters, so it steps instead of sliding.+ function draw(){+ const v=reduceMq.matches?Math.floor(p*4+1e-9)/4:p;+ fill.style.transform='scaleX('+v+')';+ rf.style.strokeDashoffset=String(1-v);+ }+ // One frame: held, it fills by the time passed over How long to hold; let go, it drains by the time passed over How fast it drains.+ function frame(ts){+ const dt=lastT===null?0:Math.min(ts-lastT,50);+ lastT=ts;+ if(holding){p=Math.min(1,p+dt/holdMs);if(p>=1)full()}+ else p=Math.max(0,p-dt/drainMs);+ draw();+ raf=holding||(!done&&p>0)?requestAnimationFrame(frame):0;+ }+ function run(){if(!raf){lastT=null;raf=requestAnimationFrame(frame)}}+ document.addEventListener('visibilitychange',()=>{lastT=null});++ // A press starts filling (a confirmed button ignores presses until it is back). byVisitor keeps Show me's run quiet for screen readers.+ function press(visitor){+ if(done)return;+ byVisitor=visitor;holding=true;+ hold.classList.add('down');+ clearTimeout(tipTimer);tip.classList.remove('on');statusEl.textContent='';+ run();+ }+ // Letting go before it is full: the fill drains, the hint shows, and the button shakes if Shakes if let go early is on.+ function release(){+ if(!holding)return;+ holding=false;+ hold.classList.remove('down');+ if(shakeTog.checked&&!reduceMq.matches){shaker.classList.remove('shake');void shaker.offsetWidth;shaker.classList.add('shake')}+ tip.classList.add('on');+ clearTimeout(tipTimer);tipTimer=setTimeout(()=>tip.classList.remove('on'),1600);+ if(byVisitor)statusEl.textContent='Not deleted. Keep holding until it fills.';+ 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.+ 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);+ }++ hold.addEventListener('pointerdown',e=>{+ if(e.pointerType==='mouse'&&e.button!==0)return;+ try{hold.setPointerCapture(e.pointerId)}catch(_){}+ press(true);+ });+ ['pointerup','pointercancel','lostpointercapture','blur'].forEach(t=>hold.addEventListener(t,release));+ hold.addEventListener('keydown',e=>{if(e.key===' '||e.key==='Enter'){e.preventDefault();if(!e.repeat)press(true)}});+ hold.addEventListener('keyup',e=>{if(e.key===' '||e.key==='Enter')release()});+ hold.addEventListener('contextmenu',e=>e.preventDefault());++ // Show me: one run at a time. Every timer of the run goes through later(); stopRun() cancels the whole run and lets go of its+ // press without the shake or the hint. This page has no Slow motion: How long to hold already sets the pace.+ function later(fn,ms){const id=setTimeout(()=>{runTimers=runTimers.filter(t=>t!==id);fn()},ms);runTimers.push(id)}+ function running(){return runTimers.length>0}+ function stopRun(){+ runTimers.forEach(clearTimeout);runTimers=[];+ if(holding&&!byVisitor){holding=false;hold.classList.remove('down');run()}+ }+ // A run starts from an empty, unconfirmed button, put there without animating: the transitions are turned off, the state is+ // cleared, a reflow makes it stick, and the transitions come back.+ function toRest(){+ cancelAnimationFrame(raf);raf=0;clearTimeout(doneTimer);clearTimeout(tipTimer);+ holding=done=false;p=0;+ easing.forEach(el=>{el.style.transition='none'});+ hold.classList.remove('down','done');card.classList.remove('gone');tip.classList.remove('on');shaker.classList.remove('shake');+ statusEl.textContent='';draw();+ void hold.offsetWidth;+ 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.+ $('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);+ });+ // 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()});++ 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('time-seg',d=>{holdMs=+d.ms});+ choices('style-seg',d=>{stage.classList.toggle('ring-mode',d.s==='ring')});+ choices('drain-seg',d=>{drainMs=+d.ms});+</script>+</body>+</html>diff --git a/index.html b/index.htmlindex e2d7eb15..4d8cc457 100644--- a/index.html+++ b/index.html@@ -674,6 +674,17 @@ button,input{font:inherit;color:inherit}.pv-cursor .foll{position:absolute;width:12%;aspect-ratio:1;border-radius:50%;background:color-mix(in srgb,var(--accent) 40%,transparent);border:1px solid var(--accent);animation:m-foll 4s ease-in-out infinite}@keyframes m-tgt{0%{left:20%;top:30%}25%{left:70%;top:24%}50%{left:74%;top:64%}75%{left:24%;top:68%}100%{left:20%;top:30%}}@keyframes m-foll{0%{left:20%;top:30%}29%{left:70%;top:24%}54%{left:74%;top:64%}79%{left:24%;top:68%}100%{left:20%;top:30%}}+/* hold to confirm: the button is held down, a red fill grows across it, then it reads Deleted and empties again */+.pv-holdconf{background:#08090c;display:grid;place-items:center}+.pv-holdconf .btn{position:relative;display:grid;place-items:center;width:78%;max-width:200px;height:24%;border-radius:999px;overflow:hidden;background:#2a1416;border:1px solid #6b2a2a;animation:hc-btn 3.6s var(--ease) infinite}+.pv-holdconf .fl{position:absolute;inset:0;background:#c43a36;transform-origin:left;animation:hc-fill 3.6s linear infinite}+.pv-holdconf .t{position:relative;grid-area:1/1;font-family:var(--text);font-size:9px;font-weight:700;letter-spacing:.04em;color:#fff;white-space:nowrap}+.pv-holdconf .t1{animation:hc-t1 3.6s steps(1,end) infinite}+.pv-holdconf .t2{opacity:0;animation:hc-t2 3.6s steps(1,end) infinite}+@keyframes hc-btn{0%,8%{transform:scale(1)}11%,56%{transform:scale(.95)}62%,100%{transform:scale(1)}}+@keyframes hc-fill{0%,8%{transform:scaleX(0);opacity:1}58%,86%{transform:scaleX(1);opacity:1}96%{transform:scaleX(1);opacity:0}100%{transform:scaleX(0);opacity:0}}+@keyframes hc-t1{0%{opacity:1}58%{opacity:0}92%,100%{opacity:1}}+@keyframes hc-t2{0%{opacity:0}58%{opacity:1}92%,100%{opacity:0}}/* ── bespoke: 05 Text & Typography ── */.pv-kinetic{background:#0c0608;display:grid;place-items:center;overflow:hidden}@@ -1007,7 +1018,7 @@ button,input{font:inherit;color:inherit}<section class="wrap home-hero" aria-labelledby="hero-title"><span class="float fl1" aria-hidden="true"></span><span class="float fl2" aria-hidden="true"></span><span class="float fl3" aria-hidden="true"></span><span class="float fl4" aria-hidden="true"></span><span class="float fl5" aria-hidden="true"></span><span class="float fl6" aria-hidden="true"></span>- <p class="pill"><span class="pill-dot" aria-hidden="true"></span>129 free animations · no coding needed</p>+ <p class="pill"><span class="pill-dot" aria-hidden="true"></span>130 free animations · no coding needed</p><h1 class="h1" id="hero-title">What do you want to animate?</h1><p class="sub">Pick a place, or describe it in your own words. Every animation plays live, and each one comes with a ready-made prompt for your AI assistant.</p><form class="search" id="search-form" role="search" action="./" method="get">@@ -1064,8 +1075,8 @@ button,input{font:inherit;color:inherit}<p class="empty-s">Try a simpler word, or pick one of these:</p><p class="pop"><button type="button" data-q="fade in">fade in</button><button type="button" data-q="typing text">typing text</button><button type="button" data-q="loading spinner">loading spinner</button><button type="button" data-q="parallax">parallax</button><button type="button" data-q="confetti">confetti</button></p></div>- <div class="more" id="more"><button type="button" class="bigbtn" id="more-btn"><span id="more-label">Browse all 129 animations</span><svg class="i" viewBox="0 0 24 24" aria-hidden="true"><path d="M12 5v14M6 13l6 6 6-6"/></svg></button></div>- <noscript><p class="noscript">This page shows its animations with JavaScript. All 129 are still easy to reach: see the <a href="https://github.com/matinmonshizadeh/animation-handbook#categories">category list on GitHub</a> or the <a href="sitemap.xml">full sitemap</a>. Each demo is a page of its own under <code>/animations/<category>/<name>/</code>.</p></noscript>+ <div class="more" id="more"><button type="button" class="bigbtn" id="more-btn"><span id="more-label">Browse all 130 animations</span><svg class="i" viewBox="0 0 24 24" aria-hidden="true"><path d="M12 5v14M6 13l6 6 6-6"/></svg></button></div>+ <noscript><p class="noscript">This page shows its animations with JavaScript. All 130 are still easy to reach: see the <a href="https://github.com/matinmonshizadeh/animation-handbook#categories">category list on GitHub</a> or the <a href="sitemap.xml">full sitemap</a>. Each demo is a page of its own under <code>/animations/<category>/<name>/</code>.</p></noscript></section><section class="how" id="how" aria-labelledby="how-title">@@ -1083,7 +1094,7 @@ button,input{font:inherit;color:inherit}<footer class="wrap foot"><a class="brand" href="./"><svg class="mark" viewBox="0 0 32 32" aria-hidden="true"><circle class="ring" cx="11.16" cy="20.84" r="6.1"/><circle class="ring" cx="15.12" cy="16.88" r="6.1"/><circle class="ring" cx="18.51" cy="13.49" r="6.1"/><circle class="ball" cx="21.2" cy="10.8" r="6.6"/></svg><span>Animation Handbook</span></a>- <p class="foot-t">129 web animations with live demos and copyable prompts.</p>+ <p class="foot-t">130 web animations with live demos and copyable prompts.</p><nav class="nav" aria-label="Footer"><a class="lnk" href="https://github.com/matinmonshizadeh/animation-handbook" target="_blank" rel="noopener noreferrer">GitHub</a><a class="lnk" href="#top">Back to top</a></nav></footer><div class="toast" id="toast" role="status" aria-live="polite"><span class="ok" aria-hidden="true"><svg class="i" viewBox="0 0 24 24"><path d="M5 12.5l4.5 4.5L19 7.5"/></svg></span><span class="toast-t"></span></div>@@ -1205,6 +1216,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.'],]},{@@ -1284,6 +1296,7 @@ const PV={'svg-line-draw':'linedraw','scrollspy-nav':'spy','scroll-background-color':'bgblend','hamburger-menu-toggle':'hamb','theme-toggle-morph':'thememorph','copy-to-clipboard':'copyfx','star-rating':'stars','toast-notification':'toast','segmented-control':'segct','pull-to-refresh':'pullref',+ 'hold-to-confirm':'holdconf','flip-card-3d':'flip3d','matrix-rain':'matrix','plasma':'plasmapv','parallax-depth-of-field':'dof','parallax-scrolling':'plx','reverse-scrolling-columns':'revcol','cover-card-to-fixed-header':'cover','fly-in-fly-out-contact-list':'flylist','stacking-cards':'stack',@@ -1405,6 +1418,7 @@ const PLACES={'toast-notification':['load'],'segmented-control':['menu','btn'],'pull-to-refresh':['load'],+ 'hold-to-confirm':['btn'],// 05'kinetic-typography':['text','intro'],'typewriter-effect':['text','intro'],@@ -1467,6 +1481,7 @@ function pvMarkup(k){case 'sig2': return '<span class="s2 anim"></span>';case 'sig3': return '<span class="s3 pa anim"></span><span class="s3 pb anim"></span>';case 'sig4': return '<span class="s4r anim"></span><span class="s4r r2 anim"></span><span class="s4r r3 anim"></span><span class="s4d"></span>';+ case 'holdconf': return '<span class="btn anim"><span class="fl anim"></span><span class="t t1 anim">HOLD TO DELETE</span><span class="t t2 anim">✓ DELETED</span></span>';case 'sig5': return '<span class="s5 anim"></span><span class="s5 anim"></span><span class="s5 anim"></span>';case 'sig6': return '<div class="cube anim"><span class="face f1"></span><span class="face f2"></span><span class="face f3"></span><span class="face f4"></span><span class="face f5"></span><span class="face f6"></span></div>';case 'sig7': return '<span class="s7 anim"></span>';diff --git a/sitemap.xml b/sitemap.xmlindex 23cc35d9..7ab615a8 100644--- a/sitemap.xml+++ b/sitemap.xml@@ -81,6 +81,7 @@<url><loc>https://matinmonshizadeh.github.io/animation-handbook/animations/04-micro-interactions/toast-notification/</loc><lastmod>2026-07-14</lastmod><changefreq>monthly</changefreq><priority>0.7</priority></url><url><loc>https://matinmonshizadeh.github.io/animation-handbook/animations/04-micro-interactions/segmented-control/</loc><lastmod>2026-07-14</lastmod><changefreq>monthly</changefreq><priority>0.7</priority></url><url><loc>https://matinmonshizadeh.github.io/animation-handbook/animations/04-micro-interactions/pull-to-refresh/</loc><lastmod>2026-07-14</lastmod><changefreq>monthly</changefreq><priority>0.7</priority></url>+ <url><loc>https://matinmonshizadeh.github.io/animation-handbook/animations/04-micro-interactions/hold-to-confirm/</loc><lastmod>2026-10-01</lastmod><changefreq>monthly</changefreq><priority>0.7</priority></url><url><loc>https://matinmonshizadeh.github.io/animation-handbook/animations/05-text-typography/kinetic-typography/</loc><lastmod>2026-07-14</lastmod><changefreq>monthly</changefreq><priority>0.7</priority></url><url><loc>https://matinmonshizadeh.github.io/animation-handbook/animations/05-text-typography/typewriter-effect/</loc><lastmod>2026-07-14</lastmod><changefreq>monthly</changefreq><priority>0.7</priority></url><url><loc>https://matinmonshizadeh.github.io/animation-handbook/animations/05-text-typography/scramble-text/</loc><lastmod>2026-07-14</lastmod><changefreq>monthly</changefreq><priority>0.7</priority></url>