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 Flash / Light Leak Transition to the guided-steps page

matinfac84d9dfef5
diff --git a/animations/03-page-transitions/flash-transition/README.md b/animations/03-page-transitions/flash-transition/README.md
index 45f1de4a..d5e600ff 100644
--- a/animations/03-page-transitions/flash-transition/README.md
+++ b/animations/03-page-transitions/flash-transition/README.md
@@ -1,7 +1,7 @@
# Flash / Light Leak
## What it is
-A flash transition covers the screen with a colored overlay that peaks at full opacity, swaps the page content while it is hidden, then fades the overlay away to reveal the new scene. The eye reads the overexposure as a single continuous moment, so the underlying content swap is never seen. Cinema uses the same trick to hide edits inside a burst of light.
+A flash transition hides a page change inside a burst of light. A colored layer covers the page and rises to full strength, the page is swapped while it is covered, and the layer then fades away to reveal the new page. The eye reads it as one bright moment, so the swap itself is never seen — the same trick films use to hide a cut.
## When to use it
- Masking a cheap or instant content swap where a crossfade would look flat
@@ -18,26 +18,23 @@ function doTransition(prev, next) {
flashEl.style.opacity = intensity; // fade the flash up
setTimeout(() => {
// Peak — swap the page behind the opaque flash
- document.getElementById('p' + prev).classList.remove('active');
- document.getElementById('p' + next).classList.add('active');
- requestAnimationFrame(() => {
- flashEl.style.transition = `opacity ${flashOut}ms ease-out, filter ${flashOut}ms ease`;
- flashEl.style.opacity = '0'; // fade the flash down to reveal
- });
+ pages[prev].classList.remove('active');
+ pages[next].classList.add('active');
+ flashEl.style.transition = `opacity ${flashOut}ms ease-out, filter ${flashOut}ms ease`;
+ flashEl.style.opacity = '0'; // fade the flash down to reveal
}, flashIn);
}
```
-The swap is deferred to a `requestAnimationFrame` after the class change so the browser commits the new transition before starting the fade-out. An optional `blur()` filter applied during the flash softens the edge and sells the light-leak feel.
+The fade-out sets its own transition in the same step as the new opacity, so it runs over `flashOut` rather than `flashIn`. An optional `blur()` filter applied during the flash softens the edge and sells the light-leak feel.
## Key parameters
| Parameter | Default | Effect |
|-----------|---------|--------|
-| Flash-in duration | 200ms | Ramp to peak. Faster feels like a camera strobe; slower feels like a wash |
-| Flash-out duration | 320ms | Reveal ramp. Usually longer than the in, so the new page eases into view |
-| Intensity (peak opacity) | 1.00 | Below 1.0 lets the swap show through faintly — keep at 1.0 to fully hide it |
-| Flash color | white | White reads as overexposure; tinted (gold, cyan) reads as a stylized light leak |
-| Blur during flash | off | Adds a soft bloom to the peak, disguising the hard overlay edge |
+| Flash color | White | White reads as a camera flash; gold, cyan and red read as a colored light leak |
+| Speed | Normal | How fast the flash rises and fades: slow is 320ms up and 510ms down, normal 200ms and 320ms, fast 120ms and 190ms; the fade is always a little longer than the rise |
+| Flash strength | Full | How solid the flash gets: full hides the page change completely; strong (75%) and soft (50%) let it show through |
+| Blurs the flash | off | Softens the flash's edges into a glow |
## Production notes
- **Swap only at true peak.** If intensity drops below ~0.9 the content change becomes visible as a hard cut through the overlay. Keep peak opacity high, and only lower it deliberately for a see-through effect.
@@ -46,7 +43,7 @@ The swap is deferred to a `requestAnimationFrame` after the class change so the
- **Library equivalents.** The View Transitions API can reproduce this by animating a `::view-transition-group` with a flash-colored pseudo-element, though a dedicated overlay is simpler. GSAP timelines chain the fade-in, swap callback, and fade-out cleanly. Barba.js exposes `leave`/`enter` hooks that map directly onto the peak-and-reveal structure.
## See also
-- [Crossfade](../crossfade/) — the plain opacity blend this technique dresses up
-- [Dissolve](../dissolve/) — another overlay-masked swap, tiled instead of solid
-- [Blur Transition](../blur-transition/) — defocus rather than overexposure to hide the change
-- [Portal / Tunnel Zoom](../portal-zoom/) — a clip-path reveal that also masks the swap
+- [Crossfade Transition](../crossfade/) — the plain fade this dresses up
+- [Dissolve Transition](../dissolve/) — tiles hide the change instead
+- [Blur Transition](../blur-transition/) — a blur hides the change instead
+- [Portal / Tunnel Zoom](../portal-zoom/) — the next page opens out of a clicked circle
diff --git a/animations/03-page-transitions/flash-transition/index.html b/animations/03-page-transitions/flash-transition/index.html
index 8ad8c585..f019e62d 100644
--- a/animations/03-page-transitions/flash-transition/index.html
+++ b/animations/03-page-transitions/flash-transition/index.html
@@ -4,7 +4,7 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Flash / Light Leak Transition — Animation Handbook</title>
- <meta name="description" content="A colored flash peaks at full opacity, hides the page swap, then fades to reveal the new scene.">
+ <meta name="description" content="A burst of light hides the moment the page changes. Best for bold, lively sites.">
<link rel="canonical" href="https://matinmonshizadeh.github.io/animation-handbook/animations/03-page-transitions/flash-transition/">
<link rel="icon" type="image/png" sizes="96x96" href="../../../favicon.png">
<link rel="icon" type="image/svg+xml" href="../../../favicon.svg">
@@ -12,201 +12,271 @@
<meta property="og:type" content="article">
<meta property="og:site_name" content="Animation Handbook">
<meta property="og:title" content="Flash / Light Leak Transition — Animation Handbook">
- <meta property="og:description" content="A colored flash peaks at full opacity, hides the page swap, then fades to reveal the new scene.">
+ <meta property="og:description" content="A burst of light hides the moment the page changes. Best for bold, lively sites.">
<meta property="og:url" content="https://matinmonshizadeh.github.io/animation-handbook/animations/03-page-transitions/flash-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="Flash / Light Leak Transition — Animation Handbook">
- <meta name="twitter:description" content="A colored flash peaks at full opacity, hides the page swap, then fades to reveal the new scene.">
+ <meta name="twitter:description" content="A burst of light hides the moment the page changes. Best for bold, lively sites.">
<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": "Flash / Light Leak Transition", "name": "Flash / Light Leak Transition", "description": "A colored flash peaks at full opacity, hides the page swap, then fades to reveal the new scene.", "url": "https://matinmonshizadeh.github.io/animation-handbook/animations/03-page-transitions/flash-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, Flash / Light Leak Transition"}</script>
+ <script type="application/ld+json">{"@context": "https://schema.org", "@type": "TechArticle", "headline": "Flash / Light Leak Transition", "name": "Flash / Light Leak Transition", "description": "A burst of light hides the moment the page changes. Best for bold, lively sites.", "url": "https://matinmonshizadeh.github.io/animation-handbook/animations/03-page-transitions/flash-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, Flash / Light Leak 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;--flash-color:#ffffff;--flash-in:200ms;--flash-out:320ms}
+ :root{--bg:#0b0b0d;--ui-bg:#111114;--ui-border:rgba(255,255,255,.09);--ui-accent:#b98cff;--ui-text:#f4f4f2;--ui-muted:#8a8a92;--flash-color:#ffffff}
*,*::before,*::after{box-sizing:border-box;margin:0;padding:0}
- body{background:var(--bg);color:var(--ui-text);font-family:var(--mono);-webkit-font-smoothing:antialiased;padding:clamp(12px,3vw,24px)}
- header{margin-bottom:20px}
- header h1{font-family:var(--disp);font-weight:700;font-size:clamp(11px,1.8vw,15px);letter-spacing:-.01em}
- header p{font-size:clamp(10px,1.2vw,12px);color:var(--ui-muted);margin-top:4px}
- .layout{display:flex;gap:clamp(12px,2vw,24px);align-items:flex-start}
- .stage{flex:1;min-width:0;height:var(--stage-h);border:1px solid var(--ui-border);border-radius:8px;background:var(--bg);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:var(--mono);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;visibility:hidden}
.page.active{pointer-events:auto;visibility:visible}
/* Flash overlay */
#flash-overlay{position:absolute;inset:0;background:var(--flash-color);opacity:0;pointer-events:none;z-index:10;filter:blur(0)}
#flash-overlay.blur-on{filter:blur(8px)}
+ /* page content */
.pc{display:flex;flex-direction:column;justify-content:center;height:100%;padding:clamp(20px,4vw,40px);gap:14px}
- .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,40px);font-weight:bold;line-height:1.1}
.pp{font-size:13px;opacity:.55;line-height:1.7;max-width:340px}
.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}
- /* timeline */
- #tl{display:flex;gap:4px;align-items:center;margin-top:4px}
- #tl>div{flex:1;min-width:0}
- .tl-seg{flex:1;height:4px;border-radius:2px;background:var(--ui-border)}
- .tl-seg.on{background:var(--ui-accent)}
- .tl-lbl{font-size:8px;color:var(--ui-muted);text-align:center;margin-top:2px}
- 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)}
- .swatches{display:flex;gap:5px}
- .sw{width:26px;height:26px;border-radius:4px;cursor:pointer;border:2px solid transparent;flex-shrink:0}
- .sw.on{border-color:var(--ui-text)}
- .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}
- .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:var(--mono);font-size:10px;padding:14px 8px;border-radius:4px;cursor:pointer;width:100%;min-height:44px}
- @media(hover:hover){button.rst:hover{border-color:var(--ui-accent);color:var(--ui-accent)}.nav-btn:hover{border-color:var(--ui-accent)}}
- @media(max-width:600px){.layout{flex-direction:column;align-items:stretch}.stage{flex:0 0 auto;width:100%}aside{width:100%}:root{--stage-h:480px}.nav-btn{min-height:44px}.sw{width:44px;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}.pp{line-height:1.5}.pgrid,.pstat{margin-top:0}}
@media(prefers-reduced-motion:reduce){#flash-overlay{display:none}}
</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="../zoom-transition/" rel="prev" title="Previous">‹ Prev</a><a class="ah-hideSm" href="../blur-transition/" 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/flash-transition/index.html" target="_blank" rel="noopener noreferrer">Source ↗</a></span></div>
-<header>
- <h1>Flash / Light Leak Transition</h1>
- <p>A colored flash peaks at full opacity, hides the page swap, then fades to reveal the new scene.</p>
-</header>
-<div class="layout">
- <div class="stage">
- <nav class="mini-nav" id="nav"></nav>
- <div class="page-area" id="page-area">
- <div id="flash-overlay"></div>
+<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="../zoom-transition/" rel="prev" aria-label="Previous: Zoom 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>Zoom Transition</span></a><a href="../blur-transition/" rel="next" aria-label="Next: Blur Transition"><span><span class="hb-dir">Next: </span>Blur Transition</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.07 · Page Transitions</p>
+ <h1>Flash / Light Leak Transition</h1>
+ <p class="hb-lede">A burst of light hides the moment the page changes. Best for bold, lively sites.</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 id="flash-overlay"></div>
+ </div>
+ </div>
+ <div class="hb-player">
+ <button class="hb-play" type="button" id="btn-demo" data-hb-demo><svg class="hb-ic" viewBox="0 0 24 24" aria-hidden="true"><path d="M4.037 4.688a.495.495 0 0 1 .651-.651l16 6.5a.5.5 0 0 1-.063.947l-6.124 1.58a2 2 0 0 0-1.438 1.435l-1.579 6.126a.5.5 0 0 1-.947.063z"/></svg>Show me</button>
+ <button class="hb-play" type="button" id="btn-reset" data-hb-reset><svg class="hb-ic" viewBox="0 0 24 24" aria-hidden="true"><path d="M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"/><path d="M3 3v5h5"/></svg>Reset</button>
+ <label class="hb-toggle"><input class="hb-switch" type="checkbox" role="switch" id="slow-tog" data-hb-slowmo autocomplete="off"><span>Slow motion</span></label>
</div>
- </div>
- <aside>
- <p class="note">Flash transitions hide the swap inside an overexposure. When the flash fades, the new content has "always been there". Cinema uses this to hide cuts; web uses it to mask cheap page swaps with style.</p>
- <div class="lbl">State</div>
- <div class="kv"><span>Page</span><span class="v" id="cur-page">Home</span></div>
- <div class="kv"><span>Stage</span><span class="v" id="stage-val">idle</span></div>
- <div id="tl">
- <div><div class="tl-seg" id="tl0"></div><div class="tl-lbl">enter</div></div>
- <div><div class="tl-seg" id="tl1"></div><div class="tl-lbl">peak</div></div>
- <div><div class="tl-seg" id="tl2"></div><div class="tl-lbl">exit</div></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="div"></div>
- <div class="lbl">Flash color</div>
- <div class="swatches" id="swatches">
- <div class="sw on" data-c="#ffffff" style="background:#ffffff" tabindex="0" role="button" aria-label="White"></div>
- <div class="sw" data-c="#f5d78e" style="background:#f5d78e" tabindex="0" role="button" aria-label="Gold"></div>
- <div class="sw" data-c="#7ae8f0" style="background:#7ae8f0" tabindex="0" role="button" aria-label="Cyan"></div>
- <div class="sw" data-c="#f07a7a" style="background:#f07a7a" tabindex="0" role="button" aria-label="Red"></div>
+ <div class="hb-settings">
+ <div class="hb-setting">
+ <p class="hb-setting-name" id="color-lbl">Flash color</p>
+ <div class="swatches" id="color-sw" role="group" aria-labelledby="color-lbl">
+ <button type="button" class="on" aria-pressed="true" aria-label="White" data-c="#ffffff" style="background:#ffffff"></button>
+ <button type="button" aria-pressed="false" aria-label="Gold" data-c="#f5d78e" style="background:#f5d78e"></button>
+ <button type="button" aria-pressed="false" aria-label="Cyan" data-c="#7ae8f0" style="background:#7ae8f0"></button>
+ <button type="button" aria-pressed="false" aria-label="Red" data-c="#f07a7a" style="background:#f07a7a"></button>
+ </div>
+ <p class="hb-hint">White looks like a camera flash; colors, a light leak.</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-in="320" data-out="510" aria-pressed="false">Slow</button>
+ <button type="button" data-in="200" data-out="320" class="on" aria-pressed="true">Normal</button>
+ <button type="button" data-in="120" data-out="190" aria-pressed="false">Fast</button>
+ </div>
+ <p class="hb-hint">How fast the flash rises and fades.</p>
+ </div>
</div>
- <div><div class="lbl" id="in-lbl">Flash-in duration</div>
- <div class="sr"><input type="range" id="in-sl" aria-labelledby="in-lbl" min="50" max="400" value="200" step="10"><span class="sv" id="in-v">200ms</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">
+ <p class="hb-setting-name" id="strength-lbl">Flash strength</p>
+ <div class="seg" id="strength-seg" role="group" aria-labelledby="strength-lbl">
+ <button type="button" data-v="1" class="on" aria-pressed="true">Full</button>
+ <button type="button" data-v="0.75" aria-pressed="false">Strong</button>
+ <button type="button" data-v="0.5" aria-pressed="false">Soft</button>
+ </div>
+ <p class="hb-hint">Below full, the page change shows through.</p>
+ </div>
+ <div class="hb-setting">
+ <label class="hb-switch-row"><span>Blurs the flash</span><input class="hb-switch" type="checkbox" role="switch" id="blur-tog" autocomplete="off"></label>
+ <p class="hb-hint">Softens the flash's edges into a glow.</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><div class="lbl" id="out-lbl">Flash-out duration</div>
- <div class="sr"><input type="range" id="out-sl" aria-labelledby="out-lbl" min="100" max="600" value="320" step="10"><span class="sv" id="out-v">320ms</span></div>
+ <div class="hb-card">
+ <p class="hb-prompt">Add a flash transition to [the pages or scenes you want to switch between]. Cover the content with a full-size colored layer that rises to its peak, swap the page while it is covered, then fade the layer away to reveal the new page, like a burst of light hiding a cut in a film. At full strength the change is completely hidden. Let the fade-out take a little longer than the rise. Keep flashes rare, never several in one second, to protect people who are sensitive to flashing light. If the visitor has reduced motion turned on, switch pages with no flash. 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>
- <div><div class="lbl" id="int-lbl">Intensity (peak opacity)</div>
- <div class="sr"><input type="range" id="int-sl" aria-labelledby="int-lbl" min="30" max="100" value="100" step="5"><span class="sv" id="int-v">1.00</span></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>
- <label class="tog" for="blur-tog"><input type="checkbox" id="blur-tog"><span>Add blur during flash</span></label>
- <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>
+ <div class="hb-fit">
+ <h2>Good for</h2>
+ <ul class="hb-tags hb-good"><li>Product launches</li><li>Music and fashion</li><li>Photo stories</li></ul>
+ <h3>Avoid on</h3>
+ <ul class="hb-tags hb-avoid"><li>Frequent page changes</li><li>Calm 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:'#0a0f18',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. Every pixel considered.</p></div>`},
- {name:'Work',bg:'#0a180a',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:'#150a18',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><b>3</b><span>Continents</span></div></div></div>`},
+ {name:'Home',bg:'#0a0f18',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. Every pixel considered.</p></div>`},
+ {name:'Work',bg:'#0a180a',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:'#150a18',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><b>3</b><span>Continents</span></div></div></div>`},
];
- const nav=document.getElementById('nav'),area=document.getElementById('page-area');
- const flashEl=document.getElementById('flash-overlay');
- const curPage=document.getElementById('cur-page'),stageVal=document.getElementById('stage-val'),logEl=document.getElementById('trans-log');
- const inSl=document.getElementById('in-sl'),inV=document.getElementById('in-v');
- const outSl=document.getElementById('out-sl'),outV=document.getElementById('out-v');
- const intSl=document.getElementById('int-sl'),intV=document.getElementById('int-v');
- const blurTog=document.getElementById('blur-tog');
+ const nav=document.getElementById('nav'),area=document.getElementById('page-area'),flashEl=document.getElementById('flash-overlay');
+ const blurTog=document.getElementById('blur-tog'),slowTog=document.getElementById('slow-tog');
const motionOk=!window.matchMedia('(prefers-reduced-motion:reduce)').matches;
- let current=0,animating=false,flashIn=200,flashOut=320,intensity=1,history=[];
+ let current=0,animating=false,flashIn=200,flashOut=320,intensity=1,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;area.insertBefore(d,flashEl);
- 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.insertBefore(d,flashEl);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 setTL(i){for(let j=0;j<3;j++)document.getElementById('tl'+j).classList.toggle('on',j<=i)}
- 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);
+ }
+
+ function updateNav(n){navBtns.forEach((b,i)=>b.classList.toggle('active',i===n))}
+ // The resting state for page n, at once. A hidden page is also out of the Tab order and the accessibility tree (visibility).
+ function showPage(n){
+ pages.forEach((el,i)=>el.classList.toggle('active',i===n));
+ updateNav(n);
+ }
+ // The overlay back to nothing at once: no transition, no opacity, no blur, and no fade left running. The reflow
+ // commits this before a new flash starts, so a flash begun in the same task rises from nothing.
+ function clearFlash(){
+ flashEl.style.transition='none';
+ flashEl.style.opacity='0';
+ flashEl.classList.remove('blur-on');
+ flashEl.getAnimations().forEach(a=>a.cancel());
+ void flashEl.offsetWidth;
+ }
+
+ // Ends a flash: 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 and shows the resting state for `current`
+ function settle(){
+ timers.forEach(clearTimeout);timers=[];wayBack=0;afterMove=null;
+ animating=false;
+ clearFlash();
+ showPage(current);
+ }
- function navigate(next){
+ 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.classList.toggle('active',i===next));return;}
- animating=true;doTransition(prev,next);
+ const prev=current;current=next;updateNav(next);
+ afterMove=then||null;
+ if(!motionOk){showPage(next);finish();return}
+ animating=true;
+ const scale=slowTog.checked?3:1;
+ doTransition(prev,next,flashIn*scale,flashOut*scale);
}
- function doTransition(prev,next){
- stageVal.textContent='entering';setTL(0);
+ // flashIn and flashOut are in ms (three times as long in slow motion), read when the flash starts
+ function doTransition(prev,next,flashIn,flashOut){
flashEl.style.transition=`opacity ${flashIn}ms ease-in, filter ${flashIn}ms ease`;
flashEl.classList.toggle('blur-on',blurTog.checked);
flashEl.style.opacity=intensity;
- setTimeout(()=>{
- // Peak — swap behind flash
- stageVal.textContent='peak';setTL(1);
- document.getElementById('p'+prev).classList.remove('active');
- document.getElementById('p'+next).classList.add('active');
- // Flash out
- requestAnimationFrame(()=>{
- flashEl.style.transition=`opacity ${flashOut}ms ease-out, filter ${flashOut}ms ease`;
- flashEl.style.opacity='0';flashEl.classList.remove('blur-on');
- stageVal.textContent='exiting';setTL(2);
- setTimeout(()=>{stageVal.textContent='idle';setTL(-1);animating=false;},flashOut);
- });
+ later(()=>{
+ // Peak: swap behind the flash and fade it out in the same step
+ pages[prev].classList.remove('active');
+ pages[next].classList.add('active');
+ flashEl.style.transition=`opacity ${flashOut}ms ease-out, filter ${flashOut}ms ease`;
+ flashEl.style.opacity='0';flashEl.classList.remove('blur-on');
+ later(finish,flashOut);
},flashIn);
}
- document.querySelectorAll('.sw').forEach(s=>{
- s.addEventListener('click',()=>{
- document.querySelectorAll('.sw').forEach(x=>x.classList.remove('on'));s.classList.add('on');
- document.documentElement.style.setProperty('--flash-color',s.dataset.c);
- });
- s.addEventListener('keydown',e=>{if(e.key==='Enter'||e.key===' '){e.preventDefault();s.click();}});
- });
- inSl.addEventListener('input',()=>{flashIn=+inSl.value;inV.textContent=flashIn+'ms'});
- outSl.addEventListener('input',()=>{flashOut=+outSl.value;outV.textContent=flashOut+'ms'});
- intSl.addEventListener('input',()=>{intensity=intSl.value/100;intV.textContent=intensity.toFixed(2)});
- document.getElementById('rst-btn').addEventListener('click',()=>{
- if(animating)return;const p=current;current=0;updateNav(0);if(p!==0)addLog(p,0);
- flashEl.style.opacity='0';document.querySelectorAll('.page').forEach((el,i)=>el.classList.toggle('active',i===0));stageVal.textContent='idle';animating=false;
- });
+ // 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.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 flash already under way 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('color-sw',d=>{document.documentElement.style.setProperty('--flash-color',d.c)});
+ choices('speed-seg',d=>{flashIn=+d.in;flashOut=+d.out});
+ choices('strength-seg',d=>{intensity=+d.v});
+ 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 da1cd644..22db40a1 100644
--- a/index.html
+++ b/index.html
@@ -938,7 +938,7 @@ const CATS=[
['crossfade','Crossfade','The old page fades out as the new one fades in. Best for calm page changes.'],
['slide-transition','Slide Transition','Pages slide across, and going back slides the other way. Best for step flows.'],
['zoom-transition','Zoom Transition','The pages zoom as they swap, as if moving in depth. Best for opening details.'],
- ['flash-transition','Flash / Light Leak','A colored flash peaks at full opacity, hides the page swap, then fades to reveal the new scene.'],
+ ['flash-transition','Flash / Light Leak','A burst of light hides the moment the page changes. Best for bold, lively sites.'],
['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.'],
['portal-zoom','Portal / Tunnel Zoom','clip-path expands from a portal element\'s center, zooming the viewport into the next page.'],