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: Rolling Numbers (04.34)
matin235a138eca56
diff --git a/README.md b/README.mdindex b54ba331..c84216e1 100644--- a/README.md+++ b/README.md@@ -156,6 +156,7 @@ All 129 techniques, each linked to its live demo.- **[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.- **[Drag to Reorder](animations/04-micro-interactions/drag-to-reorder/)** — Drag an item and the others slide aside to make room. Best for to-do lists.+- **[Rolling Numbers](animations/04-micro-interactions/rolling-numbers/)** — Each digit rolls to its new value, like a car's mileage counter. Best for counters and prices.</details>diff --git a/animations/04-micro-interactions/README.md b/animations/04-micro-interactions/README.mdindex 2c45a537..fe33c561 100644--- a/animations/04-micro-interactions/README.md+++ b/animations/04-micro-interactions/README.md@@ -36,6 +36,7 @@ Short, user-triggered animations that provide feedback, confirm actions, and com| [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. || [Drag to Reorder](drag-to-reorder/) | Drag an item and the others slide aside to make room. Best for to-do lists. |+| [Rolling Numbers](rolling-numbers/) | Each digit rolls to its new value, like a car's mileage counter. Best for counters and prices. |## Key conceptsdiff --git a/animations/04-micro-interactions/drag-to-reorder/index.html b/animations/04-micro-interactions/drag-to-reorder/index.htmlindex 2094ec3b..ee9b9eb6 100644--- a/animations/04-micro-interactions/drag-to-reorder/index.html+++ b/animations/04-micro-interactions/drag-to-reorder/index.html@@ -52,7 +52,7 @@<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>+ <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><a href="../rolling-numbers/" rel="next" aria-label="Next: Rolling Numbers"><span><span class="hb-dir">Next: </span>Rolling Numbers</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">diff --git a/animations/04-micro-interactions/rolling-numbers/README.md b/animations/04-micro-interactions/rolling-numbers/README.mdnew file mode 100644index 00000000..3efc797a--- /dev/null+++ b/animations/04-micro-interactions/rolling-numbers/README.md@@ -0,0 +1,50 @@+# Rolling Numbers++## What it is+Rolling numbers show a changing number the way a car's mileage counter does: each digit sits in a small window over a column of the digits 0 to 9, and when the value changes, the column slides until the new digit is in the window. Only the digits that change move, so a small change turns one wheel and a big jump turns them all.++## When to use it+- Live counts: visitors, likes, followers, items in a cart+- Prices that change with a plan, a quantity or a currency switch+- Scores, timers and dashboard figures that update while people watch+- Any number whose change should be noticed, without a flash or a jump++## How it works+Each digit is a fixed-width window with `overflow: hidden` over a strip that lists 0 to 9 and then 0 again (drawn by a `::before` with line breaks), and the strip is moved with `translateY`. Every wheel keeps a position that only grows or shrinks; the digit it shows is that position modulo 10, so 7, 17 and -3 all show a 7, and the extra 0 at the end of the strip lets 9 roll on to 0. A change works out how many steps each wheel turns, the way Direction says, and starts the roll from wherever the wheel is drawn now:++```js+let steps=(target[i]-shown+10)%10;+if(dir==='down')steps-=10;else if(dir==='short'&&steps>5)steps-=10;+const delay=oneByOne?n++*STAGGER*slow:0;+w.from=w.pos;w.to+=steps;w.t0=now+delay;w.ms=dur*slow;+```++One `requestAnimationFrame` loop places every moving wheel by the time passed since its start, eased out, so a roll takes the same time at any frame rate; the loop stops when every wheel has arrived:++```js+const k=Math.min(1,Math.max(0,(now-w.t0)/w.ms));+w.pos=k<1?w.from+(w.to-w.from)*(1-Math.pow(1-k,3)):w.to;+draw(w);+```++Because a roll starts from the drawn position, a click that comes before the last roll has ended carries on smoothly instead of jumping. The rolling digits are hidden from screen readers; a polite live region holds the plain number ("2,049"), so it is read once per change rather than as a string of digits. Under reduced motion the strip jumps to the new digit and the wheel fades in with a short CSS animation.++## Key parameters+| Parameter | Default | Effect |+|-----------|---------|--------|+| Roll speed | Normal | How long a digit takes to roll to its new value: slow is 900ms, normal 550ms and fast 300ms |+| Direction | Up | Up turns every digit forward, as a mileage counter does, so 9 to 0 is one step; down turns them back, like a countdown; shortest turns each digit the nearer way round |+| Digits one after another | on | Each changing digit starts 70ms after the changing digit to its right, so a big change ripples from right to left |++## Production notes+- **Equal widths**: give every digit window the same width (or use `font-variant-numeric: tabular-nums`), so the number never shifts sideways while it rolls.+- **Growing numbers**: the demo keeps four wheels. When a number gains a digit, add a wheel at the left and fade or slide it in; render the wheels from the new number and animate only those whose digit changed.+- **Formatting**: build the wheels from the formatted string (`Intl.NumberFormat`), keeping separators, currency signs and units as still characters between the wheels.+- **Accessibility**: hide the rolling digits from assistive technology and keep the real value as text; announce it in a polite live region when the visitor caused the change, not on every automatic update.+- **Reduced motion**: with `prefers-reduced-motion: reduce`, swap the digits at once, with at most a short fade.+- **Library equivalents**: NumberFlow (a web component with React, Vue and Svelte versions, which can also pick the roll direction), Odometer.js for plain JavaScript, and Framer Motion's `useSpring` with a strip per digit to build your own; GSAP can tween each strip's position the same way.++## See also+- [Counter Animation](../../01-scroll-based/counter-animation/) — numbers that count up when they scroll into view+- [Rotate Word Carousel](../../05-text-typography/rotate-word-carousel/) — one word in a sentence that keeps swapping for the next+- [Progress Animation](../progress-animation/) — a bar, a ring and steps that fill up to show progressdiff --git a/animations/04-micro-interactions/rolling-numbers/index.html b/animations/04-micro-interactions/rolling-numbers/index.htmlnew file mode 100644index 00000000..17c7104d--- /dev/null+++ b/animations/04-micro-interactions/rolling-numbers/index.html@@ -0,0 +1,245 @@+<!DOCTYPE html>+<html lang="en">+<head>+ <meta charset="UTF-8">+ <meta name="viewport" content="width=device-width, initial-scale=1.0">+ <title>Rolling Numbers — Animation Handbook</title>+ <meta name="description" content="Each digit rolls to its new value, like a car's mileage counter. Best for counters and prices.">+ <link rel="canonical" href="https://matinmonshizadeh.github.io/animation-handbook/animations/04-micro-interactions/rolling-numbers/">+ <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="Rolling Numbers — Animation Handbook">+ <meta property="og:description" content="Each digit rolls to its new value, like a car's mileage counter. Best for counters and prices.">+ <meta property="og:url" content="https://matinmonshizadeh.github.io/animation-handbook/animations/04-micro-interactions/rolling-numbers/">+ <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="Rolling Numbers — Animation Handbook">+ <meta name="twitter:description" content="Each digit rolls to its new value, like a car's mileage counter. Best for counters and prices.">+ <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": "Rolling Numbers", "name": "Rolling Numbers", "description": "Each digit rolls to its new value, like a car's mileage counter. Best for counters and prices.", "url": "https://matinmonshizadeh.github.io/animation-handbook/animations/04-micro-interactions/rolling-numbers/", "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, Rolling Numbers"}</script>+ <style>+ :root{--ui-accent:#ff9d5c;--ui-text:#f4f4f2;--ui-muted:#8a8a92;--card:#16161a}+ *,*::before,*::after{box-sizing:border-box;margin:0;padding:0}+ .stage{display:flex;align-items:center;justify-content:center;padding:16px;background:#0b0b0d}+ .counter{display:flex;flex-direction:column;align-items:center;gap:14px;width:100%;max-width:340px;padding:clamp(18px,4vw,26px) 16px;border:1px solid rgba(255,255,255,.1);border-radius:14px;background:var(--card)}+ .cap{font-size:14px;color:var(--ui-muted)}+ .num{display:flex;align-items:center;font-size:clamp(46px,13vw,76px);font-weight:800;line-height:1.1;color:var(--ui-text)}+ /* Each digit is a window one line tall over a column of the digits 0 to 9 and 0 again; the column slides, the window clips it,+ and the soft top and bottom edges make a digit rolling through look like a turning wheel */+ .wheel{display:block;width:.64em;height:1.1em;overflow:hidden;text-align:center;-webkit-mask-image:linear-gradient(transparent,#000 16%,#000 84%,transparent);mask-image:linear-gradient(transparent,#000 16%,#000 84%,transparent)}+ .strip{display:block;will-change:transform}+ .strip::before{content:"0\A 1\A 2\A 3\A 4\A 5\A 6\A 7\A 8\A 9\A 0";white-space:pre}+ .sep{width:.3em;text-align:center}+ /* Reduced motion: a changed digit is swapped at once and fades in */+ .wheel.fade{animation:rn-fade .35s ease-out both}+ @keyframes rn-fade{from{opacity:.1}to{opacity:1}}+ .btns{display:flex;gap:8px}+ .btn{min-width:64px;height:44px;padding:0 16px;border:1px solid rgba(255,255,255,.16);border-radius:8px;background:#1d1d23;color:var(--ui-text);font:600 16px/1 var(--hb-font);cursor:pointer}+ @media(hover:hover){.btn:hover{border-color:var(--ui-accent)}}+ .sr-only{position:absolute;width:1px;height:1px;margin:-1px;overflow:hidden;clip-path:inset(50%);white-space:nowrap}+ </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="../drag-to-reorder/" rel="prev" aria-label="Previous: Drag to Reorder"><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>Drag to Reorder</span></a></span>+</nav>+<main class="hb-page">+ <header class="hb-head">+ <p class="hb-cat">04.34 · Micro-Interactions</p>+ <h1>Rolling Numbers</h1>+ <p class="hb-lede">Each digit rolls to its new value, like a car's mileage counter. Best for counters and prices.</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 −1, +1 or Random to change the number (Reset brings it back), or press Show me.</p></div>+ </div>+ <div class="stage hb-dots">+ <div class="counter">+ <p class="cap" id="cap">Visitors today</p>+ <div class="num" aria-hidden="true"><span class="wheel"><span class="strip"></span></span><span class="sep">,</span><span class="wheel"><span class="strip"></span></span><span class="wheel"><span class="strip"></span></span><span class="wheel"><span class="strip"></span></span></div>+ <p class="sr-only" id="value" aria-live="polite">2,048</p>+ <div class="btns">+ <button class="btn" type="button" data-add="-1" aria-label="Subtract 1">−1</button>+ <button class="btn" type="button" data-add="1" aria-label="Add 1">+1</button>+ <button class="btn" type="button" data-add="0">Random</button>+ </div>+ </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 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="speed-lbl">Roll speed</p>+ <div class="seg" id="speed-seg" role="group" aria-labelledby="speed-lbl">+ <button type="button" data-ms="900" aria-pressed="false">Slow</button>+ <button type="button" data-ms="550" 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 a digit takes to roll to its new value.</p>+ </div>+ <div class="hb-setting">+ <p class="hb-setting-name" id="dir-lbl">Direction</p>+ <div class="seg" id="dir-seg" role="group" aria-labelledby="dir-lbl">+ <button type="button" data-dir="up" class="on" aria-pressed="true">Up</button>+ <button type="button" data-dir="down" aria-pressed="false">Down</button>+ <button type="button" data-dir="short" aria-pressed="false">Shortest</button>+ </div>+ <p class="hb-hint">Up turns every digit forward like a mileage counter; shortest takes the nearer way round.</p>+ </div>+ <div class="hb-setting">+ <label class="hb-switch-row"><span>Digits one after another</span><input class="hb-switch" type="checkbox" role="switch" id="stagger-tog" checked autocomplete="off"></label>+ <p class="hb-hint">Each digit starts a moment after the one to its right.</p>+ </div>+ </div>+ </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 rolling numbers to [the number that changes, such as a counter, score or price]. Show each digit in a small window over a column of the digits 0 to 9, and when the value changes, slide each column so its new digit rolls into view, like the wheels of a mileage counter; digits that stay the same do not move, and separators stay still. Give every digit the same width so the number never shifts sideways, and only slide the columns, never resize anything, so it stays smooth. Let screen readers hear the plain number once. If the visitor has reduced motion turned on, swap the digits with a short fade instead of rolling. 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>Counters</li><li>Prices</li><li>Scores</li><li>Dashboards</li></ul>+ <h3>Avoid on</h3>+ <ul class="hb-tags hb-avoid"><li>Numbers that change every second</li><li>Long decimals</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 slowTog=$('slow-tog'),valueEl=$('value'),reduceMq=matchMedia('(prefers-reduced-motion:reduce)');+ const START=2048,STAGGER=70;+ let value=START,dur=550,dir='up',oneByOne=true,raf=0;+ // Each wheel keeps a position that only grows or shrinks: 7 shows a 7, and so do 17 and -3. A roll moves it from where it is+ // drawn now (mid-roll too) to its new target, so a roll that starts before the last one ended carries on without a jump.+ const wheels=[...document.querySelectorAll('.wheel')].map(el=>({el,strip:el.firstChild,pos:0,from:0,to:0,t0:0,ms:1}));+ const digitsOf=v=>String(v).padStart(4,'0').split('').map(Number);+ function draw(w){w.strip.style.transform=`translateY(${(-(((w.pos%10)+10)%10)*100/11).toFixed(3)}%)`}++ // The frame loop: every moving wheel is placed by the time passed since its start, eased out, so it runs at the same speed at any+ // frame rate. It stops when every wheel has reached its target.+ function frame(now){+ let moving=false;+ for(const w of wheels){+ if(w.pos===w.to)continue;+ const k=Math.min(1,Math.max(0,(now-w.t0)/w.ms));+ w.pos=k<1?w.from+(w.to-w.from)*(1-Math.pow(1-k,3)):w.to;+ draw(w);+ if(k<1)moving=true;+ }+ raf=moving?requestAnimationFrame(frame):0;+ }++ // Shows v: every digit that changes rolls the way Direction says, the ones on the left a little after the ones on their right when+ // Digits one after another is on. Slow motion makes the rolls and the steps between them three times as long. Under reduced motion the+ // digit is swapped at once and fades in.+ function show(v,quiet){+ v=((v%10000)+10000)%10000;+ const target=digitsOf(v),slow=slowTog.checked?3:1,now=performance.now();+ let n=0;+ for(let i=wheels.length-1;i>=0;i--){+ const w=wheels[i],shown=((Math.round(w.to)%10)+10)%10;+ if(target[i]===shown)continue;+ let steps=(target[i]-shown+10)%10;+ if(dir==='down')steps-=10;else if(dir==='short'&&steps>5)steps-=10;+ const delay=oneByOne?n++*STAGGER*slow:0;+ w.from=w.pos;w.to+=steps;w.t0=now+delay;w.ms=dur*slow;+ if(reduceMq.matches){+ w.pos=w.to;draw(w);+ w.el.classList.remove('fade');void w.el.offsetWidth;w.el.style.animationDelay=delay+'ms';w.el.classList.add('fade');+ }+ }+ value=v;+ if(!quiet)valueEl.textContent=v.toLocaleString('en-US');+ if(!raf&&!reduceMq.matches)raf=requestAnimationFrame(frame);+ }+ wheels.forEach((w,i)=>{w.pos=w.to=digitsOf(START)[i];draw(w)});++ document.querySelectorAll('.btn').forEach(b=>b.addEventListener('click',()=>{+ const add=+b.dataset.add;+ let next=value+add;+ if(!add)do{next=1000+Math.floor(Math.random()*9000)}while(next===value);+ show(next);+ }));++ // 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.+ let runTimers=[];+ 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=[]}+ // The number goes up by one, then jumps to a number whose every digit is different, then rolls back to where it started. Each+ // step waits for the longest roll before it (Roll speed plus the three steps of Digits one after another). It says nothing aloud.+ $('btn-demo').addEventListener('click',()=>{+ stopRun();+ const v=value,d=digitsOf(v),far=d.map((x,i)=>(x+3+2*i)%10);+ if(!far[0])far[0]=1;+ const roll=dur+3*STAGGER;+ if(reduceMq.matches){later(()=>show(v+1,true),0,0);later(()=>show(+far.join(''),true),0,900);later(()=>show(v,true),0,1800);return}+ later(()=>show(v+1,true),0,150);+ later(()=>show(+far.join(''),true),roll,400);+ later(()=>show(v,true),2*roll,1000);+ });+ $('btn-reset').addEventListener('click',()=>{stopRun();show(START)});+ // The visitor pressed, typed or touched inside the stage: the run stops and the number stays as 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('speed-seg',d=>{dur=+d.ms});+ choices('dir-seg',d=>{dir=d.dir});+ $('stagger-tog').addEventListener('change',e=>{oneByOne=e.target.checked});+</script>+</body>+</html>diff --git a/index.html b/index.htmlindex 821b18f7..1f674fc0 100644--- a/index.html+++ b/index.html@@ -683,6 +683,14 @@ button,input{font:inherit;color:inherit}.pv-reorder .k2{top:50%;animation:m-roslide 3.4s var(--ease) infinite}.pv-reorder .k3{top:68%}@keyframes m-rodrag{0%,8%{transform:translateY(0) scale(1)}16%{transform:translateY(0) scale(1.07)}40%{transform:translateY(120%) scale(1.07)}48%,58%{transform:translateY(120%) scale(1)}66%{transform:translateY(120%) scale(1.07)}88%{transform:translateY(0) scale(1.07)}96%,100%{transform:translateY(0) scale(1)}}@keyframes m-roslide{0%,22%{transform:translateY(0)}34%,72%{transform:translateY(-120%)}84%,100%{transform:translateY(0)}}+.pv-rollnum{background:#08090c;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:7%}+.pv-rollnum .lb{display:block;width:26%;height:6px;border-radius:3px;background:#2a2e36}+.pv-rollnum .n{display:flex;font-family:var(--disp);font-weight:800;font-size:40px;line-height:1.15;color:var(--accent)}+.pv-rollnum .w{display:block;width:.64em;height:1.15em;overflow:hidden;text-align:center;-webkit-mask-image:linear-gradient(transparent,#000 16%,#000 84%,transparent);mask-image:linear-gradient(transparent,#000 16%,#000 84%,transparent)}+.pv-rollnum .s{display:block}.pv-rollnum .s::before{content:"0\A 1\A 2\A 3\A 4\A 5\A 6\A 7\A 8\A 9\A 0";white-space:pre}+.pv-rollnum .t{animation:m-rnt 4.4s cubic-bezier(.3,.7,.2,1) infinite}.pv-rollnum .u{animation:m-rnu 4.4s cubic-bezier(.3,.7,.2,1) infinite}+@keyframes m-rnt{0%,58%{transform:translateY(-4.6em)}66%,84%{transform:translateY(-5.75em)}92%,100%{transform:translateY(-4.6em)}}+@keyframes m-rnu{0%,14%{transform:translateY(-8.05em)}22%,36%{transform:translateY(-9.2em)}44%,58%{transform:translateY(-10.35em)}66%,84%{transform:translateY(-11.5em)}92%,100%{transform:translateY(-8.05em)}}/* ── bespoke: 05 Text & Typography ── */.pv-kinetic{background:#0c0608;display:grid;place-items:center;overflow:hidden}@@ -1016,7 +1024,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>130 free animations · no coding needed</p>+ <p class="pill"><span class="pill-dot" aria-hidden="true"></span>131 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">@@ -1073,8 +1081,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 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>+ <div class="more" id="more"><button type="button" class="bigbtn" id="more-btn"><span id="more-label">Browse all 131 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 131 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">@@ -1092,7 +1100,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">130 web animations with live demos and copyable prompts.</p>+ <p class="foot-t">131 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>@@ -1215,6 +1223,7 @@ const CATS=[['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.'],['drag-to-reorder','Drag to Reorder','Drag an item and the others slide aside to make room. Best for to-do lists.'],+ ['rolling-numbers','Rolling Numbers','Each digit rolls to its new value, like a car\'s mileage counter. Best for counters and prices.'],]},{@@ -1295,6 +1304,7 @@ const PV={'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','drag-to-reorder':'reorder',+ 'rolling-numbers':'rollnum','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',@@ -1417,6 +1427,7 @@ const PLACES={'segmented-control':['menu','btn'],'pull-to-refresh':['load'],'drag-to-reorder':['menu'],+ 'rolling-numbers':['text','load'],// 05'kinetic-typography':['text','intro'],'typewriter-effect':['text','intro'],@@ -1480,6 +1491,7 @@ function pvMarkup(k){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 'reorder': return '<span class="rw k1 anim"></span><span class="rw k2 anim"></span><span class="rw k3"></span>';+ case 'rollnum': return '<i class="lb"></i><span class="n"><span class="w">2</span><span class="w"><span class="s t anim"></span></span><span class="w"><span class="s u anim"></span></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 b1cb1ea7..fa440469 100644--- a/sitemap.xml+++ b/sitemap.xml@@ -82,6 +82,7 @@<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/drag-to-reorder/</loc><lastmod>2026-10-01</lastmod><changefreq>monthly</changefreq><priority>0.7</priority></url>+ <url><loc>https://matinmonshizadeh.github.io/animation-handbook/animations/04-micro-interactions/rolling-numbers/</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>