Skip to content

176 web animation techniques, each a live demo with plain settings and a ready-made prompt for your AI assistant. No dependencies, no build step.

feat: move Elastic Transition to the guided-steps page

matin281541848665
diff --git a/animations/03-page-transitions/elastic-transition/README.md b/animations/03-page-transitions/elastic-transition/README.md
index c9511337..3423f691 100644
--- a/animations/03-page-transitions/elastic-transition/README.md
+++ b/animations/03-page-transitions/elastic-transition/README.md
@@ -1,7 +1,7 @@
# Elastic Transition
## What it is
-An elastic transition overshoots its target and settles back with a spring-like wobble instead of easing smoothly to a stop. The overshoot gives the motion a sense of weight and momentum, as if the page were pulled into place by a rubber band. It can be baked into CSS keyframes for cheapness, or simulated live in JavaScript for physical accuracy.
+An elastic transition slides the new page in so that it goes a little past its place and springs back before settling, instead of easing to a stop. The overshoot gives the movement weight, as if the page were pulled into place by a rubber band. The bounce can be planned ahead as a fixed path, which is cheap, or worked out live by simulating a spring, which feels physical.
## When to use it
- Playful, characterful interfaces where motion is part of the personality
@@ -10,11 +10,11 @@ An elastic transition overshoots its target and settles back with a spring-like
- Cases where a gesture may be interrupted — a live spring reacts to interruption, a keyframe cannot
## How it works
-This demo offers two modes. The CSS mode writes a `@keyframes` rule at runtime whose intermediate percentages push past the endpoint before returning, with the overshoot amount scaled by a control. The JS mode integrates an actual spring each frame: force equals `-stiffness × displacement − damping × velocity`, and the loop runs until both position and velocity fall below a threshold.
+This demo offers two ways to bounce. The planned path writes a `@keyframes` rule at runtime whose intermediate percentages push past the endpoint before returning, with the overshoot amount set by Bounce size. The live spring integrates an actual spring each frame: force equals `-stiffness × displacement − damping × velocity`, and the loop runs until both position and velocity fall below a threshold.
```js
function doSpring(prev, next) {
- let pos = -100, vel = 0, target = 0; // start off-screen right
+ let pos = 100, vel = 0, target = 0; // start off-screen right
let lastTime = null;
function tick(now) {
if (!lastTime) lastTime = now;
@@ -34,25 +34,24 @@ function doSpring(prev, next) {
}
```
-The `dt` is clamped to 50ms so a dropped frame or a backgrounded tab cannot inject a huge time step that would make the spring explode. Recorded positions are plotted to a small canvas so the overshoot-and-settle curve is visible.
+The `dt` is clamped to 50ms so a dropped frame or a backgrounded tab cannot inject a huge time step that would make the spring explode. On the demo page, Speed and Bounce size set both ways of bouncing: the planned path's length (1400, 900 or 550ms) and overshoot (30, 60 or 100), or the live spring's stiffness (70, 180 or 500) and damping. The damping values were found by running this loop at 60 frames a second, so the spring goes about as far past its place as the planned path does (about 3.6%, 7.2% and 12% of the width). Moving the spring one step per frame calms it more than the usual spring formula expects, so the values were measured rather than worked out.
## Key parameters
| Parameter | Default | Effect |
|-----------|---------|--------|
-| Mode | CSS keyframes | Keyframes are pre-baked and cheap; JS spring is physical and interruptible |
-| Overshoot intensity (CSS) | 60% | How far past the endpoint the keyframes push before settling |
-| Duration (CSS) | 900ms | Total keyframe length; longer lets more oscillations read |
-| Stiffness (JS) | 180 | Spring constant. Higher snaps to target faster with more overshoot |
-| Damping (JS) | 20 | Resistance. Low damping oscillates for longer; high damping settles flat |
+| How it bounces | Planned path | A planned path plays a bounce decided in advance, which is cheap; a live spring works out the movement on every frame, which feels physical and can react to interruptions |
+| Bounce size | Medium | How far the page goes past its place before settling; with a live spring, a bigger bounce means less damping, so it swings for longer |
+| Speed | Normal | How quickly it settles: on the planned path slow is 1400ms, normal 900ms and fast 550ms; with a live spring, a faster speed is a stiffer spring |
## Production notes
- **Stiffness and damping interact.** Below critical damping (`damping < 2√stiffness`) the spring oscillates; at or above it, it eases in without bounce. Tune the pair together — raising stiffness usually needs more damping to stay tasteful.
- **Clamp the time step.** Integrating with the raw frame delta is the classic spring bug: one long frame and `pos` shoots to infinity. The `Math.min(dt, 0.05)` clamp is not optional.
+- **Frame rate.** The demo moves its spring one step per frame, so how far it bounces depends on the frame rate: at 30 frames a second the small bounce hardly shows, and at 120 it is a little larger. A spring that steps by time instead — fixed small steps, as many as the time that has passed needs — bounces the same at any frame rate.
- **CSS keyframe overshoot can clip.** If a page translates fully to its edge before the bounce completes, the overshoot slides content out of the visible bounds. Reserve a little slack or let the container overflow during the animation.
- **Library equivalents.** Framer Motion and React Spring take `stiffness`/`damping` directly and handle interruption for you — reach for them rather than hand-rolling the integrator in production. GSAP's `elastic.out` easing approximates the CSS-keyframe feel. CSS `linear()` easing can now encode a sampled spring curve without JavaScript at all.
## See also
-- [Slide Transition](../slide-transition/) — the linear slide this adds spring physics to
-- [Zoom Transition](../zoom-transition/) — another transform that benefits from overshoot
-- [FLIP Technique](../flip-technique/) — pairs a springy easing with measured layout deltas
-- [Morph Transition](../morph-transition/) — shape change that also reads as physical
+- [Slide Transition](../slide-transition/) — the plain slide this adds a spring to
+- [Zoom Transition](../zoom-transition/) — pages move in depth instead
+- [FLIP Technique](../flip-technique/) — elements glide to their new places
+- [Morph Transition](../morph-transition/) — a shape changes between pages
diff --git a/animations/03-page-transitions/elastic-transition/index.html b/animations/03-page-transitions/elastic-transition/index.html
index 16d7b451..b7c7903c 100644
--- a/animations/03-page-transitions/elastic-transition/index.html
+++ b/animations/03-page-transitions/elastic-transition/index.html
@@ -4,7 +4,7 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Elastic Transition — Animation Handbook</title>
- <meta name="description" content="Spring physics cause overshoot and oscillation before settling — CSS keyframes or live JS simulation.">
+ <meta name="description" content="The new page slides in, goes too far and springs back. Best for playful apps.">
<link rel="canonical" href="https://matinmonshizadeh.github.io/animation-handbook/animations/03-page-transitions/elastic-transition/">
<link rel="icon" type="image/png" sizes="96x96" href="../../../favicon.png">
<link rel="icon" type="image/svg+xml" href="../../../favicon.svg">
@@ -12,244 +12,289 @@
<meta property="og:type" content="article">
<meta property="og:site_name" content="Animation Handbook">
<meta property="og:title" content="Elastic Transition — Animation Handbook">
- <meta property="og:description" content="Spring physics cause overshoot and oscillation before settling — CSS keyframes or live JS simulation.">
+ <meta property="og:description" content="The new page slides in, goes too far and springs back. Best for playful apps.">
<meta property="og:url" content="https://matinmonshizadeh.github.io/animation-handbook/animations/03-page-transitions/elastic-transition/">
<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="Elastic Transition — Animation Handbook">
- <meta name="twitter:description" content="Spring physics cause overshoot and oscillation before settling — CSS keyframes or live JS simulation.">
+ <meta name="twitter:description" content="The new page slides in, goes too far and springs back. Best for playful apps.">
<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": "Elastic Transition", "name": "Elastic Transition", "description": "Spring physics cause overshoot and oscillation before settling — CSS keyframes or live JS simulation.", "url": "https://matinmonshizadeh.github.io/animation-handbook/animations/03-page-transitions/elastic-transition/", "inLanguage": "en", "articleSection": "Page Transitions", "isPartOf": {"@type": "WebSite", "name": "Animation Handbook", "url": "https://matinmonshizadeh.github.io/animation-handbook/"}, "author": {"@type": "Person", "name": "matinmonshizadeh"}, "keywords": "web animation, CSS animation, Page Transitions, Elastic Transition"}</script>
+ <script type="application/ld+json">{"@context": "https://schema.org", "@type": "TechArticle", "headline": "Elastic Transition", "name": "Elastic Transition", "description": "The new page slides in, goes too far and springs back. Best for playful apps.", "url": "https://matinmonshizadeh.github.io/animation-handbook/animations/03-page-transitions/elastic-transition/", "inLanguage": "en", "articleSection": "Page Transitions", "isPartOf": {"@type": "WebSite", "name": "Animation Handbook", "url": "https://matinmonshizadeh.github.io/animation-handbook/"}, "author": {"@type": "Person", "name": "matinmonshizadeh"}, "keywords": "web animation, CSS animation, Page Transitions, Elastic Transition"}</script>
<style>
- @font-face{font-family:'Bricolage';src:url('../../../assets/fonts/brico-700.woff2') format('woff2');font-weight:700;font-display:swap}
- @font-face{font-family:'Bricolage';src:url('../../../assets/fonts/brico-800.woff2') format('woff2');font-weight:800;font-display:swap}
- @font-face{font-family:'PlexMono';src:url('../../../assets/fonts/plex-400.woff2') format('woff2');font-weight:400;font-display:swap}
- @font-face{font-family:'PlexMono';src:url('../../../assets/fonts/plex-500.woff2') format('woff2');font-weight:500;font-display:swap}
- :root{--bg:#0b0b0d;--ui-bg:#111114;--ui-border:rgba(255,255,255,.09);--ui-accent:#b98cff;--ui-text:#f4f4f2;--ui-muted:#77777e;--disp:'Bricolage','Arial Narrow',sans-serif;--mono:'PlexMono',ui-monospace,Menlo,Consolas,monospace;--stage-h:620px}
+ :root{--bg:#0b0b0d;--ui-bg:#111114;--ui-border:rgba(255,255,255,.09);--ui-accent:#b98cff;--ui-text:#f4f4f2;--ui-muted:#8a8a92}
*,*::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);overflow:hidden;display:flex;flex-direction:column}
+ .stage{display:flex;flex-direction:column;overflow:hidden;background:var(--bg);color:var(--ui-text)}
.mini-nav{display:flex;gap:6px;padding:10px 12px;background:var(--ui-bg);border-bottom:1px solid var(--ui-border);flex-shrink:0}
- .nav-btn{background:none;border:1px solid var(--ui-border);color:var(--ui-muted);font-family:monospace;font-size:10px;padding:6px 14px;border-radius:4px;cursor:pointer;min-height:36px}
+ .nav-btn{background:none;border:1px solid var(--ui-border);color:var(--ui-muted);font:inherit;font-size:13px;padding:0 12px;border-radius:4px;cursor:pointer;min-height:44px}
.nav-btn.active{border-color:var(--ui-accent);color:var(--ui-accent)}
+ @media(hover:hover){.nav-btn:hover{border-color:var(--ui-accent)}}
.page-area{flex:1;position:relative;overflow:hidden}
- .page{position:absolute;inset:0;pointer-events:none}
- .page.active{pointer-events:auto}
+ .page{position:absolute;inset:0;opacity:0;pointer-events:none}
+ .page.active{opacity:1;pointer-events:auto}
.pc{display:flex;flex-direction:column;justify-content:center;height:100%;padding:clamp(20px,4vw,40px);gap:12px}
- .pe{font-size:10px;text-transform:uppercase;letter-spacing:3px;opacity:.4}
+ .pe{font-size:10px;text-transform:uppercase;letter-spacing:3px;opacity:.6}
.ph{font-size:clamp(22px,3.5vw,36px);font-weight:bold;line-height:1.15}
.pp{font-size:12px;opacity:.6;line-height:1.65;max-width:320px}
.pgrid{display:grid;grid-template-columns:repeat(3,1fr);gap:6px;margin-top:4px}
.gi{background:rgba(255,255,255,.07);border:1px solid rgba(255,255,255,.1);border-radius:6px;padding:18px 12px;font-size:11px}
.pstat{display:flex;gap:20px;margin-top:4px}
.pstat b{display:block;font-size:clamp(18px,2.5vw,24px);color:var(--ui-accent)}
- .pstat span{font-size:9px;opacity:.4;text-transform:uppercase;letter-spacing:1px}
- canvas#spring-graph{background:var(--ui-bg);border:1px solid var(--ui-border);border-radius:4px;width:100%;height:60px;display:block}
- .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:36px}
- .seg button.on{border-color:var(--ui-accent);color:var(--ui-accent);background:rgba(185,140,255,.12)}
- 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)}
- .log{display:flex;flex-direction:column;gap:2px}
- .log-row{font-size:9px;color:var(--ui-muted)}
- button.rst{background:transparent;border:1px solid var(--ui-border);color:var(--ui-text);font-family:monospace;font-size:10px;padding:14px 8px;border-radius:4px;cursor:pointer;width:100%}
- @media(hover:hover){button.rst:hover{border-color:var(--ui-accent);color:var(--ui-accent)}.nav-btn:hover{border-color:var(--ui-accent)}}
- @media(max-width:600px){.layout{flex-direction:column}.stage{flex:none;width:100%}aside{width:100%}:root{--stage-h:480px}.nav-btn,.seg button,button.rst{min-height:44px}}
+ .pstat span{font-size:9px;opacity:.6;text-transform:uppercase;letter-spacing:1px}
+ /* Short windows leave the page area under 220px: tighter spacing keeps the tallest page inside it with room to spare */
+ @media(max-height:640px){.pc{gap:8px}.gi{padding:12px}}
@media(prefers-reduced-motion:reduce){.page{transition:none!important;animation:none!important}}
</style>
<style id="kf-style"></style>
-<style id="ah-inject">
-:root{--ah-bg:rgba(17,17,20,.82);--ah-line:rgba(255,255,255,.1);--ah-ink:#f4f4f2;--ah-muted:#9a9aa2;--ah-accent:#6ea8ff}
-body{padding-top:46px}
-.ah-bar{position:fixed;top:0;left:0;right:0;height:46px;z-index:2147483000;display:flex;align-items:center;justify-content:space-between;gap:10px;padding:0 clamp(10px,3vw,18px);background:var(--ah-bg);backdrop-filter:blur(10px);-webkit-backdrop-filter:blur(10px);border-bottom:1px solid var(--ah-line);font-family:ui-monospace,Menlo,Consolas,monospace;font-size:12px;box-sizing:border-box}
-.ah-bar a,.ah-bar button{color:var(--ah-muted);text-decoration:none;background:none;border:0;font:inherit;cursor:pointer;display:inline-flex;align-items:center;gap:6px;min-height:34px;padding:0 7px;border-radius:6px;transition:color .18s,background .18s;white-space:nowrap}
-.ah-bar a:hover,.ah-bar button:hover{color:var(--ah-ink)}
-.ah-home{color:var(--ah-ink);font-weight:600}
-.ah-actions{display:flex;align-items:center;gap:2px}
-.ah-sep{width:1px;height:16px;background:var(--ah-line);margin:0 4px}
-.ah-copied{color:var(--ah-accent)!important}
-@media(max-width:600px){.ah-bar .ah-hideSm{display:none}}
-@media print{.ah-bar{display:none}body{padding-top:0}}
-</style>
+ <link rel="stylesheet" href="../../../assets/css/demo-page.css?v=4">
+ <script src="../../../assets/js/demo-page.js?v=4" defer></script>
</head>
-<body>
-<div class="ah-bar" role="navigation" aria-label="Animation Handbook"><a class="ah-home" href="../../../">← Animation Handbook</a><span class="ah-actions"><a class="ah-hideSm" href="../blur-transition/" rel="prev" title="Previous">‹ Prev</a><a class="ah-hideSm" href="../portal-zoom/" rel="next" title="Next">Next ›</a><span class="ah-sep ah-hideSm"></span><button type="button" id="ah-copy" class="ah-hideSm">Copy source</button><a class="ah-hideSm" href="https://github.com/matinmonshizadeh/animation-handbook/blob/main/animations/03-page-transitions/elastic-transition/index.html" target="_blank" rel="noopener noreferrer">Source ↗</a></span></div>
-<header>
- <h1>Elastic Transition</h1>
- <p>Spring physics cause overshoot and oscillation before settling — CSS keyframes or live JS simulation.</p>
-</header>
-<div class="layout">
- <div class="stage">
- <nav class="mini-nav" id="nav"></nav>
- <div class="page-area" id="page-area"></div>
- </div>
- <aside>
- <p class="note">True spring physics (JS) adapts to interruptions. CSS keyframes are pre-baked but cheaper. Both produce overshoot and settle — the visual feel of weight.</p>
- <div class="lbl">State</div>
- <div class="kv"><span>Page</span><span class="v" id="cur-page">Home</span></div>
- <div class="div"></div>
- <div class="lbl">Mode</div>
- <div class="seg" id="mode-seg">
- <button data-m="css" class="on">CSS keyframes</button>
- <button data-m="spring">JS spring</button>
+<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="../blur-transition/" rel="prev" aria-label="Previous: Blur Transition"><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>Blur Transition</span></a><a href="../portal-zoom/" rel="next" aria-label="Next: Portal / Tunnel Zoom"><span><span class="hb-dir">Next: </span>Portal / Tunnel Zoom</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">03.09 · Page Transitions</p>
+ <h1>Elastic Transition</h1>
+ <p class="hb-lede">The new page slides in, goes too far and springs back. Best for playful apps.</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 Work or About at the top of the box, or press Show me.</p></div>
+ </div>
+ <div class="stage">
+ <nav class="mini-nav" id="nav" aria-label="Demo pages"></nav>
+ <div class="page-area" id="page-area"></div>
</div>
- <div id="css-opts">
- <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>
+ <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="mode-lbl">How it bounces</p>
+ <div class="seg" id="mode-seg" role="group" aria-labelledby="mode-lbl">
+ <button type="button" data-mode="css" class="on" aria-pressed="true">Planned path</button>
+ <button type="button" data-mode="spring" aria-pressed="false">Live spring</button>
+ </div>
+ <p class="hb-hint">A planned path is cheap; a live spring feels more physical.</p>
+ </div>
+ <div class="hb-setting">
+ <p class="hb-setting-name" id="size-lbl">Bounce size</p>
+ <div class="seg" id="size-seg" role="group" aria-labelledby="size-lbl">
+ <button type="button" data-size="0" aria-pressed="false">Small</button>
+ <button type="button" data-size="1" class="on" aria-pressed="true">Medium</button>
+ <button type="button" data-size="2" aria-pressed="false">Large</button>
+ </div>
+ <p class="hb-hint">How far the page goes past its place before settling.</p>
</div>
- <div><div class="lbl" id="dur-lbl">Duration</div>
- <div class="sr"><input type="range" id="dur-sl" aria-labelledby="dur-lbl" min="200" max="2000" value="900" step="50"><span class="sv" id="dur-v">900ms</span></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-speed="0" aria-pressed="false">Slow</button>
+ <button type="button" data-speed="1" class="on" aria-pressed="true">Normal</button>
+ <button type="button" data-speed="2" aria-pressed="false">Fast</button>
+ </div>
+ <p class="hb-hint">How quickly the page springs into place.</p>
</div>
</div>
- <div id="spring-opts" style="display:none;flex-direction:column;gap:10px">
- <div><div class="lbl" id="stiff-lbl">Stiffness</div>
- <div class="sr"><input type="range" id="stiff-sl" aria-labelledby="stiff-lbl" min="50" max="500" value="180" step="10"><span class="sv" id="stiff-v">180</span></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 elastic transition to [the pages or panels you want to move between]. The new page should slide in from the side, go a little past its place and spring back before settling, as if pulled by a rubber band, while the old page slides away. The bounce can be planned ahead as a fixed path, which is cheap, or worked out live with a simple spring, which can react if the visitor interrupts it; with a live spring, limit each time step so one slow frame cannot throw it off. If the visitor has reduced motion turned on, switch pages without movement. 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><div class="lbl" id="damp-lbl">Damping</div>
- <div class="sr"><input type="range" id="damp-sl" aria-labelledby="damp-lbl" min="5" max="50" value="20" step="1"><span class="sv" id="damp-v">20</span></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 class="lbl">Spring graph</div>
- <canvas id="spring-graph" height="60"></canvas>
</div>
- <div class="div"></div>
- <div class="lbl">History</div>
- <div class="log" id="trans-log"></div>
- <div class="div"></div>
- <button class="rst" id="rst-btn">← Return to Home</button>
- </aside>
-</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>Playful apps</li><li>Panels and drawers</li><li>Games</li></ul>
+ <h3>Avoid on</h3>
+ <ul class="hb-tags hb-avoid"><li>Formal sites</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 PAGES=[
- {name:'Home',bg:'linear-gradient(135deg,#0d1a2e,#192640)',html:`<div class="pc"><div class="pe">Creative Studio</div><h2 class="ph">Design without compromise.</h2><p class="pp">We craft digital products that earn attention and keep it.</p></div>`},
- {name:'Work',bg:'linear-gradient(135deg,#0d1f15,#152e1e)',html:`<div class="pc"><div class="pe">Selected Work</div><h2 class="ph">The Portfolio</h2><div class="pgrid">${['Atlas','Orbit','Prism','Lumen','Frame','Echo'].map(n=>`<div class="gi">${n}</div>`).join('')}</div></div>`},
- {name:'About',bg:'linear-gradient(135deg,#1f0d26,#2e1540)',html:`<div class="pc"><div class="pe">Our Story</div><h2 class="ph">Built on conviction.</h2><p class="pp">18 people who care unreasonably about craft. Independent since 2016.</p><div class="pstat"><div><b>140+</b><span>Projects</span></div><div><b>9</b><span>Years</span></div></div></div>`},
+ {name:'Home',bg:'linear-gradient(135deg,#0d1a2e,#192640)',html:`<div class="pc"><div class="pe">Creative Studio</div><p class="ph">Design without compromise.</p><p class="pp">We craft digital products that earn attention and keep it.</p></div>`},
+ {name:'Work',bg:'linear-gradient(135deg,#0d1f15,#152e1e)',html:`<div class="pc"><div class="pe">Selected Work</div><p class="ph">The Portfolio</p><div class="pgrid">${['Atlas','Orbit','Prism','Lumen','Frame','Echo'].map(n=>`<div class="gi">${n}</div>`).join('')}</div></div>`},
+ {name:'About',bg:'linear-gradient(135deg,#1f0d26,#2e1540)',html:`<div class="pc"><div class="pe">Our Story</div><p class="ph">Built on conviction.</p><p class="pp">18 people who care unreasonably about craft. Independent since 2016.</p><div class="pstat"><div><b>140+</b><span>Projects</span></div><div><b>9</b><span>Years</span></div></div></div>`},
];
- const nav=document.getElementById('nav'),area=document.getElementById('page-area');
- const curPage=document.getElementById('cur-page'),logEl=document.getElementById('trans-log');
- const ovSl=document.getElementById('ov-sl'),ovV=document.getElementById('ov-v');
- const durSl=document.getElementById('dur-sl'),durV=document.getElementById('dur-v');
- const stiffSl=document.getElementById('stiff-sl'),stiffV=document.getElementById('stiff-v');
- const dampSl=document.getElementById('damp-sl'),dampV=document.getElementById('damp-v');
+ const nav=document.getElementById('nav'),area=document.getElementById('page-area'),slowTog=document.getElementById('slow-tog');
const kfStyle=document.getElementById('kf-style');
- const canvas=document.getElementById('spring-graph');
- let current=0,animating=false,mode='css',dur=900,overshoot=60,stiffness=180,damping=20,history=[];
const motionOk=!window.matchMedia('(prefers-reduced-motion:reduce)').matches;
+ // Bounce size (Small, Medium, Large) and Speed (Slow, Normal, Fast) each pick one value for both ways of bouncing
+ const OVERSHOOT=[30,60,100],DURATION=[1400,900,550],STIFFNESS=[70,180,500];
+ // The live spring's damping for each size (row) and speed (column), found by running its loop so that it goes about as far past its place as the planned path does
+ const DAMPING=[[12,18,28],[10,16,25],[9,14,23]];
+ let current=0,animating=false,mode='css',size=1,speed=1,rafId=0,afterMove=null,wayBack=0,timers=[];
+ const pages=[],navBtns=[];
PAGES.forEach((p,i)=>{
- const d=document.createElement('div');d.className='page'+(i===0?' active':'');d.id='p'+i;d.style.background=p.bg;d.innerHTML=p.html;d.style.opacity=i===0?'1':'0';area.appendChild(d);
- const b=document.createElement('button');b.className='nav-btn'+(i===0?' active':'');b.textContent=p.name;b.addEventListener('click',()=>navigate(i));nav.appendChild(b);
+ const d=document.createElement('div');d.className='page';d.style.background=p.bg;d.innerHTML=p.html;area.appendChild(d);pages.push(d);
+ const b=document.createElement('button');b.type='button';b.className='nav-btn';b.textContent=p.name;
+ b.addEventListener('click',()=>navigate(i));nav.appendChild(b);navBtns.push(b);
});
- function updateNav(n){document.querySelectorAll('.nav-btn').forEach((b,i)=>b.classList.toggle('active',i===n));curPage.textContent=PAGES[n].name}
- function addLog(f,t){history.unshift(PAGES[f].name+' → '+PAGES[t].name);if(history.length>3)history.pop();logEl.innerHTML=history.map(l=>`<div class="log-row">${l}</div>`).join('')}
+ // Drops a timer's id once it fires, so `timers` only holds the ones still waiting.
+ function later(fn,wait){
+ const id=setTimeout(()=>{
+ const i=timers.indexOf(id);
+ if(i>-1)timers.splice(i,1);
+ fn();
+ },wait);
+ timers.push(id);
+ return id;
+ }
+ function cancel(id){
+ clearTimeout(id);
+ const i=timers.indexOf(id);
+ if(i>-1)timers.splice(i,1);
+ }
+ // The planned path: keyframes written for each transition; ov (30, 60 or 100) scales how far past its place the page goes
function buildKF(ov){
- const t=ov/100,os=t,un=t;
+ const t=ov/100;
kfStyle.textContent=`@keyframes elastic-in{
0%{transform:translateX(100%);opacity:0}
5%{opacity:1}
- 55%{transform:translateX(${-os*12}%)}
- 75%{transform:translateX(${un*4}%)}
+ 55%{transform:translateX(${-t*12}%)}
+ 75%{transform:translateX(${t*4}%)}
88%{transform:translateX(${-t*1.5}%)}
100%{transform:translateX(0);opacity:1}
}
@keyframes elastic-out{
0%{transform:translateX(0);opacity:1}
- 40%{transform:translateX(${os*6}%)}
+ 40%{transform:translateX(${t*6}%)}
100%{transform:translateX(-100%);opacity:0}
}`;
}
- function navigate(next){
+ function updateNav(n){navBtns.forEach((b,i)=>b.classList.toggle('active',i===n))}
+ // One page's resting look: its class alone shows or hides it, with nothing left over from a transition (its background stays)
+ function rest(el,on){
+ el.classList.toggle('active',on);
+ el.style.animation='';el.style.transition='';el.style.transform='';el.style.opacity='';
+ }
+ // The resting state for page n, at once. Running animations are cancelled too, so no tail of the last movement shows.
+ function showPage(n){
+ pages.forEach((el,i)=>{rest(el,i===n);el.getAnimations().forEach(a=>a.cancel())});
+ updateNav(n);
+ }
+
+ // Ends a transition: the demo is idle again, and a Show me run goes on to its next step
+ function finish(){
+ animating=false;
+ const then=afterMove;afterMove=null;
+ if(then)then();
+ }
+ // Stops everything at once (timers, the spring's frames, the run's next step) and shows the resting state for `current`
+ function settle(){
+ timers.forEach(clearTimeout);timers=[];wayBack=0;afterMove=null;
+ if(rafId){cancelAnimationFrame(rafId);rafId=0}
+ animating=false;
+ showPage(current);
+ }
+
+ function navigate(next,then){
if(next===current||animating)return;
- const prev=current;current=next;updateNav(next);addLog(prev,next);
- if(!motionOk){document.querySelectorAll('.page').forEach((el,i)=>{el.style.opacity=i===next?'1':'0';el.classList.toggle('active',i===next)});return;}
+ const prev=current;current=next;updateNav(next);
+ afterMove=then||null;
+ if(!motionOk){showPage(next);finish();return}
animating=true;
- mode==='css'?doCSS(prev,next):doSpring(prev,next);
+ const k=slowTog.checked?3:1; // read when the transition starts; slow motion triples its movements and the timers that wait for them
+ if(mode==='css')doCSS(pages[prev],pages[next],OVERSHOOT[size],DURATION[speed]*k);
+ else doSpring(pages[prev],pages[next],k,STIFFNESS[speed],DAMPING[size][speed]);
}
- function doCSS(prev,next){
+ // Planned path: the old page's keyframes carry it away, the new page's carry it in past its place and back; d is their length in ms
+ function doCSS(o,n,overshoot,d){
buildKF(overshoot);
- const o=document.getElementById('p'+prev),n=document.getElementById('p'+next);
- o.style.animation=`elastic-out ${dur}ms ease forwards`;
- n.style.opacity='0';n.style.transform='translateX(100%)';n.style.animation='none';
- requestAnimationFrame(()=>requestAnimationFrame(()=>{
- n.classList.add('active');n.style.animation=`elastic-in ${dur}ms ease forwards`;
- setTimeout(()=>{
- o.classList.remove('active');o.style.cssText='';o.style.background=PAGES[prev].bg;o.style.opacity='0';
- n.style.cssText='';n.style.background=PAGES[next].bg;n.style.opacity='1';animating=false;
- },dur+50);
- }));
+ n.style.transform='translateX(100%)';
+ void n.offsetWidth; // commit the start off-screen before the animations begin
+ o.style.animation=`elastic-out ${d}ms ease forwards`;
+ n.classList.add('active');n.style.animation=`elastic-in ${d}ms ease forwards`;
+ later(()=>{rest(o,false);rest(n,true);finish()},d+50);
}
- function doSpring(prev,next){
- const o=document.getElementById('p'+prev),n=document.getElementById('p'+next);
- // Slide out current page simply
- o.style.transition=`transform 300ms ease-in, opacity 300ms ease-in`;
+ // Live spring: the old page slides away simply, the new one is pulled in from the right by a spring worked out on every frame
+ function doSpring(o,n,k,stiffness,damping){
+ const out=300*k;
+ o.style.transition=`transform ${out}ms ease-in, opacity ${out}ms ease-in`;
o.style.transform='translateX(-40%)';o.style.opacity='0';
- // Spring in new page from right
- let pos=100,vel=0,target=0;
- n.style.opacity='1';n.style.transform=`translateX(${pos}%)`;n.classList.add('active');
- const positions=[];
- let rafId,lastTime=null;
+ let pos=100,vel=0,target=0,lastTime=null;
+ n.style.transform=`translateX(${pos}%)`;n.classList.add('active');
function tick(now){
if(!lastTime)lastTime=now;
- const dt=Math.min((now-lastTime)/1000,0.05);lastTime=now;
+ const dt=Math.min((now-lastTime)/1000,0.05)/k; // the 50ms limit first, then a third of the step in slow motion
+ lastTime=now;
const f=-stiffness*(pos-target)-damping*vel;
vel+=f*dt;pos+=vel*dt;
- positions.push(pos);
n.style.transform=`translateX(${pos.toFixed(2)}%)`;
- if(Math.abs(pos-target)<0.5&&Math.abs(vel)<0.5){
- n.style.transform='';drawGraph(positions);
- o.classList.remove('active');o.style.cssText='';o.style.background=PAGES[prev].bg;o.style.opacity='0';
- n.style.cssText='';n.style.background=PAGES[next].bg;n.style.opacity='1';animating=false;
- }else rafId=requestAnimationFrame(tick);
+ if(Math.abs(pos-target)<0.5&&Math.abs(vel)<0.5){rafId=0;rest(o,false);rest(n,true);finish()}
+ else rafId=requestAnimationFrame(tick);
}
- setTimeout(()=>{lastTime=null;rafId=requestAnimationFrame(tick)},100);
+ later(()=>{rafId=requestAnimationFrame(tick)},100*k);
}
- function drawGraph(positions){
- const ctx=canvas.getContext('2d');const w=canvas.offsetWidth||200,h=60;
- canvas.width=w;canvas.height=h;
- ctx.fillStyle='#111114';ctx.fillRect(0,0,w,h);
- ctx.strokeStyle='rgba(255,255,255,.09)';ctx.beginPath();ctx.moveTo(0,h/2);ctx.lineTo(w,h/2);ctx.stroke();
- ctx.strokeStyle='#b98cff';ctx.beginPath();
- const min=Math.min(...positions),max=Math.max(...positions),range=max-min||1;
- positions.forEach((p,i)=>{
- const x=i/positions.length*w,y=h-((p-min)/range*(h-8)+4);
- i===0?ctx.moveTo(x,y):ctx.lineTo(x,y);
- });
- ctx.stroke();
+ // Show me: one visit to the next page, a hold of 1200ms, and the way back to where the run started
+ function showMe(){
+ settle();
+ const start=current;
+ navigate((start+1)%PAGES.length,()=>{wayBack=later(()=>{wayBack=0;navigate(start)},1200)});
}
+ function reset(){current=0;settle()}
- document.querySelectorAll('#mode-seg button').forEach(b=>b.addEventListener('click',()=>{
- document.querySelectorAll('#mode-seg button').forEach(x=>x.classList.remove('on'));b.classList.add('on');
- mode=b.dataset.m;
- document.getElementById('css-opts').style.display=mode==='css'?'flex':'none';
- document.getElementById('css-opts').style.flexDirection='column';document.getElementById('css-opts').style.gap='10px';
- document.getElementById('spring-opts').style.display=mode==='spring'?'flex':'none';
- }));
- ovSl.addEventListener('input',()=>{overshoot=+ovSl.value;ovV.textContent=overshoot+'%'});
- durSl.addEventListener('input',()=>{dur=+durSl.value;durV.textContent=dur+'ms'});
- stiffSl.addEventListener('input',()=>{stiffness=+stiffSl.value;stiffV.textContent=stiffness});
- dampSl.addEventListener('input',()=>{damping=+dampSl.value;dampV.textContent=damping});
- document.getElementById('rst-btn').addEventListener('click',()=>{
- if(animating)return;const p=current;current=0;updateNav(0);if(p!==0)addLog(p,0);
- document.querySelectorAll('.page').forEach((el,i)=>{el.classList.toggle('active',i===0);el.style.cssText='';el.style.background=PAGES[i].bg;el.style.opacity=i===0?'1':'0'});animating=false;
- });
- buildKF(60);
+ document.getElementById('btn-demo').addEventListener('click',showMe);
+ document.getElementById('btn-reset').addEventListener('click',reset);
+ // The visitor took over: cancel what the run has not started yet. A page already moving finishes on its own.
+ document.addEventListener('hb:input',()=>{afterMove=null;cancel(wayBack);wayBack=0});
+
+ 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('mode-seg',d=>{mode=d.mode});
+ choices('size-seg',d=>{size=+d.size});
+ choices('speed-seg',d=>{speed=+d.speed});
+ showPage(0);
</script>
-<script>(function(){var b=document.getElementById("ah-copy");if(!b)return;b.addEventListener("click",function(){fetch(location.href).then(function(r){return r.text();}).catch(function(){return document.documentElement.outerHTML;}).then(function(t){return navigator.clipboard.writeText(t);}).then(function(){b.textContent="Copied!";b.classList.add("ah-copied");setTimeout(function(){b.textContent="Copy source";b.classList.remove("ah-copied");},1500);}).catch(function(){b.textContent="Copy failed";setTimeout(function(){b.textContent="Copy source";},1500);});});})();</script>
</body>
</html>
diff --git a/index.html b/index.html
index f1996a9f..fe4f47f5 100644
--- a/index.html
+++ b/index.html
@@ -940,7 +940,7 @@ const CATS=[
['zoom-transition','Zoom Transition','Three scale variants — zoom-in, zoom-out, pull-through — each implying different spatial depth.'],
['flash-transition','Flash / Light Leak','A colored flash peaks at full opacity, hides the page swap, then fades to reveal the new scene.'],
['blur-transition','Blur Transition','Current page blurs and fades out, then new page sharpens in — a defocus wipe between scenes.'],
- ['elastic-transition','Elastic Transition','Spring physics cause overshoot before settling — CSS keyframes or live JS spring simulation.'],
+ ['elastic-transition','Elastic Transition','The new page slides in, goes too far and springs back. Best for playful apps.'],
['portal-zoom','Portal / Tunnel Zoom','clip-path expands from a portal element\'s center, zooming the viewport into the next page.'],
['dissolve','Dissolve','Random tiles fade at staggered delays — a non-uniform wipe that reads as dissolving rather than fading.'],
['flip-technique','FLIP Technique','First-Last-Invert-Play — CSS layout changes animated seamlessly by measuring position deltas.'],