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 Checkmark Draw to the guided-steps page

matin9fabec19d0ea
diff --git a/animations/04-micro-interactions/checkmark-draw/README.md b/animations/04-micro-interactions/checkmark-draw/README.md
index 747463a3..e76402a8 100644
--- a/animations/04-micro-interactions/checkmark-draw/README.md
+++ b/animations/04-micro-interactions/checkmark-draw/README.md
@@ -1,7 +1,7 @@
# Checkmark Draw
## What it is
-The checkmark draw animates an SVG path progressively from one end to the other, giving the impression of something being hand-drawn. It uses the `stroke-dashoffset` technique: the path is pre-drawn but hidden behind a full-length dash gap, then the gap shrinks to zero over time, revealing the stroke. Most commonly used as a success confirmation after form submission or payment.
+A check mark that draws itself, as if by hand, to confirm that something worked. The circle and the tick are there from the start but hidden, and they are revealed along their length, so the line seems to be drawn. The same trick can draw a red X when something fails.
## When to use it
- Form submission success state (the button transforms into a checkmark)
@@ -22,22 +22,22 @@ Every SVG path has a `getTotalLength()` value — the pixel length of its stroke
```css
.check-circle {
fill: none; stroke: #56d364; stroke-width: 4;
- stroke-dasharray: 188; /* 2π × 30 */
- stroke-dashoffset: 188;
+ stroke-dasharray: 189; /* 2π × 30, rounded up */
+ stroke-dashoffset: 189;
transition: stroke-dashoffset 500ms ease-out;
}
.check-mark {
fill: none; stroke: #56d364; stroke-width: 4; stroke-linecap: round; stroke-linejoin: round;
stroke-dasharray: 52;
stroke-dashoffset: 52;
- transition: stroke-dashoffset 500ms ease-out 200ms; /* delay after circle */
+ transition: stroke-dashoffset 500ms ease-out;
}
.drawn .check-circle { stroke-dashoffset: 0; }
-.drawn .check-mark { stroke-dashoffset: 0; }
+.drawn .check-mark { stroke-dashoffset: 0; transition-delay: 200ms; } /* delay after circle */
```
-The circle draws first (0ms delay), the checkmark follows with a `200ms` delay — creating the sequenced "circle then tick" effect.
+The circle draws first (0ms delay), the checkmark follows with a `200ms` delay — creating the sequenced "circle then tick" effect. The delay sits on the `.drawn` rule, so it applies only while drawing in; when the class is removed, both lines draw back out together. The demo sets the delay to 0.4 times the draw time, so it follows the Speed setting.
For paths that aren't simple geometry, measure length in JavaScript:
@@ -53,20 +53,21 @@ path.style.strokeDashoffset = 0;
## Key parameters
| Parameter | Default | Effect |
|-----------|---------|--------|
-| Duration | 500ms | 200–800ms is the legible range; faster feels technical, slower feels dramatic |
-| Easing | ease-out | Decelerating draw mimics natural handwriting — fast start, slow finish |
-| Stroke width | 4px | Thicker reads as confident; thinner reads as precise |
-| Delay between paths | 200ms | Sequence circle → mark; simultaneous is also valid but less theatrical |
+| Result | Success | Success draws a circle and a tick and turns the button green; Error draws a red X, shakes it and turns the button red |
+| Speed | Normal | How long each line takes to draw: slow is 800ms, normal 500ms and fast 300ms; 200 to 800ms is easy to follow |
+| Line thickness | Medium | Thin is 2, medium 4 and thick 7 units wide; thick reads as confident, thin as precise |
+| Feel | Smooth | Smooth slows at the end like a pen lifting off; Gentle eases in and out; Even draws at one steady pace |
+| Tick color | Green | The color of the circle and the tick; the X stays red |
## Production notes
- **Path length must match `stroke-dasharray`**: if the length is wrong, the path draws partially or overshoots. For computed paths, always use `getTotalLength()` rather than hardcoding.
- **`stroke-dasharray` on `<polyline>`**: polylines report `getTotalLength()` correctly in all major browsers. Use it for checkmarks; `<path d="M 24,41 L 35,52 L 56,30">` is equivalent.
-- **Error state pairing**: the same technique draws an X for failure. Two crossing `<line>` elements with staggered delays produce a cross-draw effect (see toggle in the demo).
+- **Error state pairing**: the same technique draws an X for failure. Two crossing `<line>` elements with staggered delays produce a cross-draw effect (the demo's Result setting shows it).
- **Shake on error**: after drawing the X, `animation: shake 400ms ease` on the container reinforces the rejection.
- **GSAP**: `gsap.to(path, { strokeDashoffset: 0, duration: 0.5, ease: "power2.out" })`. The DrawSVG plugin is more convenient for complex paths.
- **Framer Motion**: `<motion.path initial={{ pathLength: 0 }} animate={{ pathLength: 1 }} transition={{ duration: 0.5 }} />` — `pathLength` is a 0–1 shorthand for the dashoffset technique.
## See also
-- [Progress Animation](../progress-animation/) — the predecessor state before success
-- [Loading Spinner](../loading-spinner/) — the loading state that transitions to a checkmark
-- [Button Press Scale](../button-press-scale/) — press feedback before the async operation starts
+- [Progress Animation](../progress-animation/) — shows how much is done before the success
+- [Loading Spinner](../loading-spinner/) — the waiting sign before the tick
+- [Button Press Scale](../button-press-scale/) — the button shrinks while it is pressed
diff --git a/animations/04-micro-interactions/checkmark-draw/index.html b/animations/04-micro-interactions/checkmark-draw/index.html
index e2aac1d6..5643de99 100644
--- a/animations/04-micro-interactions/checkmark-draw/index.html
+++ b/animations/04-micro-interactions/checkmark-draw/index.html
@@ -4,7 +4,7 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Checkmark Draw — Animation Handbook</title>
- <meta name="description" content="SVG path draws progressively on success — stroke-dashoffset animates from full length to zero.">
+ <meta name="description" content="A tick draws itself in a circle once a task succeeds. Best for forms.">
<link rel="canonical" href="https://matinmonshizadeh.github.io/animation-handbook/animations/04-micro-interactions/checkmark-draw/">
<link rel="icon" type="image/png" sizes="96x96" href="../../../favicon.png">
<link rel="icon" type="image/svg+xml" href="../../../favicon.svg">
@@ -12,33 +12,28 @@
<meta property="og:type" content="article">
<meta property="og:site_name" content="Animation Handbook">
<meta property="og:title" content="Checkmark Draw — Animation Handbook">
- <meta property="og:description" content="SVG path draws progressively on success — stroke-dashoffset animates from full length to zero.">
+ <meta property="og:description" content="A tick draws itself in a circle once a task succeeds. Best for forms.">
<meta property="og:url" content="https://matinmonshizadeh.github.io/animation-handbook/animations/04-micro-interactions/checkmark-draw/">
<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="Checkmark Draw — Animation Handbook">
- <meta name="twitter:description" content="SVG path draws progressively on success — stroke-dashoffset animates from full length to zero.">
+ <meta name="twitter:description" content="A tick draws itself in a circle once a task succeeds. Best for forms.">
<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": "Checkmark Draw", "name": "Checkmark Draw", "description": "SVG path draws progressively on success — stroke-dashoffset animates from full length to zero.", "url": "https://matinmonshizadeh.github.io/animation-handbook/animations/04-micro-interactions/checkmark-draw/", "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, Checkmark Draw"}</script>
+ <script type="application/ld+json">{"@context": "https://schema.org", "@type": "TechArticle", "headline": "Checkmark Draw", "name": "Checkmark Draw", "description": "A tick draws itself in a circle once a task succeeds. Best for forms.", "url": "https://matinmonshizadeh.github.io/animation-handbook/animations/04-micro-interactions/checkmark-draw/", "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, Checkmark Draw"}</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;--draw-dur:500ms;--draw-ease:ease-out;--stroke-w:4;--stroke-color:#56d364}
+ :root{--ui-accent:#ff9d5c;--draw-dur:500ms;--draw-ease:ease-out;--stroke-w:4;--stroke-color:#56d364}
*,*::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:32px;padding:32px}
+ .stage{display:flex;flex-direction:column;align-items:center;justify-content:center;gap:32px;padding:32px;background:#0b0b0d}
/* The button that transforms */
- .submit-btn{position:relative;width:180px;height:52px;background:var(--ui-accent);color:#000;border:none;font-family:var(--mono);font-size:13px;font-weight:bold;border-radius:8px;cursor:pointer;overflow:hidden;transition:background .3s ease,width .3s ease;flex-shrink:0}
+ .submit-btn{position:relative;width:180px;height:52px;background:var(--ui-accent);color:#000;border:none;font-family:inherit;font-size:13px;font-weight:bold;border-radius:8px;cursor:pointer;overflow:hidden;transition:background .3s ease;flex-shrink:0}
.submit-btn:disabled{cursor:default}
+ /* The site focus ring is drawn inside the button. On the orange fill it is as light as the fill, so it turns dark. */
+ .hb-page .stage .submit-btn:focus-visible{outline-color:#0b0b0d}
.btn-text{transition:opacity .2s ease}
.btn-spinner{position:absolute;inset:0;display:flex;align-items:center;justify-content:center;opacity:0;transition:opacity .2s ease}
- .sp{width:22px;height:22px;border-radius:50%;border:3px solid rgba(0,0,0,.2);border-top-color:#000;animation:spin .7s linear infinite}
+ .sp{width:22px;height:22px;border-radius:50%;border:3px solid rgba(0,0,0,.2);border-top-color:#000}
+ /* The spinner turns only while the button is disabled (from the press until reset), so nothing on the stage runs at rest */
+ .submit-btn:disabled .sp{animation:spin .7s linear infinite}
@keyframes spin{to{transform:rotate(360deg)}}
.btn-check{position:absolute;inset:0;display:flex;align-items:center;justify-content:center;opacity:0;transition:opacity .2s ease}
/* SVG icon container */
@@ -55,140 +50,224 @@
/* Shake */
@keyframes shake{0%,100%{transform:translateX(0)}20%{transform:translateX(-6px)}40%{transform:translateX(6px)}60%{transform:translateX(-4px)}80%{transform:translateX(4px)}}
.icon-wrap.shake{animation:shake .4s ease}
- /* State label */
- .state-label{font-size:11px;color:var(--ui-muted);text-align:center;min-height:20px}
- /* Panel */
- aside{width:clamp(200px,22vw,240px);flex-shrink:0;background:var(--ui-bg);border:1px solid var(--ui-border);border-radius:8px;padding:16px;display:flex;flex-direction:column;gap:10px}
- .note{font-size:10px;color:var(--ui-muted);line-height:1.6;border-left:2px solid var(--ui-accent);padding-left:8px}
- .lbl{font-size:10px;text-transform:uppercase;letter-spacing:1px;color:var(--ui-accent)}
- .div{height:1px;background:var(--ui-border)}
- .sr{display:flex;align-items:center;gap:6px;font-size:10px}
- .sr input[type=range]{flex:1;accent-color:var(--ui-accent);min-height:44px}
- .sv{width:44px;text-align:right;color:var(--ui-text)}
- select{background:var(--ui-bg);border:1px solid var(--ui-border);color:var(--ui-text);font-family:var(--mono);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}
- input[type=color]{border:none;background:none;width:44px;height:44px;cursor:pointer;border-radius:4px;padding:0}
- button.rst{background:transparent;border:1px solid var(--ui-border);color:var(--ui-text);font-family:var(--mono);font-size:10px;padding:14px 8px;border-radius:4px;cursor:pointer;width:100%;min-height:44px}
- @media(hover:hover){button.rst:hover{border-color:var(--ui-accent);color:var(--ui-accent)}}
- @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}:root{--stage-h:auto}.stage{width:100%;height:auto;min-height:440px}}
- @media(prefers-reduced-motion:reduce){.check-circle,.check-mark,.x-mark,.x-mark2{transition:none!important}.icon-wrap.drawn .check-circle,.icon-wrap.drawn .check-mark,.icon-wrap.error .x-mark,.icon-wrap.error .x-mark2{stroke-dashoffset:0}.icon-wrap.shake{animation:none}}
+ @media(prefers-reduced-motion:reduce){.check-circle,.check-mark,.x-mark,.x-mark2{transition:none!important}.icon-wrap.drawn .check-circle,.icon-wrap.drawn .check-mark,.icon-wrap.error .x-mark,.icon-wrap.error .x-mark2{stroke-dashoffset:0}.icon-wrap.shake{animation:none}.sp{animation: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="../progress-animation/" rel="prev" title="Previous">‹ Prev</a><a class="ah-hideSm" href="../form-field-morph/" 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/checkmark-draw/index.html" target="_blank" rel="noopener noreferrer">Source ↗</a></span></div>
-<header>
- <h1>Checkmark Draw</h1>
- <p>SVG path draws progressively on success — stroke-dashoffset animates from full length to zero.</p>
-</header>
-<div class="layout">
- <div class="stage">
- <button class="submit-btn" id="submit-btn" aria-live="polite">
- <span class="btn-text" id="btn-text">Submit</span>
- <span class="btn-spinner" id="btn-spin"><span class="sp"></span></span>
- <span class="btn-check" id="btn-check">✓</span>
- </button>
- <div class="icon-wrap" id="icon-wrap">
- <svg viewBox="0 0 80 80">
- <circle class="check-circle" id="check-circle" cx="40" cy="40" r="30"/>
- <polyline class="check-mark" id="check-mark" points="24,41 35,52 56,30"/>
- <line class="x-mark" id="xm1" x1="26" y1="26" x2="54" y2="54"/>
- <line class="x-mark2" id="xm2" x1="54" y1="26" x2="26" y2="54"/>
- </svg>
+<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="../progress-animation/" rel="prev" aria-label="Previous: Progress 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>Progress Animation</span></a><a href="../form-field-morph/" rel="next" aria-label="Next: Form Field Morph"><span><span class="hb-dir">Next: </span>Form Field Morph</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.13 · Micro-Interactions</p>
+ <h1>Checkmark Draw</h1>
+ <p class="hb-lede">A tick draws itself in a circle once a task succeeds. Best for forms.</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 Submit (Reset brings it back), or press Show me.</p></div>
+ </div>
+ <div class="stage hb-dots">
+ <button class="submit-btn" id="submit-btn" type="button">
+ <span class="btn-text" id="btn-text">Submit</span>
+ <span class="btn-spinner" id="btn-spin" aria-hidden="true"><span class="sp"></span></span>
+ <span class="btn-check" id="btn-check" aria-hidden="true">✓</span>
+ </button>
+ <div class="icon-wrap" id="icon-wrap">
+ <svg viewBox="0 0 80 80" aria-hidden="true">
+ <circle class="check-circle" cx="40" cy="40" r="30"/>
+ <polyline class="check-mark" points="24,41 35,52 56,30"/>
+ <line class="x-mark" x1="26" y1="26" x2="54" y2="54"/>
+ <line class="x-mark2" x1="54" y1="26" x2="26" y2="54"/>
+ </svg>
+ </div>
+ </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>
+ <button class="hb-play" type="button" id="btn-reset" data-hb-reset><svg class="hb-ic" viewBox="0 0 24 24" aria-hidden="true"><path d="M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"/><path d="M3 3v5h5"/></svg>Reset</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="result-lbl">Result</p>
+ <div class="seg" id="result-seg" role="group" aria-labelledby="result-lbl">
+ <button type="button" data-err="0" class="on" aria-pressed="true">Success</button>
+ <button type="button" data-err="1" aria-pressed="false">Error</button>
+ </div>
+ <p class="hb-hint">Error draws a red X and gives it a shake.</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="800" aria-pressed="false">Slow</button>
+ <button type="button" data-ms="500" class="on" aria-pressed="true">Normal</button>
+ <button type="button" data-ms="300" aria-pressed="false">Fast</button>
+ </div>
+ <p class="hb-hint">How long the lines take to draw.</p>
+ </div>
+ <div class="hb-setting">
+ <p class="hb-setting-name" id="thick-lbl">Line thickness</p>
+ <div class="seg" id="thick-seg" role="group" aria-labelledby="thick-lbl">
+ <button type="button" data-w="2" aria-pressed="false">Thin</button>
+ <button type="button" data-w="4" class="on" aria-pressed="true">Medium</button>
+ <button type="button" data-w="7" aria-pressed="false">Thick</button>
+ </div>
+ <p class="hb-hint">Thick looks confident; thin looks precise.</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="feel-lbl">Feel</p>
+ <div class="seg" id="feel-seg" role="group" aria-labelledby="feel-lbl">
+ <button type="button" data-ease="ease-out" class="on" aria-pressed="true">Smooth</button>
+ <button type="button" data-ease="ease-in-out" aria-pressed="false">Gentle</button>
+ <button type="button" data-ease="linear" aria-pressed="false">Even</button>
+ </div>
+ <p class="hb-hint">Smooth slows at the end, like a pen lifting.</p>
+ </div>
+ <div class="hb-setting">
+ <p class="hb-setting-name" id="color-lbl">Tick color</p>
+ <div class="swatches" id="color-sw" role="group" aria-labelledby="color-lbl">
+ <button type="button" aria-pressed="false" aria-label="Pink" data-c="#ff6f8b" style="background:#ff6f8b"></button>
+ <button type="button" aria-pressed="false" aria-label="White" data-c="#f4f4f2" style="background:#f4f4f2"></button>
+ <button type="button" aria-pressed="false" aria-label="Blue" data-c="#58a6ff" style="background:#58a6ff"></button>
+ <button type="button" aria-pressed="false" aria-label="Purple" data-c="#d2a8ff" style="background:#d2a8ff"></button>
+ <button type="button" class="on" aria-pressed="true" aria-label="Green" data-c="#56d364" style="background:#56d364"></button>
+ <button type="button" aria-pressed="false" aria-label="Orange" data-c="#ffa657" style="background:#ffa657"></button>
+ </div>
+ <p class="hb-hint">The circle and tick; the X stays red.</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="state-label" id="state-label">Click Submit to trigger sequence</div>
- </div>
- <aside>
- <p class="note">stroke-dasharray sets the pattern length; stroke-dashoffset hides part of it. Animating offset from full length → 0 draws the path in.</p>
- <div class="lbl">Draw Duration</div>
- <div class="sr"><input type="range" id="dur-sl" min="200" max="1500" value="500" step="50"><span class="sv" id="dur-v">500ms</span></div>
- <div class="lbl">Easing</div>
- <select id="ease-sel">
- <option value="ease-out" selected>Ease out</option>
- <option value="ease-in-out">Ease in-out</option>
- <option value="linear">Linear</option>
- </select>
- <div class="lbl">Stroke Width</div>
- <div class="sr"><input type="range" id="sw-sl" min="2" max="8" value="4" step="1"><span class="sv" id="sw-v">4px</span></div>
- <div class="lbl">Stroke Color</div>
- <input type="color" id="color-pick" value="#56d364" aria-label="Stroke color">
- <label class="tog"><input type="checkbox" id="error-tog"><span>Show error (X) variant</span></label>
- <div class="div"></div>
- <button class="rst" id="replay-btn">↺ Replay</button>
- </aside>
-</div>
+ <div class="hb-card">
+ <p class="hb-prompt">Add a success check mark that draws itself to [the form or action that just finished]. After the visitor submits, show a short loading state in the button, then draw a circle and a tick inside it as if by hand: the circle first, then the tick, starting just before the circle closes. For a failure, draw a red X the same way and give it a short shake. Let the button turn green or red to match. If the visitor has reduced motion turned on, show the finished check or X at once. 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>Form success</li><li>Payments</li><li>Finished steps</li></ul>
+ <h3>Avoid on</h3>
+ <ul class="hb-tags hb-avoid"><li>Frequent small saves</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 stage=document.querySelector('.stage');
const btn=document.getElementById('submit-btn');
const btnText=document.getElementById('btn-text');
const btnSpin=document.getElementById('btn-spin');
const btnCheck=document.getElementById('btn-check');
const iconWrap=document.getElementById('icon-wrap');
- const stateLabel=document.getElementById('state-label');
- let running=false,autoTimer=null,seqTimer=null;
-
- function reset(){
- clearTimeout(seqTimer);running=false;
- iconWrap.classList.remove('drawn','error','shake');
- btn.disabled=false;btn.style.background='';
- btnText.style.opacity='1';btnSpin.style.opacity='0';btnCheck.style.opacity='0';
- stateLabel.textContent='Click Submit to trigger sequence';
- }
+ const slowTog=document.getElementById('slow-tog');
+ const vars=document.documentElement.style;
+ // Everything on the stage that eases between two looks; toRest() switches these transitions off for a moment.
+ const easing=[btn,btnText,btnSpin,btnCheck,...stage.querySelectorAll('.check-circle,.check-mark,.x-mark,.x-mark2')];
+ let showError=false,draw=500,seqTimer=0,runTimers=[];
+ // Submit: the label fades and a spinner turns for 900ms, then the circle and tick (or the X) draw and the button stays
+ // finished until reset(). The click and Show me both come through here. The 900ms wait is a hold, so Slow motion does not stretch it.
function runSequence(){
- if(running)return;
- running=true;btn.disabled=true;
- stateLabel.textContent='Loading…';
+ if(btn.disabled)return;
+ btn.disabled=true;
btnText.style.opacity='0';btnSpin.style.opacity='1';
- const showError=document.getElementById('error-tog').checked;
+ const failed=showError;
seqTimer=setTimeout(()=>{
btnSpin.style.opacity='0';btnCheck.style.opacity='1';
- if(showError){
- btn.style.background='#f85149';
- iconWrap.classList.add('error','shake');
- stateLabel.textContent='Error — X draws in';
- }else{
- btn.style.background='#56d364';
- iconWrap.classList.add('drawn');
- stateLabel.textContent='Success — checkmark draws in';
- }
- running=false;
+ if(failed){btn.style.background='#f85149';iconWrap.classList.add('error','shake')}
+ else{btn.style.background='#56d364';iconWrap.classList.add('drawn')}
},900);
}
-
+ // Back to Submit: the lines draw back out and the label fades in again.
+ function reset(){
+ clearTimeout(seqTimer);
+ iconWrap.classList.remove('drawn','error','shake');
+ btn.disabled=false;btn.style.background='';
+ btnText.style.opacity='1';btnSpin.style.opacity='0';btnCheck.style.opacity='0';
+ }
btn.addEventListener('click',runSequence);
- document.getElementById('replay-btn').addEventListener('click',()=>{reset();setTimeout(runSequence,200)});
- document.getElementById('dur-sl').addEventListener('input',e=>{
- document.getElementById('dur-v').textContent=e.target.value+'ms';
- document.documentElement.style.setProperty('--draw-dur',e.target.value+'ms');
- });
- document.getElementById('ease-sel').addEventListener('change',e=>{
- document.documentElement.style.setProperty('--draw-ease',e.target.value);
- });
- document.getElementById('sw-sl').addEventListener('input',e=>{
- document.getElementById('sw-v').textContent=e.target.value+'px';
- document.documentElement.style.setProperty('--stroke-w',e.target.value);
- });
- document.getElementById('color-pick').addEventListener('input',e=>{
- document.documentElement.style.setProperty('--stroke-color',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}
+ // Only the run's own timers stop: a sequence already under way still finishes and stays finished until Reset.
+ function stopRun(){runTimers.forEach(clearTimeout);runTimers=[]}
+ // A run starts from Submit, put there without animating: the transitions are turned off, reset() runs, a reflow (read on the
+ // button, since an SVG element has no offsetWidth) makes it stick, and the transitions come back.
+ function toRest(){
+ easing.forEach(el=>{el.style.transition='none'});
+ reset();
+ void btn.offsetWidth;
+ easing.forEach(el=>{el.style.transition=''});
+ }
+ // Submit is pressed after 300ms of rest. Its own 900ms wait follows, then the lines draw over 1.4 x Speed (the circle over Speed,
+ // the tick starting 0.4 x Speed after it) and rest 1.2 s. At the defaults: the tick is complete at 1.9 s, back to Submit at 3.1 s.
+ document.getElementById('btn-demo').addEventListener('click',()=>{
+ stopRun();
+ toRest();
+ later(runSequence,0,300);
+ later(reset,1.4*draw,2400);
});
+ document.getElementById('btn-reset').addEventListener('click',()=>{stopRun();reset()});
+ // The visitor pressed, typed, scrolled or touched inside the stage: the run stops and the button stays as it is.
+ document.addEventListener('hb:input',()=>{if(running())stopRun()});
- // Auto-replay every 4s
- autoTimer=setInterval(()=>{if(!running){reset();setTimeout(runSequence,300);}},4000);
+ 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('result-seg',d=>{showError=d.err==='1'});
+ choices('speed-seg',d=>{draw=+d.ms;vars.setProperty('--draw-dur',draw+'ms')});
+ choices('thick-seg',d=>{vars.setProperty('--stroke-w',d.w)});
+ choices('feel-seg',d=>{vars.setProperty('--draw-ease',d.ease)});
+ choices('color-sw',d=>{vars.setProperty('--stroke-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.html
index 03ef22ee..0b7161ac 100644
--- a/index.html
+++ b/index.html
@@ -963,7 +963,7 @@ const CATS=[
['shimmer-effect','Shimmer Effect','A band of light sweeps over gray placeholders. Best for loading screens.'],
['loading-spinner','Loading Spinner','Six small shapes loop to show that something is loading. Best for short waits.'],
['progress-animation','Progress Animation','A bar, a ring and steps fill up to show progress. Best for uploads.'],
- ['checkmark-draw','Checkmark Draw','SVG path draws progressively on success — stroke-dashoffset animates from full length to zero.'],
+ ['checkmark-draw','Checkmark Draw','A tick draws itself in a circle once a task succeeds. Best for forms.'],
['form-field-morph','Form Field Morph','Floating label rises out of the input on focus — persists when the field is filled.'],
['badge-pulse','Notification Badge Pulse','Dot on icon pulses to draw peripheral attention — scale, halo, or both.'],
['tooltip-reveal','Tooltip Reveal','Info box fades in after a 300ms delay — long enough to avoid triggering on mouse pass-through.'],