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

matin6746f4b5ff98
diff --git a/animations/07-ambient-background/light-leak/README.md b/animations/07-ambient-background/light-leak/README.md
index 9b4cb335..d6dcdb40 100644
--- a/animations/07-ambient-background/light-leak/README.md
+++ b/animations/07-ambient-background/light-leak/README.md
@@ -1,7 +1,7 @@
# Light Leak
## What it is
-A light leak is a warm, glowing gradient that periodically sweeps across the screen from a corner, simulating the accidental light exposure that occurred in film cameras when the body seal was imperfect and stray light reached the film. In physical photography, light leaks happen at random intervals with varying intensity. Digitally recreating that randomness — irregular timing, varying peak opacity — is what makes the effect believable rather than mechanical.
+A light leak is a warm glow that washes in from the edge of the frame and fades away again, like the stray light that reached the film when an old camera was not sealed properly. Real leaks happen at random and vary in strength, so the effect waits a random gap between leaks and peaks at a slightly different brightness each time; evenly timed leaks look like a machine, not a film camera.
## When to use it
- Editorial and photography portfolio sites where an analog aesthetic is intentional
@@ -16,25 +16,23 @@ The leak is an absolutely-positioned overlay with a radial gradient pointing fro
const leak = document.querySelector('.leak');
function flash() {
- const duration = 800 + Math.random() * 1200; // 800ms to 2000ms sweep
- const intensity = 0.3 + Math.random() * 0.4; // 0.3 to 0.7 opacity
-
- leak.style.transition = `opacity ${duration}ms ease-in-out`;
- leak.style.opacity = intensity;
+ leak.style.setProperty('--leak-dur', fadeMs + 'ms'); // the fade time, read by the CSS transition
+ // each leak peaks a little below the chosen brightness, at random
+ leak.style.setProperty('--leak-peak', (brightness * (0.75 + Math.random() * 0.25)).toFixed(3));
+ leak.classList.add('active'); // fades in over --leak-dur
+ setTimeout(fadeOut, fadeMs + 200); // hold the peak for 200ms
+}
- // Fade back out after peak, at same speed
- setTimeout(() => {
- leak.style.opacity = 0;
- scheduleNext(); // schedule the next leak irregularly
- }, duration);
+function fadeOut() {
+ leak.classList.remove('active'); // fades out over --leak-dur
+ setTimeout(flash, fadeMs + randomGap()); // a random dark gap before the next leak
}
-function scheduleNext() {
- const delay = 2000 + Math.random() * 10000; // 2s to 12s between leaks
- setTimeout(flash, delay);
+function randomGap() {
+ return (minGap + Math.random() * (maxGap - minGap)) * 1000; // 1–3s in the demo
}
-scheduleNext();
+setTimeout(flash, randomGap());
```
**Gradient for a top-left corner leak**:
@@ -44,6 +42,7 @@ scheduleNext();
position: absolute; inset: 0;
pointer-events: none;
opacity: 0;
+ transition: opacity var(--leak-dur) ease-in-out;
background: radial-gradient(
ellipse at -10% -10%,
rgba(255, 165, 50, 0.9) 0%,
@@ -52,15 +51,19 @@ scheduleNext();
transparent 70%
);
}
+
+.leak.active { opacity: var(--leak-peak); }
```
## Key parameters
| Parameter | Default | Effect |
|-----------|---------|--------|
-| Min delay | 2s | The minimum gap between leaks — too short and it feels like strobe |
-| Max delay | 12s | The maximum gap — above 20s users may forget the effect exists |
-| Sweep duration | 1–2s | The speed of one fade-in/out cycle |
-| Peak intensity | 0.3–0.7 | Varies per leak to feel organic; consistent intensity = mechanical |
+| Comes from | Top left | The corner the glow spills in from, or a band of light down the middle |
+| Time between leaks | Medium | The random dark gap between one leak and the next: short is 0.5–1.5s, medium 1–3s and long 3–8s |
+| Speed | Normal | How long each leak takes to fade in, and again to fade out: slow is 2s, normal 1.2s and fast 0.7s |
+| Brightness | Medium | How strong the glow gets: dim is 30%, medium 55% and bright 80%; each leak peaks a little below this, at random |
+| Color | Amber | Amber is the classic leak; gold, rose and magenta are warm too, and cyan looks like a cooler film stock |
+| Floating light spots | off | Soft spots of light drift up and fade after each leak |
## Production notes
- **Irregularity is the entire effect**: a light leak that fires every 8 seconds at 0.5 opacity reads as a CSS animation loop, not a film defect. Randomizing both the delay and intensity per occurrence is what creates the analog feel.
@@ -70,6 +73,6 @@ scheduleNext();
- **Framer Motion**: `<motion.div animate={{ opacity: [0, 0.5, 0] }} transition={{ times: [0, 0.5, 1], duration: 1.5 }}` on each flash. Trigger it imperatively with `controls.start()` from JavaScript.
## See also
-- [Grain Overlay](../grain-overlay/) — film grain texture as the companion analog effect
-- [Scanline](../scanline/) — CRT-era retro overlay (different era, similar "analog" motivation)
-- [Glassmorphism Animated](../../06-3d-advanced/glassmorphism-animated/) — light-over-glass effect for digital UI
+- [Grain / Film Noise Overlay](../grain-overlay/) — the film grain that pairs with a leak
+- [Scanline Effect](../scanline/) — dark lines over the page, like an old monitor
+- [Glassmorphism Animated](../../06-3d-advanced/glassmorphism-animated/) — frosted glass over moving color
diff --git a/animations/07-ambient-background/light-leak/index.html b/animations/07-ambient-background/light-leak/index.html
index 764de95c..b8502576 100644
--- a/animations/07-ambient-background/light-leak/index.html
+++ b/animations/07-ambient-background/light-leak/index.html
@@ -4,7 +4,7 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Light Leak — Animation Handbook</title>
- <meta name="description" content="Warm light sweeps across the scene with random irregular timing — evoking accidental film camera flares.">
+ <meta name="description" content="Warm light washes in from a corner at random times. Best for photo sites.">
<link rel="canonical" href="https://matinmonshizadeh.github.io/animation-handbook/animations/07-ambient-background/light-leak/">
<link rel="icon" type="image/png" sizes="96x96" href="../../../favicon.png">
<link rel="icon" type="image/svg+xml" href="../../../favicon.svg">
@@ -12,196 +12,247 @@
<meta property="og:type" content="article">
<meta property="og:site_name" content="Animation Handbook">
<meta property="og:title" content="Light Leak — Animation Handbook">
- <meta property="og:description" content="Warm light sweeps across the scene with random irregular timing — evoking accidental film camera flares.">
+ <meta property="og:description" content="Warm light washes in from a corner at random times. Best for photo sites.">
<meta property="og:url" content="https://matinmonshizadeh.github.io/animation-handbook/animations/07-ambient-background/light-leak/">
<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="Light Leak — Animation Handbook">
- <meta name="twitter:description" content="Warm light sweeps across the scene with random irregular timing — evoking accidental film camera flares.">
+ <meta name="twitter:description" content="Warm light washes in from a corner at random times. Best for photo 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": "Light Leak", "name": "Light Leak", "description": "Warm light sweeps across the scene with random irregular timing — evoking accidental film camera flares.", "url": "https://matinmonshizadeh.github.io/animation-handbook/animations/07-ambient-background/light-leak/", "inLanguage": "en", "articleSection": "Ambient & Background", "isPartOf": {"@type": "WebSite", "name": "Animation Handbook", "url": "https://matinmonshizadeh.github.io/animation-handbook/"}, "author": {"@type": "Person", "name": "matinmonshizadeh"}, "keywords": "web animation, CSS animation, Ambient & Background, Light Leak"}</script>
+ <script type="application/ld+json">{"@context": "https://schema.org", "@type": "TechArticle", "headline": "Light Leak", "name": "Light Leak", "description": "Warm light washes in from a corner at random times. Best for photo sites.", "url": "https://matinmonshizadeh.github.io/animation-handbook/animations/07-ambient-background/light-leak/", "inLanguage": "en", "articleSection": "Ambient & Background", "isPartOf": {"@type": "WebSite", "name": "Animation Handbook", "url": "https://matinmonshizadeh.github.io/animation-handbook/"}, "author": {"@type": "Person", "name": "matinmonshizadeh"}, "keywords": "web animation, CSS animation, Ambient & Background, Light Leak"}</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:#ffce5a;--ui-text:#f4f4f2;--ui-muted:#77777e;--disp:'Bricolage','Arial Narrow',sans-serif;--mono:'PlexMono',ui-monospace,Menlo,Consolas,monospace;--stage-h:620px;--leak-dur:1.2s;--leak-op:.55}
+ :root{--ui-accent:#ffce5a;--leak-dur:1.2s;--leak-op:.55}
*,*::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;overflow:hidden;position:relative;background:linear-gradient(135deg,#040608,#08111a)}
+ .stage{position:relative;overflow:hidden;background:linear-gradient(135deg,#040608,#08111a)}
/* Scene content */
.scene{position:absolute;inset:0;display:flex;align-items:center;justify-content:center;padding:32px}
.photo-mock{width:100%;max-width:300px;height:200px;border-radius:8px;background:linear-gradient(135deg,#0d1a2e,#1a2e3a);border:1px solid rgba(255,255,255,.08);display:flex;align-items:flex-end;padding:16px}
- .photo-cap{font-size:11px;color:rgba(255,255,255,.5)}
- /* Leak overlay */
+ .photo-cap{font-size:11px;color:rgba(255,255,255,.72)}
+ /* Leak overlay: the fade is a CSS transition; the gradient itself is painted by applyColor() in JS,
+ since the leak colour is live-editable. The dir-* class is the state flag. */
.leak{position:absolute;inset:0;pointer-events:none;z-index:5;opacity:0;transition:opacity var(--leak-dur) ease-in-out}
.leak.active{opacity:var(--leak-peak,var(--leak-op))}
- /* Direction variants: the gradient itself is painted by applyColor() in JS,
- since the leak colour is live-editable. The dir-* class is the state flag. */
- /* Bokeh blobs */
- .bokeh{position:absolute;border-radius:50%;pointer-events:none;z-index:4;animation:bokeh-float linear infinite;filter:blur(8px);display:none}
+ /* Light spots: each floats up once and removes itself when it ends. "both" keeps a spot hidden during its start delay. */
+ .bokeh{position:absolute;border-radius:50%;pointer-events:none;z-index:4;animation:bokeh-float linear both;filter:blur(8px)}
@keyframes bokeh-float{from{transform:translateY(100%) scale(0);opacity:0}20%{opacity:.8}80%{opacity:.5}to{transform:translateY(-120%) scale(1.5);opacity:0}}
- /* Card */
- .fg-card{position:absolute;bottom:28px;left:50%;transform:translateX(-50%);width:clamp(180px,55%,280px);background:rgba(4,6,8,.7);backdrop-filter:blur(10px);-webkit-backdrop-filter:blur(10px);border:1px solid rgba(255,255,255,.1);border-radius:10px;padding:16px 18px;z-index:10}
- .fg-eyebrow{font-size:9px;letter-spacing:2px;text-transform:uppercase;color:rgba(255,165,50,.7);margin-bottom:6px}
- .fg-title{font-family:Georgia,serif;font-size:clamp(13px,1.8vw,17px);color:#fff;margin-bottom:6px;font-style:italic}
- .fg-body{font-size:10px;color:rgba(255,255,255,.45);line-height:1.6}
- 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:44px;text-align:right;color:var(--ui-text)}
- select{background:var(--ui-bg);border:1px solid var(--ui-border);color:var(--ui-text);font-family:monospace;font-size:10px;padding:8px 6px;border-radius:4px;width:100%;min-height:44px}
- .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}
- input[type=color]{border:none;background:none;width:44px;height:30px;cursor:pointer;border-radius:4px;padding:0}
- 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)}}
- @media(max-width:600px){.layout{flex-direction:column}.stage{flex:none;width:100%}aside{width:100%}:root{--stage-h:420px}
- input[type=color]{height:44px}.tog input{width:44px;height:44px}}
- /* Reduced motion: no repeated flash — the leak sits steady and dim instead. */
- @media(prefers-reduced-motion:reduce){.leak,.leak.active{transition:none!important;opacity:calc(var(--leak-op) * .5)}.bokeh{animation-duration:60s!important}}
</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=3">
+ <script src="../../../assets/js/demo-page.js?v=3" 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="../scanline/" rel="prev" title="Previous">‹ Prev</a><a class="ah-hideSm" href="../starfield/" 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/07-ambient-background/light-leak/index.html" target="_blank" rel="noopener noreferrer">Source ↗</a></span></div>
-<header>
- <h1>Light Leak</h1>
- <p>Warm light sweeps across the scene with random irregular timing — evoking accidental film camera flares.</p>
-</header>
-<div class="layout">
- <div class="stage" id="stage">
- <div class="scene">
- <div class="photo-mock"><div class="photo-cap">ambient · atmospheric · analog warmth</div></div>
+<body class="hb" data-hb-kind="loop">
+<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="../scanline/" rel="prev" aria-label="Previous: Scanline Effect"><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>Scanline Effect</span></a><a href="../starfield/" rel="next" aria-label="Next: Starfield / Space Particles"><span><span class="hb-dir">Next: </span>Starfield / Space Particles</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">07.06 · Ambient &amp; Background</p>
+ <h1>Light Leak</h1>
+ <p class="hb-lede">Warm light washes in from a corner at random times. Best for photo 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">Watch it</h2><p>Leaks come at random, a few seconds apart. Pause it to look closely, or turn on slow motion to see each leak fade.</p></div>
+ </div>
+ <div class="stage" id="stage">
+ <div class="scene">
+ <div class="photo-mock"><div class="photo-cap">ambient · atmospheric · analog warmth</div></div>
+ </div>
+ <div class="leak dir-tl" id="leak" aria-hidden="true"></div>
+ </div>
+ <div class="hb-player">
+ <button class="hb-play" type="button" id="btn-pause" data-hb-pause="css" data-state="playing"><svg class="hb-ic hb-i-pause" viewBox="0 0 24 24" aria-hidden="true"><rect x="6" y="4" width="4" height="16" rx="1"/><rect x="14" y="4" width="4" height="16" rx="1"/></svg><svg class="hb-ic hb-i-play" viewBox="0 0 24 24" aria-hidden="true"><path d="M6 3l14 9-14 9z"/></svg><span class="hb-pause-label">Pause</span></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 and see the difference as it moves.</p></div>
+ </div>
+ <div class="hb-settings">
+ <div class="hb-setting">
+ <p class="hb-setting-name" id="dir-lbl">Comes from</p>
+ <div class="seg" id="dir-seg" role="group" aria-labelledby="dir-lbl">
+ <button type="button" data-dir="dir-tl" class="on" aria-pressed="true">Top left</button>
+ <button type="button" data-dir="dir-tr" aria-pressed="false">Top right</button>
+ <button type="button" data-dir="dir-bl" aria-pressed="false">Bottom left</button>
+ <button type="button" data-dir="dir-br" aria-pressed="false">Bottom right</button>
+ <button type="button" data-dir="dir-h" aria-pressed="false">Down the middle</button>
+ </div>
+ <p class="hb-hint">Where the light spills in.</p>
+ </div>
+ <div class="hb-setting">
+ <p class="hb-setting-name" id="gap-lbl">Time between leaks</p>
+ <div class="seg" id="gap-seg" role="group" aria-labelledby="gap-lbl">
+ <button type="button" data-min="0.5" data-max="1.5" aria-pressed="false">Short</button>
+ <button type="button" data-min="1" data-max="3" class="on" aria-pressed="true">Medium</button>
+ <button type="button" data-min="3" data-max="8" aria-pressed="false">Long</button>
+ </div>
+ <p class="hb-hint">Gaps are random within the range, so it never feels timed.</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="2000" aria-pressed="false">Slow</button>
+ <button type="button" data-ms="1200" class="on" aria-pressed="true">Normal</button>
+ <button type="button" data-ms="700" aria-pressed="false">Fast</button>
+ </div>
+ <p class="hb-hint">How quickly each leak fades in and out.</p>
+ </div>
+ </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="bri-lbl">Brightness</p>
+ <div class="seg" id="bri-seg" role="group" aria-labelledby="bri-lbl">
+ <button type="button" data-bri="0.3" aria-pressed="false">Dim</button>
+ <button type="button" data-bri="0.55" class="on" aria-pressed="true">Medium</button>
+ <button type="button" data-bri="0.8" aria-pressed="false">Bright</button>
+ </div>
+ <p class="hb-hint">Each leak peaks a little below this, at random.</p>
+ </div>
+ <div class="hb-setting">
+ <p class="hb-setting-name" id="color-lbl">Color</p>
+ <div class="swatches" id="color-sw" role="group" aria-labelledby="color-lbl">
+ <button type="button" class="on" aria-pressed="true" aria-label="Amber" data-c="#ffa532" style="background:#ffa532"></button>
+ <button type="button" aria-pressed="false" aria-label="Gold" data-c="#ffce5a" style="background:#ffce5a"></button>
+ <button type="button" aria-pressed="false" aria-label="Rose" data-c="#ff6f8b" style="background:#ff6f8b"></button>
+ <button type="button" aria-pressed="false" aria-label="Magenta" data-c="#ff5ca8" style="background:#ff5ca8"></button>
+ <button type="button" aria-pressed="false" aria-label="Cyan" data-c="#5ad1ff" style="background:#5ad1ff"></button>
+ </div>
+ <p class="hb-hint">Warm colors look like film; cyan looks cooler.</p>
+ </div>
+ <div class="hb-setting">
+ <label class="hb-switch-row"><span>Floating light spots</span><input class="hb-switch" type="checkbox" role="switch" id="spots-tog" autocomplete="off"></label>
+ <p class="hb-hint">Soft spots of light drift up after each leak.</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="leak dir-tl" id="leak"></div>
- <div class="fg-card">
- <div class="fg-eyebrow">Light Leak</div>
- <div class="fg-title">Analog warmth, digital precision</div>
- <div class="fg-body">Real film light leaks happen at random. Mechanical timing reads as fake.</div>
+ <div class="hb-card">
+ <p class="hb-prompt">Add a light leak effect to [the photo, video or section you want it over]. Place a soft glow of light, classically warm amber, spilling in from one corner or down the middle, in a see-through layer that clicks pass through, and fade it in and out every so often, like stray light reaching the film in an old camera. Make the gaps between leaks random and vary each leak's strength a little, because evenly timed leaks look fake. Keep each leak soft, so it never looks like a flash. If the visitor has reduced motion turned on, keep the glow still and faint. 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>
- <aside>
- <p class="note">KEY: irregularity. Mechanical, periodic light leaks look fake. Random timing and varying intensity per sweep is what makes them believable.</p>
- <div class="lbl">Direction</div>
- <select id="dir-sel">
- <option value="dir-tl" selected>Top-left corner</option>
- <option value="dir-tr">Top-right corner</option>
- <option value="dir-bl">Bottom-left corner</option>
- <option value="dir-br">Bottom-right corner</option>
- <option value="dir-h">Horizontal center</option>
- </select>
- <div class="lbl">Sweep Duration</div>
- <div class="sr"><input type="range" id="dur-sl" min="4" max="20" value="12" step="2"><span class="sv" id="dur-v">1.2s</span></div>
- <div class="lbl">Min / Max Delay (s)</div>
- <div class="sr"><input type="range" id="mindelay-sl" min="1" max="8" value="2" step="1"><span class="sv" id="mindelay-v">2s</span></div>
- <div class="sr"><input type="range" id="maxdelay-sl" min="5" max="20" value="10" step="1"><span class="sv" id="maxdelay-v">10s</span></div>
- <div class="lbl">Intensity</div>
- <div class="sr"><input type="range" id="int-sl" min="10" max="90" value="55" step="5"><span class="sv" id="int-v">0.55</span></div>
- <div class="lbl">Leak Color</div>
- <input type="color" id="color-pick" value="#ffa532" aria-label="Leak color">
- <label class="tog"><input type="checkbox" id="bokeh-tog"><span>Bokeh light blobs</span></label>
- <div class="div"></div>
- <div class="kv"><span>Next leak in</span><span class="v" id="next-v">—</span></div>
- <button class="rst" id="pause-btn">⏸ Pause</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>Photo and film sites</li><li>Portfolios</li><li>Music pages</li><li>Lifestyle brands</li></ul>
+ <h3>Avoid on</h3>
+ <ul class="hb-tags hb-avoid"><li>Dashboards</li><li>Long reading pages</li></ul>
+ </div>
+ </section>
+
+ <section class="hb-related" aria-labelledby="hb-related-title" hidden>
+ <h2 id="hb-related-title">Similar animations</h2>
+ <div class="hb-rel-list"></div>
+ </section>
+</main>
+<footer class="hb-foot"><span>Animation Handbook</span><a href="#top">Back to top ↑</a></footer>
<script>
+ const stage=document.getElementById('stage');
const leak=document.getElementById('leak');
- const nextV=document.getElementById('next-v');
- let paused=false,leakTimer=null,countTimer=null,minDelay=2,maxDelay=10,intensity=.55;
- let bokehOn=false;
+ const slowTog=document.getElementById('slow-tog');
+ const vars=document.documentElement.style;
+ let minGap=1,maxGap=3,dur=1200,intensity=.55,bokehOn=false;
let curColor='rgba(255,165,50,';
+ // Pause freezes the leak under way: its fade stops where it is and the timer keeps the time it had left.
+ // The floating light spots are CSS keyframes, which the Pause button holds by itself; only the fade is held here.
+ // Every timer goes through wait(), so there is only ever one pending timer and Play can never start a second chain.
+ let timer=0,next=null,due=0,left=0,held=[],paused=false;
+ function wait(fn,ms){clearTimeout(timer);next=fn;if(paused){left=ms;return}due=performance.now()+ms;timer=setTimeout(()=>{next=null;fn()},ms)}
+ function freeze(){paused=true;clearTimeout(timer);if(next)left=Math.max(0,due-performance.now());held=stage.getAnimations({subtree:true}).filter(a=>a instanceof CSSTransition&&a.playState==='running');held.forEach(a=>a.pause())}
+ // A fade that Pause caught at or past its end is finished, not played: play() would rewind it to the start.
+ function thaw(){paused=false;held.forEach(a=>{if(a.playState!=='paused')return;if(a.currentTime>=a.effect.getComputedTiming().endTime)a.finish();else a.play()});held=[];if(next)wait(next,left)}
+ document.addEventListener('hb:pause',e=>e.detail.paused?freeze():thaw());
+
+ // The gradient is painted here because its colour is live-editable; the dir-* class says where it comes from.
+ const CORNER={'dir-tl':'-10% -10%','dir-tr':'110% -10%','dir-bl':'-10% 110%','dir-br':'110% 110%'};
function applyColor(){
- const lc=curColor;
- const dir=[...leak.classList].find(c=>c.startsWith('dir-'));
- if(dir==='dir-tl')leak.style.background=`radial-gradient(ellipse at -10% -10%,${lc}.9) 0%,${lc}.5) 20%,${lc}.1) 50%,transparent 70%)`;
- else if(dir==='dir-tr')leak.style.background=`radial-gradient(ellipse at 110% -10%,${lc}.9) 0%,${lc}.5) 20%,${lc}.1) 50%,transparent 70%)`;
- else if(dir==='dir-bl')leak.style.background=`radial-gradient(ellipse at -10% 110%,${lc}.9) 0%,${lc}.5) 20%,${lc}.1) 50%,transparent 70%)`;
- else if(dir==='dir-br')leak.style.background=`radial-gradient(ellipse at 110% 110%,${lc}.9) 0%,${lc}.5) 20%,${lc}.1) 50%,transparent 70%)`;
- else leak.style.background=`linear-gradient(90deg,transparent,${lc}.6) 40%,${lc}.8) 50%,${lc}.6) 60%,transparent)`;
+ const c=curColor,dir=[...leak.classList].find(n=>n.startsWith('dir-'));
+ leak.style.background=dir==='dir-h'
+ ?`linear-gradient(90deg,transparent,${c}.6) 40%,${c}.8) 50%,${c}.6) 60%,transparent)`
+ :`radial-gradient(ellipse at ${CORNER[dir]},${c}.9) 0%,${c}.5) 20%,${c}.1) 50%,transparent 70%)`;
}
+ function randomGap(){return(minGap+Math.random()*(maxGap-minGap))*1000}
+
+ // One leak: fade in, hold 200ms at the peak, fade out, then a dark gap. The next leak starts only when the glow is gone.
+ // Slow motion stretches this leak's fade (and the waits for it) three times; the hold and the gap keep their length.
function flash(){
- if(paused)return;
- const dur=+document.getElementById('dur-sl').value*100;
- // Real leaks vary in strength — jitter the peak so it never reads as a loop
+ const slow=slowTog.checked?3:1,d=dur*slow;
+ leak.style.setProperty('--leak-dur',d+'ms');
+ // Real leaks vary in strength, so each one peaks a little below the chosen brightness
leak.style.setProperty('--leak-peak',(intensity*(.75+Math.random()*.25)).toFixed(3));
leak.classList.add('active');
- setTimeout(()=>leak.classList.remove('active'),dur+200);
- if(bokehOn)spawnBokeh();
- scheduleNext();
+ if(bokehOn)spawnBokeh(slow);
+ wait(()=>fadeOut(d),d+200);
}
-
- function scheduleNext(){
- const delay=(minDelay+Math.random()*(maxDelay-minDelay))*1000;
- let countdown=Math.round(delay/1000);
- nextV.textContent=countdown+'s';
- clearInterval(countTimer);
- leakTimer=setTimeout(flash,delay);
- // Hold the id locally: the stop timer must clear *this* interval, not
- // whichever one the next cycle has already installed.
- const tick=setInterval(()=>{countdown--;nextV.textContent=Math.max(0,countdown)+'s';},1000);
- countTimer=tick;
- setTimeout(()=>clearInterval(tick),delay);
+ function fadeOut(d){
+ leak.classList.remove('active');
+ wait(flash,d+randomGap());
}
- function spawnBokeh(){
- const stage=document.getElementById('stage');
+ function spawnBokeh(slow){
for(let i=0;i<3;i++){
const b=document.createElement('div');b.className='bokeh';
const sz=20+Math.random()*40;
- b.style.cssText=`width:${sz}px;height:${sz}px;background:${curColor}.6);left:${20+Math.random()*60}%;bottom:0;animation-duration:${3+Math.random()*4}s;animation-delay:${Math.random()*.5}s;display:block`;
+ b.style.cssText=`width:${sz}px;height:${sz}px;background:${curColor}.6);left:${20+Math.random()*60}%;bottom:0;animation-duration:${(3+Math.random()*4)*slow}s;animation-delay:${Math.random()*.5}s`;
+ b.addEventListener('animationend',()=>b.remove());
stage.appendChild(b);
- setTimeout(()=>b.remove(),(8000));
}
}
- document.getElementById('dir-sel').addEventListener('change',e=>{
+ 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);
+ }));
+ }
+ // Comes from and Color repaint the glow at once, even while paused. The other settings are read by the next leak;
+ // Brightness never writes --leak-peak here, because that would restart a fade that Pause is holding.
+ choices('dir-seg',d=>{
leak.classList.remove('dir-tl','dir-tr','dir-bl','dir-br','dir-h');
- leak.classList.add(e.target.value);applyColor();
- });
- document.getElementById('dur-sl').addEventListener('input',e=>{
- document.getElementById('dur-v').textContent=(e.target.value/10).toFixed(1)+'s';
- document.documentElement.style.setProperty('--leak-dur',e.target.value*100+'ms');
- });
- document.getElementById('mindelay-sl').addEventListener('input',e=>{minDelay=+e.target.value;document.getElementById('mindelay-v').textContent=minDelay+'s';});
- document.getElementById('maxdelay-sl').addEventListener('input',e=>{maxDelay=+e.target.value;document.getElementById('maxdelay-v').textContent=maxDelay+'s';});
- document.getElementById('int-sl').addEventListener('input',e=>{intensity=e.target.value/100;document.getElementById('int-v').textContent=intensity.toFixed(2);document.documentElement.style.setProperty('--leak-op',intensity);leak.style.setProperty('--leak-peak',intensity);});
- document.getElementById('color-pick').addEventListener('input',e=>{
- const h=e.target.value;curColor=`rgba(${parseInt(h.slice(1,3),16)},${parseInt(h.slice(3,5),16)},${parseInt(h.slice(5,7),16)},`;applyColor();
+ leak.classList.add(d.dir);
+ applyColor();
});
- document.getElementById('bokeh-tog').addEventListener('change',e=>{bokehOn=e.target.checked;});
- document.getElementById('pause-btn').addEventListener('click',()=>{
- paused=!paused;clearTimeout(leakTimer);clearInterval(countTimer);
- document.getElementById('pause-btn').textContent=paused?'▶ Resume':'⏸ Pause';
- if(!paused)scheduleNext();else nextV.textContent='—';
+ choices('gap-seg',d=>{minGap=+d.min;maxGap=+d.max});
+ choices('speed-seg',d=>{dur=+d.ms});
+ choices('bri-seg',d=>{intensity=+d.bri;vars.setProperty('--leak-op',intensity)});
+ choices('color-sw',d=>{
+ const h=d.c;
+ curColor=`rgba(${parseInt(h.slice(1,3),16)},${parseInt(h.slice(3,5),16)},${parseInt(h.slice(5,7),16)},`;
+ applyColor();
});
+ document.getElementById('spots-tog').addEventListener('change',e=>{bokehOn=e.target.checked});
- applyColor();scheduleNext();
+ applyColor();
+ wait(flash,randomGap());
</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 d4b9f664..c5bb93ba 100644
--- a/index.html
+++ b/index.html
@@ -1038,7 +1038,7 @@ const CATS=[
['aurora','Aurora / Northern Lights','Blurred bands of light sway like the northern lights. Best for dark backgrounds.'],
['grain-overlay','Grain / Film Noise Overlay','Fine grain flickers over the page, like old film. Best for editorial sites.'],
['scanline','Scanline Effect','Dark lines and a sweeping beam imitate an old TV screen. Best for retro sites.'],
- ['light-leak','Light Leak','Warm gradient fires at random irregular intervals — analog film camera aesthetic.'],
+ ['light-leak','Light Leak','Warm light washes in from a corner at random times. Best for photo sites.'],
['starfield','Starfield / Space Particles','Stars drift outward from center with parallax depth — slow ambient speed, never hyperspace.'],
['breathing-glow','Breathing / Pulsing Glow','Radial glow expands and contracts on a 5-second breath cycle — calm resting state.'],
['ambient-ripple','Ambient Ripple Effect','Concentric rings emit periodically from idle sources — passive atmosphere, not click-driven.'],