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 Portal / Tunnel Zoom to the guided-steps page

matineba34bdbe857
diff --git a/animations/03-page-transitions/portal-zoom/README.md b/animations/03-page-transitions/portal-zoom/README.md
index 01facfde..211b67a7 100644
--- a/animations/03-page-transitions/portal-zoom/README.md
+++ b/animations/03-page-transitions/portal-zoom/README.md
@@ -1,7 +1,7 @@
# Portal / Tunnel Zoom
## What it is
-A portal zoom treats a small on-screen element as a window into the next page: clicking it expands a circular (or rectangular) clip-path outward from the portal's center until the incoming page fills the whole stage. The effect reads as diving through the portal rather than swapping to a new URL. The destination is already rendered behind the mask before the animation begins, so the growth reveals it rather than loading it.
+A portal zoom treats a small element on the page as a window into the next page. Clicking it opens a circle, or a square, from the element's center that grows until the new page fills the whole view, so it feels like diving through the portal rather than jumping to a new page. The new page is already there underneath; the growing opening only reveals it.
## When to use it
- Gallery or case-study entries where a thumbnail should "open into" its detail view
@@ -24,7 +24,7 @@ nextEl.style.clipPath = `circle(0% at ${px} ${py})`; // pinhole at the portal
nextEl.style.transition = 'none';
nextEl.classList.add('active');
nextEl.offsetHeight; // force reflow to commit start
-nextEl.style.transition = `clip-path ${dur}ms ${easeSel.value}`;
+nextEl.style.transition = `clip-path ${dur}ms ${ease}`;
nextEl.style.clipPath = `circle(150% at ${px} ${py})`; // expand to cover the stage
```
@@ -33,11 +33,9 @@ The end radius is `150%` rather than `100%` because the circle must reach the co
## Key parameters
| Parameter | Default | Effect |
|-----------|---------|--------|
-| Portal shape | circle | `circle()` tunnels; `inset()` square reveals a rectangular aperture |
-| Duration | 1.2s | Long enough to read as travel; too short becomes a plain wipe |
-| Easing | ease-in | `ease-in` = diving in, `ease-out` = pulling back, `ease-in-out` = smooth throughout |
-| End radius | 150% | Must exceed 100% so the circle reaches the stage corners |
-| Origin (px, py) | portal center | Where the clip expands from; measured live from the clicked element |
+| Portal shape | Circle | A circle feels like a tunnel; a square opens like a window |
+| Speed | Normal | How long the opening takes to fill the view: slow is 1900ms, normal 1200ms and fast 700ms; too fast and it becomes a plain wipe |
+| Feel | Speeds up | Speeds up feels like diving in; Smooth slows at the end, like pulling back; Gentle eases in and out; Even keeps one steady pace |
## Production notes
- **Force the reflow.** Without reading `offsetHeight` (or another layout property) between the zero-radius clip and the transition, the browser coalesces both writes and the page appears instantly at full size. The reflow read is what makes the growth animate.
@@ -46,7 +44,7 @@ The end radius is `150%` rather than `100%` because the circle must reach the co
- **Library equivalents.** The View Transitions API is the natural fit — animate `clip-path` on `::view-transition-new(root)` from a pinhole at the click point for the same effect natively. GSAP animates `clipPath` strings directly; Framer Motion animates the `clipPath` style prop. This is also a common shader/WebGL reveal, but clip-path covers the DOM case without a canvas.
## See also
-- [Zoom Transition](../zoom-transition/) — scales the whole page rather than clipping a window
-- [Shared Element Transition](../shared-element-transition/) — an element grows into the next page's layout
-- [Flash / Light Leak](../flash-transition/) — another reveal that hides the swap behind an overlay
-- [Morph Transition](../morph-transition/) — reshapes an element between states instead of clipping
+- [Zoom Transition](../zoom-transition/) — the whole page scales instead
+- [Shared Element Transition](../shared-element-transition/) — a picture grows into the next page
+- [Flash / Light Leak Transition](../flash-transition/) — a burst of light hides the change
+- [Morph Transition](../morph-transition/) — a shape changes between pages
diff --git a/animations/03-page-transitions/portal-zoom/index.html b/animations/03-page-transitions/portal-zoom/index.html
index 8bbc6442..5ab7f4cc 100644
--- a/animations/03-page-transitions/portal-zoom/index.html
+++ b/animations/03-page-transitions/portal-zoom/index.html
@@ -4,7 +4,7 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Portal / Tunnel Zoom — Animation Handbook</title>
- <meta name="description" content="Zooming through a portal element — clip-path expands from the portal&#x27;s center to fill the stage.">
+ <meta name="description" content="The next page opens out of a circle you click. Best for big reveals.">
<link rel="canonical" href="https://matinmonshizadeh.github.io/animation-handbook/animations/03-page-transitions/portal-zoom/">
<link rel="icon" type="image/png" sizes="96x96" href="../../../favicon.png">
<link rel="icon" type="image/svg+xml" href="../../../favicon.svg">
@@ -12,166 +12,233 @@
<meta property="og:type" content="article">
<meta property="og:site_name" content="Animation Handbook">
<meta property="og:title" content="Portal / Tunnel Zoom — Animation Handbook">
- <meta property="og:description" content="Zooming through a portal element — clip-path expands from the portal&#x27;s center to fill the stage.">
+ <meta property="og:description" content="The next page opens out of a circle you click. Best for big reveals.">
<meta property="og:url" content="https://matinmonshizadeh.github.io/animation-handbook/animations/03-page-transitions/portal-zoom/">
<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="Portal / Tunnel Zoom — Animation Handbook">
- <meta name="twitter:description" content="Zooming through a portal element — clip-path expands from the portal&#x27;s center to fill the stage.">
+ <meta name="twitter:description" content="The next page opens out of a circle you click. Best for big reveals.">
<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": "Portal / Tunnel Zoom", "name": "Portal / Tunnel Zoom", "description": "Zooming through a portal element — clip-path expands from the portal's center to fill the stage.", "url": "https://matinmonshizadeh.github.io/animation-handbook/animations/03-page-transitions/portal-zoom/", "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, Portal / Tunnel Zoom"}</script>
+ <script type="application/ld+json">{"@context": "https://schema.org", "@type": "TechArticle", "headline": "Portal / Tunnel Zoom", "name": "Portal / Tunnel Zoom", "description": "The next page opens out of a circle you click. Best for big reveals.", "url": "https://matinmonshizadeh.github.io/animation-handbook/animations/03-page-transitions/portal-zoom/", "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, Portal / Tunnel Zoom"}</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;--dur:1200ms;--ease:ease-in}
+ :root{--bg:#0b0b0d;--ui-bg:#111114;--ui-border:rgba(255,255,255,.09);--ui-accent:#b98cff;--ui-text:#f4f4f2;--ui-muted:#8a8a92;--hb-stage-h-phone:360px}
*,*::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;opacity:0}
- .page.active{pointer-events:auto;opacity:1}
- /* Portal element on each page */
- .portal{position:absolute;cursor:pointer;display:flex;align-items:center;justify-content:center;transition:transform .2s ease}
+ /* A page that is not on show is hidden, so the portal on it cannot take focus */
+ .page{position:absolute;inset:0;pointer-events:none;opacity:0;visibility:hidden}
+ .page.active{pointer-events:auto;opacity:1;visibility:visible}
+ /* Portal element on each page, in the top-right corner where it never covers the Gallery grid */
+ .portal{position:absolute;top:24px;right:24px;width:80px;height:80px;display:flex;align-items:center;justify-content:center;border:3px solid rgba(255,255,255,.2);border-radius:50%;color:inherit;font:inherit;cursor:pointer;transition:transform .2s ease}
@media(hover:hover){.portal:hover{transform:scale(1.06)}}
- .portal-label{font-size:10px;text-align:center;opacity:.7;margin-top:6px;pointer-events:none}
+ .portal-label{font-size:11px;opacity:.8;text-align:center;padding:4px;line-height:1.3;pointer-events:none}
/* Page content */
.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(20px,3vw,34px);font-weight:bold;line-height:1.15}
.pp{font-size:12px;opacity:.6;line-height:1.65;max-width:300px}
.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:14px 10px;font-size:11px}
.pstat{display:flex;gap:16px;margin-top:4px}
.pstat b{display:block;font-size:clamp(16px,2.2vw,22px);color:var(--ui-accent)}
- .pstat span{font-size:9px;opacity:.4;text-transform:uppercase;letter-spacing:1px}
- /* Zoom mask overlay */
- #zoom-mask{position:absolute;inset:0;z-index:20;pointer-events:none;clip-path:circle(0% at 50% 50%);background:var(--mask-bg,#060a10);transition:clip-path var(--dur) var(--ease)}
- #zoom-mask.expanding{clip-path:circle(150% at var(--px,50%) var(--py,50%))}
- 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)}
- 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}
- .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%}.nav-btn,button.rst{min-height:44px}:root{--stage-h:480px}}
- @media(prefers-reduced-motion:reduce){#zoom-mask{transition:none!important}}
+ .pstat span{font-size:9px;opacity:.6;text-transform:uppercase;letter-spacing:1px}
+ /* Phones and short windows get a smaller portal in a tighter corner. Short windows leave the page area under 220px: it sits a
+ little higher, and tighter spacing keeps the tallest page clear of it and of the edges */
+ @media(max-width:600px),(max-height:640px){.portal{top:16px;right:16px;width:64px;height:64px}}
+ @media(max-height:640px){.portal{top:8px}.pc{gap:8px}.gi{padding:12px}}
+ @media(prefers-reduced-motion:reduce){.portal{transition: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="../elastic-transition/" rel="prev" title="Previous">‹ Prev</a><a class="ah-hideSm" href="../dissolve/" 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/portal-zoom/index.html" target="_blank" rel="noopener noreferrer">Source ↗</a></span></div>
-<header>
- <h1>Portal / Tunnel Zoom</h1>
- <p>Zooming through a portal element — clip-path expands from the portal's center to fill the stage.</p>
-</header>
-<div class="layout">
- <div class="stage">
- <nav class="mini-nav" id="nav"></nav>
- <div class="page-area" id="page-area">
- <div id="zoom-mask"></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="../elastic-transition/" rel="prev" aria-label="Previous: Elastic 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>Elastic Transition</span></a><a href="../dissolve/" rel="next" aria-label="Next: Dissolve Transition"><span><span class="hb-dir">Next: </span>Dissolve 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.10 · Page Transitions</p>
+ <h1>Portal / Tunnel Zoom</h1>
+ <p class="hb-lede">The next page opens out of a circle you click. Best for big reveals.</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 the round portal or a page name, 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>
- <aside>
- <p class="note">The portal reads as a window into the next page. clip-path: circle() expands from the portal's center coordinates. The new page is already rendered behind the mask before the animation starts.</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>Portal</span><span class="v" id="portal-val">Click portal →</span></div>
- <div class="div"></div>
- <div class="lbl">Portal shape</div>
- <select id="shape-sel">
- <option value="circle" selected>Circle</option>
- <option value="square">Square (inset)</option>
- </select>
- <div><div class="lbl" id="dur-lbl">Duration</div>
- <div class="sr"><input type="range" id="dur-sl" aria-labelledby="dur-lbl" min="400" max="3000" value="1200" step="100"><span class="sv" id="dur-v">1.2s</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="shape-lbl">Portal shape</p>
+ <div class="seg" id="shape-seg" role="group" aria-labelledby="shape-lbl">
+ <button type="button" data-shape="circle" class="on" aria-pressed="true">Circle</button>
+ <button type="button" data-shape="square" aria-pressed="false">Square</button>
+ </div>
+ <p class="hb-hint">A circle feels like a tunnel; a square like a window.</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="1900" 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">Slower reads as travel; too fast looks like a wipe.</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="feel-lbl">Feel</p>
+ <div class="seg" id="feel-seg" role="group" aria-labelledby="feel-lbl">
+ <button type="button" data-ease="ease-in" class="on" aria-pressed="true">Speeds up</button>
+ <button type="button" data-ease="ease-out" aria-pressed="false">Smooth</button>
+ <button type="button" data-ease="ease-in-out" aria-pressed="false">Gentle</button>
+ <button type="button" data-ease="linear" aria-pressed="false">Even</button>
+ </div>
+ <p class="hb-hint">Speeding up feels like diving in.</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">Easing</div>
- <select id="ease-sel">
- <option value="ease-in" selected>Ease in (zoom-in)</option>
- <option value="ease-out">Ease out (zoom-out)</option>
- <option value="ease-in-out">Ease in-out</option>
- <option value="linear">Linear</option>
- </select>
+ <div class="hb-card">
+ <p class="hb-prompt">Add a portal transition to [the element that should open into the next page]. When the visitor clicks it, show the next page through an opening that starts as a point at the element's center and grows until the new page fills the view, as if diving through a window. Put the new page underneath first and only grow the visible opening, measuring the element's position at the moment of the click so the opening starts exactly there. Make the opening big enough at the end to reach the corners. If the visitor has reduced motion turned on, show the new page at once. 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 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>Big reveals</li><li>Galleries</li><li>Story chapters</li><li>Calls to action</li></ul>
+ <h3>Avoid on</h3>
+ <ul class="hb-tags hb-avoid"><li>Everyday navigation</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)',portalBg:'#1a3060',portalLabel:'Enter gallery',
- html:`<div class="pc"><div class="pe">Creative Studio</div><h2 class="ph">Design without compromise.</h2><p class="pp">Click the portal to travel to the gallery.</p></div>`},
+ html:`<div class="pc"><div class="pe">Creative Studio</div><p class="ph">Design without compromise.</p><p class="pp">Click the portal to travel to the gallery.</p></div>`},
{name:'Gallery',bg:'linear-gradient(135deg,#0d1f15,#152e1e)',portalBg:'#2a5040',portalLabel:'View about',
- 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>`},
+ 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)',portalBg:'#402060',portalLabel:'Return home',
- 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>`},
+ 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 zoomMask=document.getElementById('zoom-mask');
- const curPage=document.getElementById('cur-page'),portalVal=document.getElementById('portal-val'),logEl=document.getElementById('trans-log');
- const durSl=document.getElementById('dur-sl'),durV=document.getElementById('dur-v');
- const easeSel=document.getElementById('ease-sel'),shapeSel=document.getElementById('shape-sel');
- let current=0,animating=false,dur=1200,history=[];
+ const nav=document.getElementById('nav'),area=document.getElementById('page-area'),slowTog=document.getElementById('slow-tog');
const motionOk=!window.matchMedia('(prefers-reduced-motion:reduce)').matches;
-
- function buildPortal(page,pageEl,next){
- const p=document.createElement('div');p.className='portal';
- const size=80;
- p.style.cssText=`bottom:32px;right:32px;width:${size}px;height:${size}px;border-radius:50%;background:${page.portalBg};border:3px solid rgba(255,255,255,.2);flex-direction:column;gap:4px`;
- p.innerHTML=`<div style="font-size:9px;opacity:.6;text-align:center;padding:4px;line-height:1.3">${page.portalLabel}</div>`;
- p.addEventListener('click',()=>{if(!animating)navigate(next,p)});
- pageEl.appendChild(p);
- }
+ let current=0,animating=false,shape='circle',dur=1200,ease='ease-in',afterMove=null,wayBack=0,timers=[];
+ const pages=[],portals=[],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,zoomMask);
- const next=(i+1)%PAGES.length;buildPortal(p,d,next);
- const b=document.createElement('button');b.className='nav-btn'+(i===0?' active':'');b.textContent=p.name;b.addEventListener('click',()=>{if(!animating)navigate(i,null)});nav.appendChild(b);
+ const d=document.createElement('div');d.className='page';d.style.background=p.bg;d.innerHTML=p.html;
+ // The portal opens the next page out of itself
+ const portal=document.createElement('button');portal.type='button';portal.className='portal';portal.style.background=p.portalBg;
+ const label=document.createElement('span');label.className='portal-label';label.textContent=p.portalLabel;
+ portal.appendChild(label);
+ portal.addEventListener('click',()=>navigate((i+1)%PAGES.length,portal));
+ d.appendChild(portal);area.appendChild(d);pages.push(d);portals.push(portal);
+ 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);
+ }
- function navigate(next,portalEl){
+ 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 the opening's clip, transition and stacking gone (its background stays)
+ function rest(el,on){
+ el.classList.toggle('active',on);
+ el.style.clipPath='';el.style.transition='';el.style.zIndex='';
+ }
+ // The resting state for page n, at once. A running opening is cancelled too, so no tail of it shows.
+ function showPage(n){
+ pages.forEach((el,i)=>{rest(el,i===n);el.getAnimations().forEach(a=>a.cancel())});
+ updateNav(n);
+ }
+
+ // Ends an opening: the demo is idle again, and a Show me run goes on to its next step
+ function finish(){
+ animating=false;
+ // Focus that was on the portal of the page now hidden moves to the portal of the page on show, so a keyboard visitor keeps their place
+ const at=document.activeElement;
+ if(at&&pages.some(p=>p.contains(at))&&!pages[current].contains(at))portals[current].focus({preventScroll:true});
+ 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;
+ showPage(current);
+ }
+
+ // portalEl is the portal that was clicked; without one (a page name, the way back) the opening starts in the middle of the page area
+ function navigate(next,portalEl,then){
if(next===current||animating)return;
- const prev=current;current=next;updateNav(next);addLog(prev,next);
- portalVal.textContent=PAGES[next].name;
- if(!motionOk){document.querySelectorAll('.page').forEach((el,i)=>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;
- const prevEl=document.getElementById('p'+prev),nextEl=document.getElementById('p'+next);
+ const prevEl=pages[prev],nextEl=pages[next],d=dur*(slowTog.checked?3:1); // read when the opening starts; three times as long in slow motion
const areaRect=area.getBoundingClientRect();
let px='50%',py='50%';
if(portalEl){
@@ -179,30 +246,43 @@ body{padding-top:46px}
px=((pr.left+pr.width/2-areaRect.left)/areaRect.width*100).toFixed(1)+'%';
py=((pr.top+pr.height/2-areaRect.top)/areaRect.height*100).toFixed(1)+'%';
}
- // Clip the new page to nothing at the portal position, then expand to fill
- const isSquare=shapeSel.value==='square';
+ // Clip the new page to nothing at the portal position, then open it out to fill the page area
+ const isSquare=shape==='square';
const startClip=isSquare?`inset(${py} ${(100-parseFloat(px)).toFixed(1)}% ${(100-parseFloat(py)).toFixed(1)}% ${px})`:`circle(0% at ${px} ${py})`;
const endClip=isSquare?'inset(0%)':`circle(150% at ${px} ${py})`;
- nextEl.style.clipPath=startClip;nextEl.style.zIndex='2'; // incoming page must paint above the outgoing one regardless of DOM order
+ nextEl.style.clipPath=startClip;nextEl.style.zIndex='2'; // the incoming page paints above the outgoing one whatever the DOM order
nextEl.style.transition='none';
nextEl.classList.add('active');
- nextEl.offsetHeight; // force reflow
- nextEl.style.transition=`clip-path ${dur}ms ${easeSel.value}`;
+ nextEl.offsetHeight; // force reflow: commit the pinhole before the growth is switched on
+ nextEl.style.transition=`clip-path ${d}ms ${ease}`;
nextEl.style.clipPath=endClip;
- setTimeout(()=>{
- prevEl.classList.remove('active');
- nextEl.style.clipPath='';nextEl.style.transition='';nextEl.style.zIndex='';
- animating=false;
- },dur+50);
+ later(()=>{rest(prevEl,false);rest(nextEl,true);finish()},d+50);
}
- durSl.addEventListener('input',()=>{dur=+durSl.value;durV.textContent=(dur/1000).toFixed(1)+'s';document.documentElement.style.setProperty('--dur',dur+'ms')});
- easeSel.addEventListener('change',()=>document.documentElement.style.setProperty('--ease',easeSel.value));
- 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));zoomMask.style.clipPath='circle(0%)';zoomMask.classList.remove('expanding');animating=false;
- });
+ // Show me: click the portal of the page on show, hold the new page for 1200ms, then go back the way a page name does
+ function showMe(){
+ settle();
+ const start=current;
+ navigate((start+1)%PAGES.length,portals[start],()=>{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. An opening 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('shape-seg',d=>{shape=d.shape});
+ choices('speed-seg',d=>{dur=+d.ms});
+ choices('feel-seg',d=>{ease=d.ease});
+ 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 fe4f47f5..fcb0c61d 100644
--- a/index.html
+++ b/index.html
@@ -941,7 +941,7 @@ const CATS=[
['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','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.'],
+ ['portal-zoom','Portal / Tunnel Zoom','The next page opens out of a circle you click. Best for big reveals.'],
['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.'],
]