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: move Bounce In to the guided-steps page
matinb068c3e5d4fd
diff --git a/animations/02-entrance-and-exit/bounce-in/README.md b/animations/02-entrance-and-exit/bounce-in/README.mdindex b050bb67..84760d54 100644--- a/animations/02-entrance-and-exit/bounce-in/README.md+++ b/animations/02-entrance-and-exit/bounce-in/README.md@@ -11,7 +11,7 @@ Bounce In brings an element up from small and low, overshoots its final size and- Any single element small enough that an energetic entrance won't feel heavy## How it works-The card animates via a named keyframe rather than a transition. Each stop scales past 1 and pulls back under it, translating the vertical overshoot at the same time. The overshoot amounts are computed from an intensity slider so the waypoints stay proportional:+The card animates via a named keyframe rather than a transition. Each stop scales past 1 and pulls back under it, translating the vertical overshoot at the same time. The overshoot amounts are computed from the Bounce strength choice (an intensity of 30, 60 or 100) so the waypoints stay proportional:```jsconst t=intensity/100;@@ -29,16 +29,16 @@ kf=`@keyframes bounce-in{.card.in{animation:bounce-in var(--dur) ease forwards}```-The generated CSS is injected into a live `<style>` tag, so changing intensity or bounce count rewrites the keyframe rule on the fly. Two- and three-bounce modes simply add more overshoot/undershoot pairs at tighter percentage intervals, each smaller than the last to imitate energy dissipating.+The generated CSS is injected into a live `<style>` tag, so changing Bounce strength or Number of bounces rewrites the keyframe rule on the fly. Two- and three-bounce modes simply add more overshoot/undershoot pairs at tighter percentage intervals, each smaller than the last to imitate energy dissipating.## Key parameters| Parameter | Default | Effect ||-----------|---------|--------|-| Overshoot intensity | 60% | How far past full size it grows; 0% means no bounce, 100% is exaggerated |-| Duration | 1100ms | Bounces need room to breathe; too short and the spring reads as a jitter |-| Bounces | 1× Single | How many times it overshoots; almost always one, since more looks cartoonish |-| Combine with fade | on | Whether it fades in while it bounces or is visible from the start |+| Bounce strength | Medium | How far past full size it grows: soft about 5%, medium 9% and strong 15%, with smaller dips back under |+| Number of bounces | One | How many times it overshoots; almost always one, since more looks cartoonish |+| Speed | Normal | How long it takes: slow is 1800ms, normal 1100ms and fast 650ms; too short and the spring reads as a jitter |+| Fades in | on | Whether it fades in while it bounces or is visible from the start |## Production notes- **Keyframes over easing**: an overshoot spring like `cubic-bezier(.34,1.56,.64,1)` gives *one* overshoot. Genuine multi-stage bounce and squash-and-stretch require explicit waypoints — that is the whole reason this technique uses `@keyframes`.@@ -49,6 +49,6 @@ The generated CSS is injected into a live `<style>` tag, so changing intensity o- **GSAP**: `Bounce.out` / `Elastic.out` eases, or a `.fromTo()` with overshoot values, cover this without a manual keyframe block.## See also-- [Scale In](../scale-in/) — the same scale entrance without the overshoot-- [Rotate In](../rotate-in/) — pairs a springy ease with a spin for icons-- [Slide In](../slide-in/) — positional entrance that also benefits from spring easing+- [Scale In](../scale-in/) — grows into place without the bounce+- [Rotate In](../rotate-in/) — spins into place while it grows+- [Slide In](../slide-in/) — travels into place from one edgediff --git a/animations/02-entrance-and-exit/bounce-in/index.html b/animations/02-entrance-and-exit/bounce-in/index.htmlindex aa9b1898..618550ba 100644--- a/animations/02-entrance-and-exit/bounce-in/index.html+++ b/animations/02-entrance-and-exit/bounce-in/index.html@@ -4,7 +4,7 @@<meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Bounce In — Animation Handbook</title>- <meta name="description" content="Overshoots final position then springs back — implemented with explicit @keyframes waypoints, not easing alone.">+ <meta name="description" content="Lands with a springy bounce. Best for badges and success messages."><link rel="canonical" href="https://matinmonshizadeh.github.io/animation-handbook/animations/02-entrance-and-exit/bounce-in/"><link rel="icon" type="image/png" sizes="96x96" href="../../../favicon.png"><link rel="icon" type="image/svg+xml" href="../../../favicon.svg">@@ -12,23 +12,18 @@<meta property="og:type" content="article"><meta property="og:site_name" content="Animation Handbook"><meta property="og:title" content="Bounce In — Animation Handbook">- <meta property="og:description" content="Overshoots final position then springs back — implemented with explicit @keyframes waypoints, not easing alone.">+ <meta property="og:description" content="Lands with a springy bounce. Best for badges and success messages."><meta property="og:url" content="https://matinmonshizadeh.github.io/animation-handbook/animations/02-entrance-and-exit/bounce-in/"><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="Bounce In — Animation Handbook">- <meta name="twitter:description" content="Overshoots final position then springs back — implemented with explicit @keyframes waypoints, not easing alone.">+ <meta name="twitter:description" content="Lands with a springy bounce. Best for badges and success messages."><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": "Bounce In", "name": "Bounce In", "description": "Overshoots final position then springs back — implemented with explicit @keyframes waypoints, not easing alone.", "url": "https://matinmonshizadeh.github.io/animation-handbook/animations/02-entrance-and-exit/bounce-in/", "inLanguage": "en", "articleSection": "Entrance & Exit", "isPartOf": {"@type": "WebSite", "name": "Animation Handbook", "url": "https://matinmonshizadeh.github.io/animation-handbook/"}, "author": {"@type": "Person", "name": "matinmonshizadeh"}, "keywords": "web animation, CSS animation, Entrance & Exit, Bounce In"}</script>+ <script type="application/ld+json">{"@context": "https://schema.org", "@type": "TechArticle", "headline": "Bounce In", "name": "Bounce In", "description": "Lands with a springy bounce. Best for badges and success messages.", "url": "https://matinmonshizadeh.github.io/animation-handbook/animations/02-entrance-and-exit/bounce-in/", "inLanguage": "en", "articleSection": "Entrance & Exit", "isPartOf": {"@type": "WebSite", "name": "Animation Handbook", "url": "https://matinmonshizadeh.github.io/animation-handbook/"}, "author": {"@type": "Person", "name": "matinmonshizadeh"}, "keywords": "web animation, CSS animation, Entrance & Exit, Bounce In"}</script><style>- :root{--bg:#0b0b0d;--ui-bg:#111114;--ui-border:rgba(255,255,255,.09);--ui-accent:#5fd88a;--ui-text:#f4f4f2;--ui-muted:#77777e;--stage-h:620px;--dur:1100ms}+ :root{--ui-accent:#5fd88a;--ui-muted:#77777e;--dur:1100ms}*,*::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(16px,2.2vw,22px);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;align-items:center;justify-content:center;overflow:hidden}+ .stage{display:flex;align-items:center;justify-content:center;background:#0b0b0d}.card{background:#161b22;border:1px solid #30363d;border-radius:14px;padding:clamp(28px,5vw,48px);text-align:center;max-width:300px;opacity:0;transform:scale(0.3) translateY(40px)}.card.in{animation:bounce-in var(--dur) ease forwards}@@ -38,98 +33,139 @@.card-title{font-size:clamp(16px,2.4vw,22px);font-weight:bold;margin-bottom:8px}.card-sub{font-size:11px;color:var(--ui-muted);line-height:1.65}@media(prefers-reduced-motion:reduce){.card.in{animation:none!important;opacity:1;transform:none}.card.out{animation:none!important;opacity:0}}- /* keyframe inspector */- .kf-block{background:#0a0f14;border:1px solid var(--ui-border);border-radius:4px;padding:8px;font-size:8px;color:#56d364;line-height:1.7;overflow-x:auto;white-space:pre}- 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)}- .kv{display:flex;justify-content:space-between;font-size:10px;color:var(--ui-muted)}- .kv .v{color:var(--ui-text)}- .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:38px;text-align:right;color:var(--ui-text)}- .seg{display:flex;gap:3px}- .seg button{flex:1;background:none;border:1px solid var(--ui-border);color:var(--ui-muted);font-family:monospace;font-size:9px;padding:8px 4px;border-radius:4px;cursor:pointer;min-height:44px}- .seg button.on{border-color:var(--ui-accent);color:var(--ui-accent);background:rgba(95,216,138,.12)}- .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}- .btn-row{display:flex;gap:6px}- button.act{flex:1;background:transparent;border:1px solid var(--ui-border);color:var(--ui-text);font-family:monospace;font-size:10px;padding:14px 6px;border-radius:4px;cursor:pointer;min-height:44px}- button.act.pri{border-color:var(--ui-accent);color:var(--ui-accent)}- @media(hover:hover){button.act:hover{border-color:var(--ui-accent);color:var(--ui-accent)}}- @media(max-width:600px){.layout{flex-direction:column}.stage{flex:none;width:100%}aside{width:100%}:root{--stage-h:480px}}</style><style id="kf-style"></style>-<link rel="stylesheet" href="../../../assets/css/handbook.css">-<script src="../../../assets/js/handbook.js" defer></script>+ <link rel="stylesheet" href="../../../assets/css/demo-page.css">+ <script src="../../../assets/js/demo-page.js" defer></script></head>-<body class="hb" data-hb-autoplay>-<nav class="hb-bar" aria-label="Animation Handbook"><a class="hb-home" href="../../../">← <span>Animation Handbook</span></a><span class="hb-pager"><a href="../flip-in/" rel="prev" aria-label="Previous: Flip In">‹ <span class="hb-name">Flip In</span></a><a href="../rotate-in/" rel="next" aria-label="Next: Rotate In"><span class="hb-name">Rotate In</span> ›</a></span></nav>-<main class="hb-view">- <div class="stage">- <div class="card" id="card">- <div class="card-icon">◈</div>- <div class="card-title">Bounce Landing</div>- <div class="card-sub">Real bounce is more complex than a single cubic-bezier curve. Hand-tuned keyframe waypoints give precise control over each phase.</div>+<body class="hb" data-hb-kind="once" 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="../flip-in/" rel="prev" aria-label="Previous: Flip In"><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>Flip In</span></a><a href="../rotate-in/" rel="next" aria-label="Next: Rotate In"><span><span class="hb-dir">Next: </span>Rotate In</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">02.12 · Entrance & Exit</p>+ <h1>Bounce In</h1>+ <p class="hb-lede">Lands with a springy bounce. Best for badges and success messages.</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">Watch it</h2><p>It plays by itself. Turn on slow motion to see each part of the movement.</p></div>+ </div>+ <div class="stage hb-dots">+ <div class="card" id="card">+ <div class="card-icon">◈</div>+ <div class="card-title">Bounce Landing</div>+ <div class="card-sub">A real bounce goes past its size and back, a little less each time.</div>+ </div>+ </div>+ <div class="hb-player">+ <button class="hb-play" type="button" id="btn-play" data-hb-replay><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>Replay</button>+ <label class="hb-toggle"><input class="hb-switch" type="checkbox" role="switch" id="loop-tog" data-hb-loop><span>Loop</span></label>+ <label class="hb-toggle"><input class="hb-switch" type="checkbox" role="switch" id="slow-tog" data-hb-slowmo><span>Slow motion</span></label></div>- </div>- <aside class="hb-side">- <header class="hb-head">- <p class="hb-cat">02.12 · Entrance & Exit</p>- <h1>Bounce In</h1>- <p class="hb-lede">Overshoots its final size and position, then springs back to rest.</p>- </header>- <section class="hb-settings" aria-label="Settings">- <h2 class="hb-label">Settings</h2>- <div class="lbl">State</div>- <div class="kv"><span>Status</span><span class="v" id="st">hidden</span></div>- <div class="div"></div>- <div><div class="lbl" id="ov-lbl">Overshoot intensity</div>- <div class="sr"><input type="range" id="ov-sl" aria-labelledby="ov-lbl" min="0" max="100" value="60" step="5"><span class="sv" id="ov-v">60%</span></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 and the animation plays again.</p></div>+ </div>+ <div class="hb-settings">+ <div class="hb-setting">+ <p class="hb-setting-name" id="strength-lbl">Bounce strength</p>+ <div class="seg" id="strength-seg" role="group" aria-labelledby="strength-lbl">+ <button type="button" data-strength="30" aria-pressed="false">Soft</button>+ <button type="button" data-strength="60" class="on" aria-pressed="true">Medium</button>+ <button type="button" data-strength="100" aria-pressed="false">Strong</button>+ </div>+ <p class="hb-hint">How far it grows past full size before settling.</p>+ </div>+ <div class="hb-setting">+ <p class="hb-setting-name" id="bounces-lbl">Number of bounces</p>+ <div class="seg" id="bounces-seg" role="group" aria-labelledby="bounces-lbl">+ <button type="button" data-bounces="1" class="on" aria-pressed="true">One</button>+ <button type="button" data-bounces="2" aria-pressed="false">Two</button>+ <button type="button" data-bounces="3" aria-pressed="false">Three</button>+ </div>+ <p class="hb-hint">One usually looks best; more looks cartoonish.</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="1800" aria-pressed="false">Slow</button>+ <button type="button" data-ms="1100" class="on" aria-pressed="true">Normal</button>+ <button type="button" data-ms="650" aria-pressed="false">Fast</button>+ </div>+ <p class="hb-hint">Too fast and the bounce looks like a jitter.</p>+ </div></div>- <div><div class="lbl" id="dur-lbl">Duration</div>- <div class="sr"><input type="range" id="dur-sl" aria-labelledby="dur-lbl" min="300" max="2000" value="1100" step="100"><span class="sv" id="dur-v">1100ms</span></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">+ <label class="hb-switch-row"><span>Fades in</span><input class="hb-switch" type="checkbox" role="switch" id="fade-tog" checked></label>+ <p class="hb-hint">Softens the first moment.</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="lbl">Bounces</div>- <div class="seg" id="bounce-seg">- <button data-b="1" class="on">1× Single</button>- <button data-b="2">2× Double</button>- <button data-b="3">3× Triple</button>+ <div class="hb-card">+ <p class="hb-prompt">Add a bounce-in entrance to [the element you want to animate]. When it appears, it should start small and a little below its final spot, grow slightly past full size, dip just under it, then settle, as if it landed with a small spring. Each bounce is smaller than the one before, like energy running out, and one bounce usually looks best. Unless the settings turn it off, fade it in at the same time. Animate only its position, size and opacity so it stays smooth. If the visitor has reduced motion turned on, show the element without the bounce. 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>- <label class="tog" for="fade-tog"><input type="checkbox" id="fade-tog" checked><span>Combine with fade</span></label>- <div class="kf-block" id="kf-display" hidden>@keyframes bounce-in { ... }</div>- <div class="div"></div>- <label class="tog" for="loop-tog"><input type="checkbox" id="loop-tog" data-hb-skip data-hb-loop><span>Auto-loop</span></label>- <div class="btn-row">- <button class="act pri" id="btn-in" data-hb-replay aria-label="Play bounce in">Play in</button>- <button class="act" id="btn-out" aria-label="Play out">Play out</button>- <button class="act" id="btn-rst" data-hb-reset aria-label="Reset">Reset</button>+ </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>- </section>- <div class="hb-take">- <section class="hb-prompt-box" aria-labelledby="hb-prompt-title">- <h2 class="hb-label" id="hb-prompt-title">Prompt</h2>- <p class="hb-prompt">Add a bounce-in entrance to [the element you want to animate]. When it appears, it should start small and a little below its final spot, grow slightly past full size, dip just under it, then settle, as if it landed with a small spring. Each bounce is smaller than the one before, like energy running out, and one bounce usually looks best. Unless the settings turn it off, fade it in at the same time. Animate only its position, size and opacity so it stays smooth. If the visitor has reduced motion turned on, show the element without the bounce. Match the settings listed below.</p>- </section>+ <div class="hb-fit">+ <h2>Good for</h2>+ <ul class="hb-tags hb-good"><li>Success messages</li><li>Badges</li><li>Small pop-ups</li><li>Playful brands</li></ul>+ <h3>Avoid on</h3>+ <ul class="hb-tags hb-avoid"><li>Formal content</li><li>Large panels</li></ul></div>- </aside>+ </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 card=document.getElementById('card');- const stEl=document.getElementById('st');- const durSl=document.getElementById('dur-sl'),durV=document.getElementById('dur-v');- const ovSl=document.getElementById('ov-sl'),ovV=document.getElementById('ov-v');- const fadeTog=document.getElementById('fade-tog'),loopTog=document.getElementById('loop-tog');- const kfStyle=document.getElementById('kf-style'),kfDisplay=document.getElementById('kf-display');+ const vars=document.documentElement.style;+ const loopTog=document.getElementById('loop-tog'),slowTog=document.getElementById('slow-tog');+ const fadeTog=document.getElementById('fade-tog');+ const kfStyle=document.getElementById('kf-style');const motionOk=!window.matchMedia('(prefers-reduced-motion:reduce)').matches;- let dur=1100,bounces=1,looping=false,loopTimer=null,animTimer=null;+ let strength=60,bounces=1,ms=1100,timers=[];+ function dur(){return slowTog.checked?ms*3:ms}function buildKF(intensity,n){const t=intensity/100;const ov1=1+t*0.15,un1=1-t*0.07,ov2=1+t*0.06,un2=1-t*0.03;const fadeIn=fadeTog.checked;- let kf,display;+ let kf;if(n===1){kf=`@keyframes bounce-in{0% {opacity:${fadeIn?0:1};transform:scale(0.3) translateY(40px)}@@ -137,7 +173,6 @@80% {transform:scale(${un1.toFixed(3)}) translateY(3px)}100%{opacity:1;transform:scale(1) translateY(0)}}`;- display=`0% scale(0.3) translateY(40px)\n55% scale(${ov1.toFixed(2)}) translateY(-8px)\n80% scale(${un1.toFixed(2)}) translateY(3px)\n100% scale(1) translateY(0)`;}else if(n===2){kf=`@keyframes bounce-in{0% {opacity:${fadeIn?0:1};transform:scale(0.3) translateY(40px)}@@ -147,7 +182,6 @@90% {transform:scale(${un2.toFixed(3)}) translateY(1px)}100%{opacity:1;transform:scale(1) translateY(0)}}`;- display=`0% →40% → 60% → 75% → 90% → 100%\nDouble overshoot: ${ov1.toFixed(2)} / ${ov2.toFixed(2)}`;}else{kf=`@keyframes bounce-in{0% {opacity:${fadeIn?0:1};transform:scale(0.3) translateY(40px)}@@ -158,36 +192,46 @@88% {transform:scale(${(1+t*0.03).toFixed(3)}) translateY(-1px)}100%{opacity:1;transform:scale(1) translateY(0)}}`;- display=`Triple: ${ov1.toFixed(2)} → ${un1.toFixed(2)} → ${ov2.toFixed(2)}\n→ ${un2.toFixed(2)} → ${(1+t*0.03).toFixed(2)} → 1.0`;}kfStyle.textContent=kf;- kfDisplay.textContent=display;}-- function _trigger(cls){- clearTimeout(animTimer);+ function apply(){+ vars.setProperty('--dur',dur()+'ms');+ buildKF(strength,bounces);+ }+ function later(fn,wait){timers.push(setTimeout(fn,wait))}+ function bounceIn(){card.classList.remove('in','out');void card.offsetWidth;- buildKF(+ovSl.value,bounces);- card.classList.add(cls);- stEl.textContent=cls==='in'?'playing in':'playing out';- const d=cls==='out'?Math.round(dur*0.5):dur;- animTimer=setTimeout(()=>stEl.textContent=cls==='in'?'visible':'hidden',d);+ card.classList.add('in');+ }+ // One play bounces in. While Loop is on it then holds, shrinks out at half the duration, waits+ // and plays again; switching Loop off lets the card finish landed. Slow motion stretches dur(),+ // which the shrink-out is always half of; the 800ms hold and 400ms wait stay fixed.+ function cycle(){+ apply();bounceIn();+ if(!loopTog.checked||!motionOk)return;+ later(()=>{+ if(!loopTog.checked)return;+ card.classList.remove('in');void card.offsetWidth;+ card.classList.add('out');+ later(cycle,Math.round(dur()*0.5)+400);+ },dur()+800);}- function stopLoop(){looping=false;clearTimeout(loopTimer);loopTog.checked=false}- function loop(){_trigger('in');loopTimer=setTimeout(()=>{_trigger('out');loopTimer=setTimeout(()=>{if(looping)loop()},Math.round(dur*0.5)+400)},dur+800)}+ function play(){timers.forEach(clearTimeout);timers=[];cycle()}- document.getElementById('btn-in').addEventListener('click',()=>{stopLoop();_trigger('in')});- document.getElementById('btn-out').addEventListener('click',()=>{stopLoop();_trigger('out')});- document.getElementById('btn-rst').addEventListener('click',()=>{stopLoop();clearTimeout(animTimer);card.classList.remove('in','out');stEl.textContent='hidden'});- loopTog.addEventListener('change',()=>{looping=loopTog.checked;if(looping&&motionOk)loop();else stopLoop()});- document.querySelectorAll('#bounce-seg button').forEach(b=>b.addEventListener('click',()=>{- document.querySelectorAll('#bounce-seg button').forEach(x=>x.classList.remove('on'));b.classList.add('on');- bounces=+b.dataset.b;buildKF(+ovSl.value,bounces);- }));- ovSl.addEventListener('input',()=>{ovV.textContent=ovSl.value+'%';buildKF(+ovSl.value,bounces)});- durSl.addEventListener('input',()=>{dur=+durSl.value;durV.textContent=dur+'ms';document.documentElement.style.setProperty('--dur',dur+'ms')});- fadeTog.addEventListener('change',()=>buildKF(+ovSl.value,bounces));- buildKF(60,1);+ document.getElementById('btn-play').addEventListener('click',play);+ loopTog.addEventListener('change',()=>{if(loopTog.checked)play()});+ 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('strength-seg',d=>{strength=+d.strength});+ choices('bounces-seg',d=>{bounces=+d.bounces});+ choices('speed-seg',d=>{ms=+d.ms});+ apply();</script></body></html>diff --git a/index.html b/index.htmlindex 4d539da9..693918b2 100644--- a/index.html+++ b/index.html@@ -923,7 +923,7 @@ const CATS=[['word-by-word-reveal','Word-by-Word Reveal','Words appear one after another at a reading pace. Best for quotes and intros.'],['blur-in','Blur In','Comes into focus from a blur, like a camera. Best for featured cards and photos.'],['flip-in','Flip In','Swings into view in 3D, like a card turning over. Best for cards and tiles.'],- ['bounce-in','Bounce In','Overshoots final position then springs back — explicit @keyframes waypoints, not easing alone.'],+ ['bounce-in','Bounce In','Lands with a springy bounce. Best for badges and success messages.'],['rotate-in','Rotate In','Spins into place while it grows. Best for icons, stars and badges.'],]},