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: Add-to-Cart Fly (04.32)
matin8e12f5a70106
diff --git a/README.md b/README.mdindex ca0a9d2e..ebf4837f 100644--- a/README.md+++ b/README.md@@ -157,6 +157,7 @@ All 129 techniques, each linked to its live demo.- **[Pull to Refresh](animations/04-micro-interactions/pull-to-refresh/)** — Pulling a list down shows a spinner, then new items. Best for feeds.- **[Animated Gradient Border](animations/04-micro-interactions/gradient-border/)** — A band of colors runs around the edge of a card or button. Best for featured offers.- **[Spotlight Hover Glow](animations/04-micro-interactions/spotlight-hover/)** — A soft light follows the pointer and lights up the card edges near it. Best for feature grids.+- **[Add-to-Cart Fly](animations/04-micro-interactions/add-to-cart-fly/)** — A copy of the product flies into the cart, which bumps and counts up. Best for shops.</details>diff --git a/animations/04-micro-interactions/README.md b/animations/04-micro-interactions/README.mdindex 1519b2b0..88132fa9 100644--- a/animations/04-micro-interactions/README.md+++ b/animations/04-micro-interactions/README.md@@ -37,6 +37,7 @@ Short, user-triggered animations that provide feedback, confirm actions, and com| [Pull to Refresh](pull-to-refresh/) | Pulling a list down shows a spinner, then new items. Best for feeds. || [Animated Gradient Border](gradient-border/) | A band of colors runs around the edge of a card or button. Best for featured offers. || [Spotlight Hover Glow](spotlight-hover/) | A soft light follows the pointer and lights up the card edges near it. Best for feature grids. |+| [Add-to-Cart Fly](add-to-cart-fly/) | A copy of the product flies into the cart, which bumps and counts up. Best for shops. |## Key conceptsdiff --git a/animations/04-micro-interactions/add-to-cart-fly/README.md b/animations/04-micro-interactions/add-to-cart-fly/README.mdnew file mode 100644index 00000000..ad1261b1--- /dev/null+++ b/animations/04-micro-interactions/add-to-cart-fly/README.md@@ -0,0 +1,52 @@+# Add-to-Cart Fly++## What it is+An add-to-cart fly sends a small copy of a product's picture into the cart icon when the visitor presses Add to cart. The copy shrinks as it travels, the cart gives a little bump as it lands, and the number on the cart goes up, so the visitor sees where the item went.++## When to use it+- Product lists and grids in online shops, where the cart icon is far from the product+- Food and grocery ordering, where people add many items in a row+- Wish lists and save-for-later buttons+- Any add button whose only other feedback is a number changing in a corner++## How it works+On a press, the product's picture is cloned and laid over itself in a layer of the stage. The copy sits in two nested wrappers, so each direction gets its own timing, and all three parts are animated with `element.animate()` (the Web Animations API) on `transform` and `opacity` only:++```js+fly.animate([{ transform: 'none' }, { transform: `translateX(${dx}px)` }],+ { duration: dur, fill: 'forwards', easing: 'linear' }); // sideways, at an even pace+lift.animate([+ { transform: 'none', easing: 'cubic-bezier(.333,.667,.667,1)' }, // rising, slowing down+ { offset: at, transform: `translateY(${top}px)`, easing: 'cubic-bezier(.333,0,.667,.333)' }, // falling, faster+ { transform: `translateY(${dy}px)` }+], { duration: dur, fill: 'forwards' });+copy.animate([+ { transform: 'none', easing: 'ease-out' }, { offset: .3, transform: `scale(${mid})` },+ { offset: .85, transform: `scale(${end})`, opacity: 1 }, { transform: `scale(${end * .6})`, opacity: 0 }+], { duration: dur, fill: 'forwards' });+```++The two vertical easings are the two halves of a parabola: `cubic-bezier(.333,.667,.667,1)` is exactly t(2 − t) and `cubic-bezier(.333,0,.667,.333)` exactly t², so with the sideways move at an even pace the copy follows the path of a thrown ball. The top of the arc sits a little above the cart, and the moment `at` it is reached comes from the start speed such a throw needs: `v = 2·top − 2·√(top·(top − dy))` and `at = −v / (2·(dy − v))`. The Straight path gives both wrappers the same `ease-in-out` instead, which keeps the copy on a line.++When the vertical animation's `finished` promise resolves, the copy is removed, the count goes up, and the cart and its badge play a short bump. Because the landing waits for the animation itself, Slow motion (which sets `playbackRate` to one third on every animation in the stage) slows the flight and the landing together. Reset cancels any copy still in the air, so it never lands late.++## Key parameters+| Parameter | Default | Effect |+|-----------|---------|--------|+| Flight speed | Normal | How long the copy takes to reach the cart: slow is 1.1s, normal 0.7s and fast 0.45s |+| Path | Arc | Arc rises and drops into the cart like a toss; Straight goes in a line, easing in and out |+| Cart bumps | On | The cart tips and grows for a moment and its badge pops as the copy lands; off, only the number changes |++## Production notes+- **Measure at the press**: read the picture's and the cart's positions with `getBoundingClientRect()` when the button is pressed, since the page may have scrolled; on a whole page, give the copy `position: fixed` so scrolling during the flight does not move it.+- **Update the cart at once**: add the item to the cart data right away and only delay the visible count, so nothing is lost if the visitor leaves mid-flight, and announce the change to screen readers through a live region.+- **Many presses**: each press gets its own copy; cancel copies still in the air (`animation.cancel()`) when the cart is emptied or the view changes.+- **Keep it short**: a flight much longer than a second makes a quick shopper wait for feedback, and on a page where people add dozens of items, a simple count change is kinder.+- **Reduced motion**: under `prefers-reduced-motion: reduce` nothing flies and the cart does not bump; the new number fades in.+- **Libraries**: GSAP's MotionPathPlugin flies an element along a curve (`motionPath: { path: [...], curviness: 1.25 }`), Framer Motion can give `x` and `y` different `ease` values for the same arc, and the CSS `offset-path` property is another way to follow a curve.++## See also+- [Heart / Like Burst](../heart-burst/) — another button that celebrates the press+- [Notification Badge Pulse](../badge-pulse/) — a badge that draws the eye to a count+- [Button Press Scale](../button-press-scale/) — the small press the Add to cart button makes+- [Shared Element Transition](../../03-page-transitions/shared-element-transition/) — a picture that moves from one place to anotherdiff --git a/animations/04-micro-interactions/add-to-cart-fly/index.html b/animations/04-micro-interactions/add-to-cart-fly/index.htmlnew file mode 100644index 00000000..1d683876--- /dev/null+++ b/animations/04-micro-interactions/add-to-cart-fly/index.html@@ -0,0 +1,276 @@+<!DOCTYPE html>+<html lang="en">+<head>+ <meta charset="UTF-8">+ <meta name="viewport" content="width=device-width, initial-scale=1.0">+ <title>Add-to-Cart Fly — Animation Handbook</title>+ <meta name="description" content="A copy of the product flies into the cart, which bumps and counts up. Best for shops.">+ <link rel="canonical" href="https://matinmonshizadeh.github.io/animation-handbook/animations/04-micro-interactions/add-to-cart-fly/">+ <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="Add-to-Cart Fly — Animation Handbook">+ <meta property="og:description" content="A copy of the product flies into the cart, which bumps and counts up. Best for shops.">+ <meta property="og:url" content="https://matinmonshizadeh.github.io/animation-handbook/animations/04-micro-interactions/add-to-cart-fly/">+ <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="Add-to-Cart Fly — Animation Handbook">+ <meta name="twitter:description" content="A copy of the product flies into the cart, which bumps and counts up. Best for shops.">+ <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": "Add-to-Cart Fly", "name": "Add-to-Cart Fly", "description": "A copy of the product flies into the cart, which bumps and counts up. Best for shops.", "url": "https://matinmonshizadeh.github.io/animation-handbook/animations/04-micro-interactions/add-to-cart-fly/", "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, Add-to-Cart Fly"}</script>+ <style>+ :root{--ui-accent:#ff9d5c}+ *,*::before,*::after{box-sizing:border-box;margin:0;padding:0}+ .stage{position:relative;display:flex;flex-direction:column;overflow:hidden;background:#0b0b0d;color:#f4f4f2;touch-action:manipulation}+ /* The stage is a small shop: a header with the cart, then a row of products */+ .bar{flex:none;display:flex;align-items:center;justify-content:space-between;padding:clamp(12px,2vw,26px) clamp(14px,2.4vw,24px) 0}+ .brand{font-size:15px;font-weight:800;letter-spacing:-.01em}+ .cart{position:relative;display:grid;place-items:center;width:44px;height:44px;border-radius:12px;border:1px solid rgba(255,255,255,.14);background:#141418}+ .cart svg{width:22px;height:22px;fill:none;stroke:#f4f4f2;stroke-width:1.8;stroke-linecap:round;stroke-linejoin:round}+ .badge{position:absolute;top:-7px;right:-7px;display:grid;place-items:center;min-width:21px;height:21px;padding:0 5px;border-radius:11px;+ background:var(--ui-accent);color:#1a0e05;font-size:11px;font-weight:800;font-variant-numeric:tabular-nums}+ .products{flex:1;min-height:0;display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:clamp(10px,2vw,20px);+ width:100%;max-width:820px;margin:0 auto;padding:clamp(12px,2vw,20px) clamp(14px,2.4vw,24px) clamp(14px,2.4vw,24px)}+ .prod{display:flex;flex-direction:column;gap:8px;min-height:0;min-width:0}+ /* The picture is the part that gets copied and flown: it fills what the name, price and button leave */+ .pic{flex:1;min-height:0;display:grid;place-items:center;border-radius:12px}+ .pic svg{width:clamp(30px,22%,52px);height:auto;fill:none;stroke:#fff;stroke-width:1.6;stroke-linecap:round;stroke-linejoin:round}+ .p1{background:linear-gradient(140deg,#6ea8ff,#3b5bdb)}+ .p2{background:linear-gradient(140deg,#ffb27d,#e8590c)}+ .p3{background:linear-gradient(140deg,#7be0a0,#2b9a4a)}+ .row{display:flex;justify-content:space-between;gap:8px;font-size:clamp(13px,1.5vw,15px)}+ .name{font-weight:700;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}+ .price{color:#adadb2}+ .add{flex:none;min-height:44px;border:0;border-radius:10px;background:var(--ui-accent);color:#1a0e05;font:inherit;font-size:clamp(13px,1.5vw,15px);+ font-weight:700;cursor:pointer;transition:transform .12s ease}+ .add:active,.add.pressing{transform:scale(.95)}+ /* 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 .add:focus-visible{outline-color:#0b0b0d}+ /* The flying copy: an outer layer moves it sideways, an inner one up and down, the copy itself shrinks */+ .fly{position:absolute;left:0;top:0;z-index:5;pointer-events:none;will-change:transform}+ .fly>div{will-change:transform}+ .copy{position:absolute;left:0;top:0;box-shadow:0 8px 24px rgba(0,0,0,.45);will-change:transform,opacity}+ .sr-only{position:absolute;width:1px;height:1px;margin:-1px;overflow:hidden;clip-path:inset(50%);white-space:nowrap}+ @media(max-width:600px){+ .products{grid-template-columns:repeat(2,minmax(0,1fr))}+ .prod:nth-child(3){display:none}+ }+ @media(prefers-reduced-motion:reduce){.add{transition: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="../spotlight-hover/" rel="prev" aria-label="Previous: Spotlight Hover Glow"><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>Spotlight Hover Glow</span></a></span>+</nav>+<main class="hb-page">+ <header class="hb-head">+ <p class="hb-cat">04.32 · Micro-Interactions</p>+ <h1>Add-to-Cart Fly</h1>+ <p class="hb-lede">A copy of the product flies into the cart, which bumps and counts up. Best for shops.</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 Add to cart (Reset brings the count back), or press Show me.</p></div>+ </div>+ <div class="stage">+ <div class="bar">+ <span class="brand">Shop</span>+ <span class="cart" id="cart" aria-hidden="true"><svg viewBox="0 0 24 24"><path d="M2.5 3.5h2.3l2.5 11a1.5 1.5 0 0 0 1.5 1.2h8.6a1.5 1.5 0 0 0 1.4-1.1l1.9-6.6H6"/><circle cx="9.5" cy="19.6" r="1.4"/><circle cx="17" cy="19.6" r="1.4"/></svg><span class="badge" id="badge"><span id="count">2</span></span></span>+ </div>+ <div class="products">+ <div class="prod">+ <div class="pic p1" aria-hidden="true"><svg viewBox="0 0 24 24"><path d="M4 15v-3a8 8 0 0 1 16 0v3"/><rect x="3" y="14" width="4.5" height="7" rx="1.5"/><rect x="16.5" y="14" width="4.5" height="7" rx="1.5"/></svg></div>+ <p class="row"><span class="name">Headphones</span><span class="price">$89</span></p>+ <button class="add" type="button" aria-label="Add Headphones to cart">Add to cart</button>+ </div>+ <div class="prod">+ <div class="pic p2" aria-hidden="true"><svg viewBox="0 0 24 24"><rect x="3" y="7" width="18" height="13" rx="2.5"/><path d="M8.5 7 10 4.5h4L15.5 7"/><circle cx="12" cy="13.5" r="3.5"/></svg></div>+ <p class="row"><span class="name">Camera</span><span class="price">$249</span></p>+ <button class="add" type="button" aria-label="Add Camera to cart">Add to cart</button>+ </div>+ <div class="prod">+ <div class="pic p3" aria-hidden="true"><svg viewBox="0 0 24 24"><path d="M4 9h12v6a5 5 0 0 1-5 5H9a5 5 0 0 1-5-5z"/><path d="M16 11h1.5a2.5 2.5 0 0 1 0 5H16"/><path d="M8 3.5v2.5M12 3.5v2.5"/></svg></div>+ <p class="row"><span class="name">Mug</span><span class="price">$14</span></p>+ <button class="add" type="button" aria-label="Add Mug to cart">Add to cart</button>+ </div>+ </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>+ <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="speed-lbl">Flight speed</p>+ <div class="seg" id="speed-seg" role="group" aria-labelledby="speed-lbl">+ <button type="button" data-ms="1100" aria-pressed="false">Slow</button>+ <button type="button" data-ms="700" class="on" aria-pressed="true">Normal</button>+ <button type="button" data-ms="450" aria-pressed="false">Fast</button>+ </div>+ <p class="hb-hint">How long the copy takes to reach the cart.</p>+ </div>+ <div class="hb-setting">+ <p class="hb-setting-name" id="path-lbl">Path</p>+ <div class="seg" id="path-seg" role="group" aria-labelledby="path-lbl">+ <button type="button" data-arc="1" class="on" aria-pressed="true">Arc</button>+ <button type="button" data-arc="0" aria-pressed="false">Straight</button>+ </div>+ <p class="hb-hint">An arc rises and drops into the cart, like a toss.</p>+ </div>+ <div class="hb-setting">+ <label class="hb-switch-row"><span>Cart bumps</span><input class="hb-switch" type="checkbox" role="switch" id="bump-tog" checked autocomplete="off"></label>+ <p class="hb-hint">The cart and its count jump as the copy lands.</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 an add-to-cart animation to [the Add to cart buttons of your product list]. When one is pressed, copy that product's picture and fly the copy into the cart icon, shrinking it on the way, then remove it. Move it with transforms only: for a curved path, slide it sideways at an even pace while an inner layer rises and then drops into the cart; for a straight path, move both together. As it lands, raise the number on the cart and, when the settings include it, give the cart a small bump. Tell screen readers that the item was added. If the visitor has reduced motion turned on, fly nothing and fade the new number in. 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>Online shops</li><li>Product lists</li><li>Food ordering</li><li>Wish lists</li></ul>+ <h3>Avoid on</h3>+ <ul class="hb-tags hb-avoid"><li>Bulk order forms</li><li>Quick reorder lists</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'),cart=document.getElementById('cart'),cartIcon=cart.querySelector('svg'),+ badge=document.getElementById('badge'),countEl=document.getElementById('count'),statusEl=document.getElementById('status'),+ slowTog=document.getElementById('slow-tog'),reduce=window.matchMedia('(prefers-reduced-motion: reduce)');+ const prods=[...stage.querySelectorAll('.prod')];+ const OUT='cubic-bezier(.333,.667,.667,1)',IN='cubic-bezier(.333,0,.667,.333)'; // the two halves of a thrown arc+ const REST=2;+ let count=REST,dur=700,arc=true,bump=true,flights=[],bumps=[],runTimers=[];++ function show(){countEl.textContent=count>99?'99+':String(count)}+ // The copy has landed: the count goes up, and the cart and its badge bump (Cart bumps). Under reduced motion nothing flew,+ // and the new number fades in instead.+ function land(name,quiet){+ count++;show();+ if(!quiet)statusEl.textContent=name+' added to the cart, '+count+' items.';+ if(reduce.matches){countEl.animate([{opacity:0},{opacity:1}],{duration:400,easing:'ease-out'});return}+ if(!bump)return;+ bumps.forEach(a=>a.cancel());+ bumps=[cart.animate([{transform:'none'},{transform:'scale(1.22) rotate(-7deg)',offset:.35},{transform:'scale(.94) rotate(3deg)',offset:.7},{transform:'none'}],{duration:450,easing:'ease-out'}),+ badge.animate([{transform:'none'},{transform:'scale(1.45)',offset:.4},{transform:'none'}],{duration:450,easing:'ease-out'})];+ }+ // A copy of the picture is laid over it and flown to the middle of the cart icon. Arc: the outer layer moves sideways at an+ // even pace while the inner one rises, slowing, to a little above the cart and then drops into it, gathering speed, which is+ // the path of a thrown ball. Straight: both layers ease the same way, so the copy goes in a line.+ function add(prod,quiet){+ const name=prod.querySelector('.name').textContent;+ if(reduce.matches){land(name,quiet);return}+ const pic=prod.querySelector('.pic'),s=stage.getBoundingClientRect(),p=pic.getBoundingClientRect(),c=cartIcon.getBoundingClientRect();+ const x0=p.left+p.width/2-s.left-stage.clientLeft,y0=p.top+p.height/2-s.top-stage.clientTop;+ const dx=c.left+c.width/2-(p.left+p.width/2),dy=c.top+c.height/2-(p.top+p.height/2);+ const fly=document.createElement('div'),lift=document.createElement('div'),copy=pic.cloneNode(true);+ fly.className='fly';fly.style.left=x0+'px';fly.style.top=y0+'px';+ copy.classList.add('copy');+ Object.assign(copy.style,{width:p.width+'px',height:p.height+'px',marginLeft:-p.width/2+'px',marginTop:-p.height/2+'px'});+ lift.append(copy);fly.append(lift);stage.append(fly);+ const opts={duration:dur,fill:'forwards'};+ fly.animate([{transform:'none'},{transform:`translateX(${dx}px)`}],{...opts,easing:arc?'linear':'ease-in-out'});+ let ys=[{transform:'none'},{transform:`translateY(${dy}px)`}];+ if(arc){+ // The top of the arc: a little above both ends, and never closer than 20px to the top of the stage+ const top=Math.max(Math.min(0,dy)-Math.min(28,Math.max(10,Math.abs(dx)*.05)),20-y0);+ const v=2*top-2*Math.sqrt(top*(top-dy)),at=-v/(2*(dy-v)); // start speed and the moment it is reached+ ys=[{transform:'none',easing:OUT},{offset:at,transform:`translateY(${top}px)`,easing:IN},{transform:`translateY(${dy}px)`}];+ }+ const flight=lift.animate(ys,{...opts,easing:arc?'linear':'ease-in-out'});+ // The copy shrinks fast to a token at most 90px across, then on to the size of the cart icon, and fades into it+ const big=Math.max(p.width,p.height),end=Math.min(1,26/big),mid=Math.max(end,Math.min(1,90/big));+ copy.animate([{transform:'none',easing:'ease-out'},{offset:.3,transform:`scale(${mid})`},{offset:.85,transform:`scale(${end})`,opacity:1},+ {transform:`scale(${end*.6})`,opacity:0}],opts);+ const f={fly,flight};flights.push(f);+ flight.finished.then(()=>{fly.remove();flights=flights.filter(x=>x!==f);land(name,quiet)},()=>{});+ }+ prods.forEach(prod=>prod.querySelector('.add').addEventListener('click',()=>add(prod,false)));++ // Show me: one run at a time. Every timer of the run goes through later(); stopRun() cancels the whole run.+ // later(fn, move, hold) waits move*(slow?3:1) + hold ms: Slow motion triples the movement, never the hold.+ function later(fn,move,hold){+ const id=setTimeout(()=>{runTimers=runTimers.filter(t=>t!==id);fn()},move*(slowTog.checked?3:1)+(hold||0));+ runTimers.push(id);+ }+ function running(){return runTimers.length>0}+ function stopRun(){runTimers.forEach(clearTimeout);runTimers=[]}+ // Back to the cart of the start: copies in the air are dropped (cancelled, so they never land), bumps stop, the count is 2.+ function toRest(){+ flights.forEach(f=>{f.flight.cancel();f.fly.remove()});flights=[];+ bumps.forEach(a=>a.cancel());bumps=[];+ countEl.getAnimations().forEach(a=>a.cancel());+ prods.forEach(p=>p.querySelector('.add').classList.remove('pressing'));+ count=REST;show();statusEl.textContent='';+ }+ // The first product's button is pressed after 300ms of rest; the copy flies for Flight speed and the cart bumps for 450ms;+ // after 1.5 s more the count fades back to 2. At the defaults the run is over at 3 s. Show me's press says nothing aloud.+ document.getElementById('btn-demo').addEventListener('click',()=>{+ stopRun();+ toRest();+ const btn=prods[0].querySelector('.add');+ later(()=>{btn.classList.add('pressing');add(prods[0],true)},0,300);+ later(()=>btn.classList.remove('pressing'),0,450);+ later(()=>{count=REST;show();countEl.animate([{opacity:0},{opacity:1}],{duration:300,easing:'ease-out'})},dur+450,1500);+ });+ document.getElementById('btn-reset').addEventListener('click',()=>{stopRun();toRest()});+ // The visitor pressed, typed, scrolled or touched inside the stage: the run stops, and a copy in the air still lands.+ 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('path-seg',d=>{arc=d.arc==='1'});+ document.getElementById('bump-tog').addEventListener('change',e=>{bump=e.target.checked});+</script>+</body>+</html>diff --git a/animations/04-micro-interactions/spotlight-hover/index.html b/animations/04-micro-interactions/spotlight-hover/index.htmlindex 356b394d..01088fa1 100644--- a/animations/04-micro-interactions/spotlight-hover/index.html+++ b/animations/04-micro-interactions/spotlight-hover/index.html@@ -54,7 +54,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="../gradient-border/" rel="prev" aria-label="Previous: Animated Gradient Border"><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>Animated Gradient Border</span></a></span>+ <span class="hb-pager"><a href="../gradient-border/" rel="prev" aria-label="Previous: Animated Gradient Border"><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>Animated Gradient Border</span></a><a href="../add-to-cart-fly/" rel="next" aria-label="Next: Add-to-Cart Fly"><span><span class="hb-dir">Next: </span>Add-to-Cart Fly</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/index.html b/index.htmlindex babc4f87..cc12989a 100644--- a/index.html+++ b/index.html@@ -694,6 +694,28 @@ button,input{font:inherit;color:inherit}.pv-spotlight .sg i{position:relative;border-radius:6px;background:rgba(18,19,24,.88)}.pv-spotlight .sg i::after{content:"";position:absolute;left:14%;bottom:24%;width:48%;height:5px;border-radius:2px;background:#2b2e38}@keyframes m-spot{0%,100%{transform:translate(-22%,-18%)}30%{transform:translate(45%,22%)}60%{transform:translate(112%,-8%)}80%{transform:translate(60%,-30%)}}+/* add to cart: a copy of the product is tossed along an arc (an even sideways move, a rise that slows and a fall that speeds up)+ into the cart, which bumps as its count goes from 2 to 3; 1cqw and 1cqh are 1% of the stage's width and height */+.pv-cartfly{background:#08090c;overflow:hidden;container-type:size}+.pv-cartfly .pd,.pv-cartfly .fs{border-radius:7px;background:linear-gradient(140deg,var(--c1),#3b5bdb)}+.pv-cartfly .pd{position:absolute;left:12cqw;top:34cqh;width:32cqw;height:44cqh}+.pv-cartfly .bt{position:absolute;left:12cqw;top:82cqh;width:32cqw;height:9cqh;border-radius:4px;background:var(--accent);animation:m-cfbt 3s ease-out infinite}+.pv-cartfly .ct{position:absolute;left:calc(86cqw - 8cqh);top:12cqh;width:16cqh;height:16cqh;display:grid;place-items:center;border-radius:6px;border:1px solid rgba(255,255,255,.2);animation:m-cfbump 3s ease-out infinite}+.pv-cartfly .ct svg{width:64%;height:64%;fill:none;stroke:var(--ink);stroke-width:2;stroke-linecap:round;stroke-linejoin:round}+.pv-cartfly .bd{position:absolute;right:-3cqh;top:-3cqh;width:8cqh;height:8cqh;border-radius:50%;background:var(--accent);color:#16161b;font:800 5.5cqh/8cqh var(--text);text-align:center}+.pv-cartfly .bd b{position:absolute;inset:0}+.pv-cartfly .n2{animation:m-cfn2 3s infinite}+.pv-cartfly .n3{opacity:0;animation:m-cfn3 3s infinite}+.pv-cartfly .fx{position:absolute;left:28cqw;top:56cqh;animation:m-cfx 3s linear infinite}+.pv-cartfly .fy{position:absolute;left:0;top:0;animation:m-cfy 3s infinite}+.pv-cartfly .fs{position:absolute;left:-16cqw;top:-22cqh;width:32cqw;height:44cqh;opacity:0;box-shadow:0 4px 12px rgba(0,0,0,.5);animation:m-cfs 3s infinite}+@keyframes m-cfbt{0%,12%{transform:none}15%{transform:scale(.9)}20%,100%{transform:none}}+@keyframes m-cfx{0%,18%{transform:translateX(0)}58%,100%{transform:translateX(58cqw)}}+@keyframes m-cfy{0%,18%{transform:translateY(0);animation-timing-function:cubic-bezier(.333,.667,.667,1)}47%{transform:translateY(-42cqh);animation-timing-function:cubic-bezier(.333,0,.667,.333)}58%,100%{transform:translateY(-36cqh)}}+@keyframes m-cfs{0%,17.9%{opacity:0;transform:none}18%{opacity:1;transform:none;animation-timing-function:ease-out}30%{transform:scale(.55)}52%{opacity:1;transform:scale(.3)}58%,100%{opacity:0;transform:scale(.18)}}+@keyframes m-cfbump{0%,58%{transform:none}63%{transform:scale(1.25) rotate(-8deg)}68%{transform:scale(.94) rotate(3deg)}74%,100%{transform:none}}+@keyframes m-cfn2{0%,57.9%{opacity:1}58%,100%{opacity:0}}+@keyframes m-cfn3{0%,57.9%{opacity:0}58%,100%{opacity:1}}/* ── bespoke: 05 Text & Typography ── */.pv-kinetic{background:#0c0608;display:grid;place-items:center;overflow:hidden}@@ -1027,7 +1049,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>131 free animations · no coding needed</p>+ <p class="pill"><span class="pill-dot" aria-hidden="true"></span>132 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">@@ -1084,8 +1106,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 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>+ <div class="more" id="more"><button type="button" class="bigbtn" id="more-btn"><span id="more-label">Browse all 132 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 132 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">@@ -1103,7 +1125,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">131 web animations with live demos and copyable prompts.</p>+ <p class="foot-t">132 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>@@ -1227,6 +1249,7 @@ const CATS=[['pull-to-refresh','Pull to Refresh','Pulling a list down shows a spinner, then new items. Best for feeds.'],['gradient-border','Animated Gradient Border','A band of colors runs around the edge of a card or button. Best for featured offers.'],['spotlight-hover','Spotlight Hover Glow','A soft light follows the pointer and lights up the card edges near it. Best for feature grids.'],+ ['add-to-cart-fly','Add-to-Cart Fly','A copy of the product flies into the cart, which bumps and counts up. Best for shops.'],]},{@@ -1306,7 +1329,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',- 'gradient-border':'gradborder','spotlight-hover':'spotlight',+ 'gradient-border':'gradborder','spotlight-hover':'spotlight','add-to-cart-fly':'cartfly','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',@@ -1430,6 +1453,7 @@ const PLACES={'pull-to-refresh':['load'],'gradient-border':['btn','imgcard'],'spotlight-hover':['imgcard','btn'],+ 'add-to-cart-fly':['btn'],// 05'kinetic-typography':['text','intro'],'typewriter-effect':['text','intro'],@@ -1494,6 +1518,7 @@ function pvMarkup(k){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 'gradborder': return '<span class="gbx"><span class="gl"><i class="anim"></i></span><span class="rg"><i class="anim"></i></span><span class="in"><b></b><b></b><b></b></span></span>';case 'spotlight': return '<span class="sg"><span class="lt anim"></span>'+'<i></i>'.repeat(6)+'</span>';+ case 'cartfly': return '<span class="pd"></span><span class="bt anim"></span><span class="ct anim"><svg viewBox="0 0 24 24"><path d="M2.5 3.5h2.3l2.5 11a1.5 1.5 0 0 0 1.5 1.2h8.6a1.5 1.5 0 0 0 1.4-1.1l1.9-6.6H6"/><circle cx="9.5" cy="19.6" r="1.4"/><circle cx="17" cy="19.6" r="1.4"/></svg><span class="bd"><b class="n2 anim">2</b><b class="n3 anim">3</b></span></span><span class="fx anim"><span class="fy anim"><span class="fs 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 3492b2a9..91cdb082 100644--- a/sitemap.xml+++ b/sitemap.xml@@ -83,6 +83,7 @@<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/gradient-border/</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/spotlight-hover/</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/add-to-cart-fly/</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>