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 Fly-in Fly-out Contact List to the guided-steps page

matinaa00aab6d5ca
diff --git a/animations/01-scroll-based/fly-in-fly-out-contact-list/README.md b/animations/01-scroll-based/fly-in-fly-out-contact-list/README.md
index 405203c9..7c4b6ef7 100644
--- a/animations/01-scroll-based/fly-in-fly-out-contact-list/README.md
+++ b/animations/01-scroll-based/fly-in-fly-out-contact-list/README.md
@@ -4,12 +4,11 @@
## What it is
-Each row in a scrollable contact list animates through three viewport zones:
-an entry zone at the bottom (row fades and translates in from below), an
-active zone in the middle (row is fully visible and stable), and an exit zone
-at the top (row fades and translates out upward). The effect is continuous and
-bidirectional — scrubbed to scroll position rather than triggered once. A row
-that scrolls back into the active zone after exiting reappears smoothly.
+A fly-in, fly-out list animates its rows as they pass near the edges of the
+scrolling area. A row coming in at the bottom fades in, slides up and grows to
+full size; a row leaving at the top does the reverse; rows in the middle stay
+still. Because it follows the scroll position rather than playing once,
+scrolling back brings rows back the same way.
## When to use it
@@ -37,27 +36,37 @@ if (pos < Z) { // exit zone (top)
const t = pos / Z; // 0 = fully exited, 1 = entering active
opacity = lerp(0, 1, t);
ty = lerp(-DIST, 0, t);
- scale = lerp(SCALE_MIN, 1, t);
+ scale = lerp(SCALE, 1, t);
} else if (pos > 1 - Z) { // entry zone (bottom)
const t = (1 - pos) / Z; // 0 = fully below, 1 = entering active
opacity = lerp(0, 1, t);
ty = lerp(DIST, 0, t);
- scale = lerp(SCALE_MIN, 1, t);
+ scale = lerp(SCALE, 1, t);
} // else: active zone — opacity=1, ty=0, scale=1
```
An `IntersectionObserver` with `rootMargin: '50% 0px'` maintains a Set of
rows currently in or near the viewport. The rAF callback iterates only that
-Set — never all 15 rows unconditionally.
+Set — never all 15 rows unconditionally. The one exception is a jump longer
+than the observer's margin (Back to top, a dragged scrollbar): rows it has not
+added yet still carry the style they were left with, so every row is styled once.
+The first frame counts as such a jump, which gives the first picture its effect.
+
+The list ends with 70px of padding, as much as the farthest a row can slide.
+Without it, a row still arriving at the bottom would sit below the list and
+stretch the scroll length, then give it back as it settles, and a script that
+reads the length once (as the demo's Play button does) would aim at an end that
+is not there.
## Key parameters
| Parameter | Default | Effect |
|-----------|---------|--------|
-| `DIST` | 40px | Translation distance at zone edges |
-| `SCALE_MIN` | 0.94 | Scale at zone edges (1 = no shrink) |
-| `Z` | 0.25 | Fraction of viewport height for each zone |
-| Effect mode | all combined | opacity + translateY + scale together |
+| Effect | All three | Which changes a row makes in the bands: all three (moving, fading and shrinking) together read as physical motion; moving only or fading only feels flatter |
+| Edge zone size | Medium | How tall each band is: small is 15% of the box, medium 25% and large 35% |
+| How far rows move | Medium | How far a row slides at the very edge: short is 20px, medium 40px and far 70px |
+| How much rows shrink | Medium | The size of a row at the very edge: a little is 97%, medium 94% and a lot 88% |
+| Shows the zones | off | Tints the two bands, red for leaving and green for arriving |
## Production notes
@@ -86,7 +95,6 @@ Set — never all 15 rows unconditionally.
## See also
-- [Cover Card to Fixed Header](../cover-card-to-fixed-header/) — the same
- single-progress piecewise lerp model applied to a morphing header.
-- [Parallax Scrolling](../parallax-scrolling/) — scroll-position driving
- layer transforms; the architectural pattern this builds on.
+- [Reveal on Scroll](../reveal-on-scroll/) — cards appear once as they cross a line
+- [Stagger Reveal](../stagger-reveal/) — items in a group appear one after another
+- [Cover Card to Fixed Header](../cover-card-to-fixed-header/) — a tall cover shrinks into a slim header
diff --git a/animations/01-scroll-based/fly-in-fly-out-contact-list/index.html b/animations/01-scroll-based/fly-in-fly-out-contact-list/index.html
index fa43eac0..186f9ab1 100644
--- a/animations/01-scroll-based/fly-in-fly-out-contact-list/index.html
+++ b/animations/01-scroll-based/fly-in-fly-out-contact-list/index.html
@@ -4,7 +4,7 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Fly-in Fly-out Contact List — Animation Handbook</title>
- <meta name="description" content="Rows translate and fade as they enter and exit the scroll viewport — effect scrubbed continuously to scroll position.">
+ <meta name="description" content="Rows fade and slide as they near the top or bottom edge. Best for long lists.">
<link rel="canonical" href="https://matinmonshizadeh.github.io/animation-handbook/animations/01-scroll-based/fly-in-fly-out-contact-list/">
<link rel="icon" type="image/png" sizes="96x96" href="../../../favicon.png">
<link rel="icon" type="image/svg+xml" href="../../../favicon.svg">
@@ -12,198 +12,169 @@
<meta property="og:type" content="article">
<meta property="og:site_name" content="Animation Handbook">
<meta property="og:title" content="Fly-in Fly-out Contact List — Animation Handbook">
- <meta property="og:description" content="Rows translate and fade as they enter and exit the scroll viewport — effect scrubbed continuously to scroll position.">
+ <meta property="og:description" content="Rows fade and slide as they near the top or bottom edge. Best for long lists.">
<meta property="og:url" content="https://matinmonshizadeh.github.io/animation-handbook/animations/01-scroll-based/fly-in-fly-out-contact-list/">
<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="Fly-in Fly-out Contact List — Animation Handbook">
- <meta name="twitter:description" content="Rows translate and fade as they enter and exit the scroll viewport — effect scrubbed continuously to scroll position.">
+ <meta name="twitter:description" content="Rows fade and slide as they near the top or bottom edge. Best for long lists.">
<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": "Fly-in Fly-out Contact List", "name": "Fly-in Fly-out Contact List", "description": "Rows translate and fade as they enter and exit the scroll viewport — effect scrubbed continuously to scroll position.", "url": "https://matinmonshizadeh.github.io/animation-handbook/animations/01-scroll-based/fly-in-fly-out-contact-list/", "inLanguage": "en", "articleSection": "Scroll-Based", "isPartOf": {"@type": "WebSite", "name": "Animation Handbook", "url": "https://matinmonshizadeh.github.io/animation-handbook/"}, "author": {"@type": "Person", "name": "matinmonshizadeh"}, "keywords": "web animation, CSS animation, Scroll-Based, Fly-in Fly-out Contact List"}</script>
+ <script type="application/ld+json">{"@context": "https://schema.org", "@type": "TechArticle", "headline": "Fly-in Fly-out Contact List", "name": "Fly-in Fly-out Contact List", "description": "Rows fade and slide as they near the top or bottom edge. Best for long lists.", "url": "https://matinmonshizadeh.github.io/animation-handbook/animations/01-scroll-based/fly-in-fly-out-contact-list/", "inLanguage": "en", "articleSection": "Scroll-Based", "isPartOf": {"@type": "WebSite", "name": "Animation Handbook", "url": "https://matinmonshizadeh.github.io/animation-handbook/"}, "author": {"@type": "Person", "name": "matinmonshizadeh"}, "keywords": "web animation, CSS animation, Scroll-Based, Fly-in Fly-out Contact List"}</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:#6ea8ff;--ui-text:#f4f4f2;--ui-muted:#77777e;
- --row-bg:#111114;
- --disp:'Bricolage','Arial Narrow',sans-serif;
- --mono:'PlexMono',ui-monospace,Menlo,Consolas,monospace;
- }
+ :root{--ui-accent:#6ea8ff;--ui-text:#f4f4f2;--ui-muted:#8a8a92;--ui-border:rgba(255,255,255,.09);--row-bg:#111114}
*,*::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:620px;
- overflow-y:scroll;scrollbar-width:none;
- border:1px solid var(--ui-border);border-radius:8px;
- position:relative;
- }
+ .stage{position:relative;overflow-y:auto;scrollbar-width:none;background:#0b0b0d}
.stage::-webkit-scrollbar{display:none}
-
- .contact-list{padding:12px;display:flex;flex-direction:column;gap:6px;position:relative}
-
- .row{
- background:var(--row-bg);border:1px solid var(--ui-border);
- border-radius:8px;padding:10px 12px;
- display:flex;align-items:center;gap:10px;
- min-height:56px;will-change:transform,opacity;
- }
- .avatar{
- width:36px;height:36px;border-radius:50%;flex-shrink:0;
- display:flex;align-items:center;justify-content:center;
- font-size:12px;font-weight:bold;color:var(--ui-text);
- }
+ /* The bottom padding is as tall as the farthest a row can slide (70px), so a row still arriving at the bottom
+ never adds to the scroll length, which Play reads once when it starts. */
+ .contact-list{padding:12px 12px 70px;display:flex;flex-direction:column;gap:6px;position:relative}
+ .row{background:var(--row-bg);border:1px solid var(--ui-border);border-radius:8px;padding:10px 12px;display:flex;align-items:center;gap:10px;min-height:56px;will-change:transform,opacity}
+ .avatar{width:36px;height:36px;border-radius:50%;flex-shrink:0;display:flex;align-items:center;justify-content:center;font-size:12px;font-weight:bold;color:var(--ui-text)}
.row-info{flex:1;min-width:0}
- .row-name{font-size:12px;color:#e6edf3}
- .row-sub{font-size:10px;color:var(--ui-muted);margin-top:2px}
+ .row-name{font-size:14px;color:#e6edf3}
+ .row-sub{font-size:12px;color:var(--ui-muted);margin-top:2px}
.row-meta{display:flex;flex-direction:column;align-items:flex-end;gap:3px;flex-shrink:0}
.dot{width:7px;height:7px;border-radius:50%}
.dot.online{background:#3fb950}
.dot.offline{background:var(--ui-muted)}
- .badge{background:#0d2840;color:#58a6ff;font-size:9px;padding:1px 5px;border-radius:8px}
- .meta-time{font-size:8px;color:var(--ui-muted)}
-
- .zone-overlay{
- position:sticky;top:0;height:0;overflow:visible;
- pointer-events:none;display:none;z-index:5;
- }
+ .badge{background:#0d2840;color:#58a6ff;font-size:11px;padding:1px 5px;border-radius:8px}
+ .meta-time{font-size:11px;color:var(--ui-muted)}
+ /* Shown, the overlay is one more flex item and would push the rows down by the list's 6px gap: the negative margin cancels it */
+ .zone-overlay{position:sticky;top:0;height:0;overflow:visible;margin-bottom:-6px;pointer-events:none;display:none;z-index:5}
.zone-overlay.visible{display:block}
.zone-band{position:absolute;left:0;right:0}
.zone-exit{background:rgba(248,81,73,.1);top:0}
.zone-entry{background:rgba(63,185,80,.1)}
- .zone-label{font-size:8px;color:var(--ui-muted);padding:2px 6px;display:block}
-
- 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)}
- .tbl{display:flex;flex-direction:column;gap:2px}
- .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}
- .sr .sv{width:34px;text-align:right;color:var(--ui-text)}
- .div{height:1px;background:var(--ui-border)}
- .modes{display:flex;flex-direction:column;gap:2px}
- .mode-opt{display:flex;align-items:center;gap:6px;font-size:10px;cursor:pointer;min-height:44px}
- .mode-opt input{accent-color:var(--ui-accent);width:14px;height:14px;flex-shrink:0}
- .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}
- button{
- background:transparent;border:1px solid var(--ui-border);
- color:var(--ui-text);font-family:monospace;font-size:10px;
- padding:17px 8px;border-radius:4px;cursor:pointer;width:100%;
- }
- @media(hover:hover){button:hover{border-color:var(--ui-accent);color:var(--ui-accent)}}
-
- @media(max-width:600px){
- .layout{flex-direction:column}
- aside{width:100%}.stage{flex:none;width:100%}
- .stage{height:480px}
- .avatar{width:32px;height:32px;font-size:10px}
- }
+ .zone-label{font-size:11px;color:var(--ui-muted);padding:2px 6px;display:block}
+ .zone-label-end{position:absolute;bottom:2px}
+ @media(max-width:600px){.avatar{width:32px;height:32px;font-size:11px}}
@media(prefers-reduced-motion:reduce){.row{will-change:auto}}
</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="../cover-card-to-fixed-header/" rel="prev" title="Previous">‹ Prev</a><a class="ah-hideSm" href="../stacking-cards/" 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/01-scroll-based/fly-in-fly-out-contact-list/index.html" target="_blank" rel="noopener noreferrer">Source ↗</a></span></div>
-
-<header>
- <h1>Fly-in Fly-out Contact List</h1>
- <p>Rows translate and fade as they enter and exit the scroll viewport — effect scrubbed continuously to scroll position.</p>
-</header>
-
-<div class="layout">
-
- <div class="stage" id="stage">
- <div class="contact-list" id="contact-list">
- <div class="zone-overlay" id="zone-overlay">
- <div class="zone-band zone-exit" id="zone-exit">
- <span class="zone-label">↑ exit zone</span>
- </div>
- <div class="zone-band zone-entry" id="zone-entry">
- <span class="zone-label" style="position:absolute;bottom:2px">↓ entry zone</span>
+<body class="hb" data-hb-kind="scroll" 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="../cover-card-to-fixed-header/" rel="prev" aria-label="Previous: Cover Card to Fixed Header"><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>Cover Card to Fixed Header</span></a><a href="../stacking-cards/" rel="next" aria-label="Next: Stacking Cards"><span><span class="hb-dir">Next: </span>Stacking Cards</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">01.05 · Scroll-Based</p>
+ <h1>Fly-in Fly-out Contact List</h1>
+ <p class="hb-lede">Rows fade and slide as they near the top or bottom edge. Best for long lists.</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">Scroll it</h2><p>Scroll inside the box, or press Play and it scrolls for you.</p></div>
+ </div>
+ <div class="stage" id="stage" tabindex="0" role="region" aria-label="A list of contacts">
+ <div class="contact-list" id="contact-list">
+ <div class="zone-overlay" id="zone-overlay" aria-hidden="true">
+ <div class="zone-band zone-exit" id="zone-exit"><span class="zone-label">↑ exit zone</span></div>
+ <div class="zone-band zone-entry" id="zone-entry"><span class="zone-label zone-label-end">↓ entry zone</span></div>
</div>
</div>
</div>
- </div>
-
- <aside>
- <p class="note">The combination of fade + translate + scale is what gives this effect its 'flying' quality. Each property alone feels mechanical. Together they read as smooth, physical motion.</p>
-
- <div>
- <div class="lbl">Viewport</div>
- <div class="tbl">
- <div class="kv"><span>Scroll</span><span class="v" id="scroll-prog">0%</span></div>
- <div class="kv"><span>Visible rows</span><span class="v" id="visible-count">0</span></div>
- </div>
+ <div class="hb-player">
+ <button class="hb-play" type="button" id="btn-scroll" data-hb-autoscroll><svg class="hb-ic" viewBox="0 0 24 24" aria-hidden="true"><path d="M12 5v14M19 12l-7 7-7-7"/></svg>Play</button>
+ <button class="hb-play" type="button" id="btn-top" data-hb-top><svg class="hb-ic" viewBox="0 0 24 24" aria-hidden="true"><path d="M12 19V5M5 12l7-7 7 7"/></svg>Back to top</button>
</div>
+ </section>
- <div class="div"></div>
-
- <div>
- <div class="lbl" id="dist-lbl">Translate Distance</div>
- <div class="sr"><input type="range" id="dist-sl" aria-labelledby="dist-lbl" min="0" max="80" value="40"><span class="sv" id="dist-val">40px</span></div>
- </div>
- <div>
- <div class="lbl" id="scale-lbl">Scale Delta</div>
- <div class="sr"><input type="range" id="scale-sl" aria-labelledby="scale-lbl" min="80" max="100" value="94"><span class="sv" id="scale-val">0.94</span></div>
+ <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 scroll again or press Play.</p></div>
</div>
- <div>
- <div class="lbl" id="zone-lbl">Zone Size</div>
- <div class="sr"><input type="range" id="zone-sl" aria-labelledby="zone-lbl" min="10" max="40" value="25"><span class="sv" id="zone-val">25%</span></div>
+ <div class="hb-settings">
+ <div class="hb-setting">
+ <p class="hb-setting-name" id="mode-lbl">Effect</p>
+ <div class="seg" id="mode-seg" role="group" aria-labelledby="mode-lbl">
+ <button type="button" data-mode="all" class="on" aria-pressed="true">All three</button>
+ <button type="button" data-mode="translate" aria-pressed="false">Move only</button>
+ <button type="button" data-mode="fade" aria-pressed="false">Fade only</button>
+ </div>
+ <p class="hb-hint">All three moves, fades and shrinks each row together.</p>
+ </div>
+ <div class="hb-setting">
+ <p class="hb-setting-name" id="zone-lbl">Edge zone size</p>
+ <div class="seg" id="zone-seg" role="group" aria-labelledby="zone-lbl">
+ <button type="button" data-zone="0.15" aria-pressed="false">Small</button>
+ <button type="button" data-zone="0.25" class="on" aria-pressed="true">Medium</button>
+ <button type="button" data-zone="0.35" aria-pressed="false">Large</button>
+ </div>
+ <p class="hb-hint">How close to the edge a row starts to fly out.</p>
+ </div>
+ <div class="hb-setting" id="dist-setting">
+ <p class="hb-setting-name" id="dist-lbl">How far rows move</p>
+ <div class="seg" id="dist-seg" role="group" aria-labelledby="dist-lbl">
+ <button type="button" data-dist="20" aria-pressed="false">Short</button>
+ <button type="button" data-dist="40" class="on" aria-pressed="true">Medium</button>
+ <button type="button" data-dist="70" aria-pressed="false">Far</button>
+ </div>
+ <p class="hb-hint">The distance a row slides as it leaves.</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" id="scale-setting">
+ <p class="hb-setting-name" id="scale-lbl">How much rows shrink</p>
+ <div class="seg" id="scale-seg" role="group" aria-labelledby="scale-lbl">
+ <button type="button" data-scale="0.97" aria-pressed="false">A little</button>
+ <button type="button" data-scale="0.94" class="on" aria-pressed="true">Medium</button>
+ <button type="button" data-scale="0.88" aria-pressed="false">A lot</button>
+ </div>
+ <p class="hb-hint">The size a row shrinks to at the edge.</p>
+ </div>
+ <div class="hb-setting">
+ <label class="hb-switch-row"><span>Shows the zones</span><input class="hb-switch" type="checkbox" role="switch" id="zones-tog" autocomplete="off"></label>
+ <p class="hb-hint">Tints the two bands where rows fly in and out.</p>
+ </div>
+ </div>
+ </details>
+ </section>
- <div class="div"></div>
-
- <div>
- <div class="lbl">Effect Mode</div>
- <div class="modes">
- <label class="mode-opt"><input type="radio" name="mode" value="all" checked><span>All combined</span></label>
- <label class="mode-opt"><input type="radio" name="mode" value="translate"><span>Translate only</span></label>
- <label class="mode-opt"><input type="radio" name="mode" value="fade"><span>Fade only</span></label>
+ <section class="hb-step hb-prompt-step" aria-labelledby="hb-prompt-title">
+ <div class="hb-step-head">
+ <span class="hb-num" aria-hidden="true">3</span>
+ <div><h2 id="hb-prompt-title">Copy the prompt</h2><p>Paste it into an AI assistant such as ChatGPT, Claude or Cursor to build this in your own project.</p></div>
+ </div>
+ <div class="hb-card">
+ <p class="hb-prompt">Add a fly-in, fly-out effect to [your scrolling list, such as contacts or messages]. Treat a band at the top and a band at the bottom of the scrolling area as edge zones. As a row passes through the bottom band it arrives, and as it passes through the top band it leaves: the deeper it is in the band, the more it is faded, moved and shrunk, as the settings choose, and in the middle it shows in full. Work it out from the scroll position on every frame, so scrolling back brings rows back. If the visitor has reduced motion turned on, do not move or shrink rows; only fade them a little near the edges. 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>
+ </section>
- <div class="div"></div>
-
- <label class="tog" for="preview-tog">
- <input type="checkbox" id="preview-tog">
- <span>Preview zones</span>
- </label>
-
- <button id="reset-btn">Reset</button>
- </aside>
-
-</div>
-
+ <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>Contact lists</li><li>Chat lists</li><li>Activity feeds</li><li>Search results</li></ul>
+ <h3>Avoid on</h3>
+ <ul class="hb-tags hb-avoid"><li>Short lists</li><li>Tables</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 CONTACTS = [
{i:'SK',n:'Sara Klein', s:'Design lead · Berlin', t:'now', b:0,o:true },
@@ -226,12 +197,13 @@ body{padding-top:46px}
'#3a1a1a','#1a2a3d','#2d1a3d','#1e2d1e','#3a2a00'];
const avatarColor = i => COLORS[(i.charCodeAt(0)+i.charCodeAt(1))%COLORS.length];
- const list = document.getElementById('contact-list');
+ const $ = id => document.getElementById(id);
+ const list = $('contact-list');
const rows = CONTACTS.map(c => {
const el = document.createElement('div');
el.className = 'row';
el.innerHTML =
- `<div class="avatar" style="background:${avatarColor(c.i)}">${c.i}</div>` +
+ `<div class="avatar" aria-hidden="true" style="background:${avatarColor(c.i)}">${c.i}</div>` +
`<div class="row-info"><div class="row-name">${c.n}</div>` +
`<div class="row-sub">${c.s}</div></div>` +
`<div class="row-meta">` +
@@ -241,41 +213,26 @@ body{padding-top:46px}
return el;
});
- const stage = document.getElementById('stage');
- const scrollProg = document.getElementById('scroll-prog');
- const visCount = document.getElementById('visible-count');
- const distSl = document.getElementById('dist-sl');
- const distVal = document.getElementById('dist-val');
- const scaleSl = document.getElementById('scale-sl');
- const scaleVal = document.getElementById('scale-val');
- const zoneSl = document.getElementById('zone-sl');
- const zoneVal = document.getElementById('zone-val');
- const previewTog = document.getElementById('preview-tog');
- const resetBtn = document.getElementById('reset-btn');
- const zoneOverlay = document.getElementById('zone-overlay');
- const zoneExit = document.getElementById('zone-exit');
- const zoneEntry = document.getElementById('zone-entry');
- const motionMQ = window.matchMedia('(prefers-reduced-motion: reduce)');
+ const stage = $('stage'), zoneOverlay = $('zone-overlay'), zoneExit = $('zone-exit'), zoneEntry = $('zone-entry');
+ const distSetting = $('dist-setting'), scaleSetting = $('scale-setting'), zonesTog = $('zones-tog');
+ const motionMQ = window.matchMedia('(prefers-reduced-motion: reduce)');
let DIST = 40, SCALE = 0.94, Z = 0.25, mode = 'all';
let ticking = false;
const visible = new Set();
-
const io = new IntersectionObserver(entries => {
entries.forEach(e => e.isIntersecting ? visible.add(e.target) : visible.delete(e.target));
schedule(); // paints the initial state, and re-styles rows the observer just re-added
- }, { root: stage, rootMargin: '50% 0px', threshold: 0 }); // 50% covers max zone size (40%)
+ }, { root: stage, rootMargin: '50% 0px', threshold: 0 }); // 50% covers the largest zone (35%)
rows.forEach(r => io.observe(r));
function lerp(a, b, t) { return a + (b - a) * t; }
function clamp(v, lo, hi) { return Math.min(Math.max(v, lo), hi); }
-
function applyRow(el) {
const top = el.offsetTop - stage.scrollTop;
const pos = top / stage.clientHeight;
const reduced = motionMQ.matches;
let opacity = 1, ty = 0, sc = 1;
-
if (pos < Z) {
const t = clamp(pos / Z, 0, 1);
opacity = reduced ? lerp(0.3, 1, t) : (mode !== 'translate' ? lerp(0, 1, t) : 1);
@@ -287,12 +244,10 @@ body{padding-top:46px}
if (!reduced && mode !== 'fade') ty = lerp(DIST, 0, t);
if (!reduced && mode === 'all') sc = lerp(SCALE, 1, t);
}
-
el.style.opacity = opacity;
el.style.transform = `translate3d(0,${ty}px,0) scale(${sc})`;
return top + el.offsetHeight > 0 && top < stage.clientHeight;
}
-
function updateOverlay() {
const h = stage.clientHeight, zH = Math.round(h * Z);
zoneExit.style.height = zH + 'px';
@@ -300,43 +255,36 @@ body{padding-top:46px}
zoneEntry.style.top = (h - zH) + 'px';
}
+ // A jump longer than the observer's margin (Back to top, Play starting again, a dragged scrollbar) brings in rows it has
+ // not added yet, still in the style they were left with: on a jump every row is styled once. The first call is a jump.
+ let lastTop = Infinity;
function update() {
- const st = stage.scrollTop;
- const max = stage.scrollHeight - stage.clientHeight;
- scrollProg.textContent = max > 0 ? Math.round(st / max * 100) + '%' : '0%';
- let onScreen = 0;
- visible.forEach(el => { if (applyRow(el)) onScreen++; }); // set includes a 50% margin — count only rows in view
- visCount.textContent = onScreen;
+ const jumped = Math.abs(stage.scrollTop - lastTop) > stage.clientHeight / 2;
+ lastTop = stage.scrollTop;
+ (jumped ? rows : visible).forEach(el => applyRow(el));
ticking = false;
}
-
- function schedule() {
- if (!ticking) { requestAnimationFrame(update); ticking = true; }
- }
-
+ function schedule() { if (!ticking) { requestAnimationFrame(update); ticking = true; } }
stage.addEventListener('scroll', schedule, { passive: true });
window.addEventListener('resize', () => { updateOverlay(); schedule(); });
motionMQ.addEventListener('change', schedule);
-
- distSl.addEventListener('input', () => { DIST = +distSl.value; distVal.textContent = DIST + 'px'; update(); });
- scaleSl.addEventListener('input', () => { SCALE = scaleSl.value / 100; scaleVal.textContent = SCALE.toFixed(2); update(); });
- zoneSl.addEventListener('input', () => { Z = zoneSl.value / 100; zoneVal.textContent = zoneSl.value + '%'; updateOverlay(); update(); });
- document.querySelectorAll('input[name="mode"]').forEach(r =>
- r.addEventListener('change', () => { mode = r.value; update(); }));
- previewTog.addEventListener('change', () => zoneOverlay.classList.toggle('visible', previewTog.checked));
-
- resetBtn.addEventListener('click', () => {
- distSl.value = 40; DIST = 40; distVal.textContent = '40px';
- scaleSl.value = 94; SCALE = 0.94; scaleVal.textContent = '0.94';
- zoneSl.value = 25; Z = 0.25; zoneVal.textContent = '25%';
- document.querySelector('input[value="all"]').checked = true; mode = 'all';
- previewTog.checked = false; zoneOverlay.classList.remove('visible');
- stage.scrollTop = 0; updateOverlay(); update();
- });
-
+ 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);
+ }));
+ }
+ // How far rows move matters unless the effect is only a fade; how much they shrink only when all three are on
+ choices('mode-seg', d => { mode = d.mode; distSetting.hidden = mode === 'fade'; scaleSetting.hidden = mode !== 'all'; update(); });
+ choices('zone-seg', d => { Z = +d.zone; updateOverlay(); update(); });
+ choices('dist-seg', d => { DIST = +d.dist; update(); });
+ choices('scale-seg', d => { SCALE = +d.scale; update(); });
+ zonesTog.addEventListener('change', () => zoneOverlay.classList.toggle('visible', zonesTog.checked));
updateOverlay();
update();
+ // The site font can land after the first paint and change the row heights, so style the rows again once the fonts are ready
+ if (document.fonts && document.fonts.ready) document.fonts.ready.then(update);
</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 2e08e689..02829324 100644
--- a/index.html
+++ b/index.html
@@ -883,7 +883,7 @@ const CATS=[
['parallax-scrolling','Parallax Scrolling','Far layers move slower than near ones as you scroll. Best for hero scenes.'],
['reverse-scrolling-columns','Reverse-Scrolling Columns','Side columns run the opposite way to the middle one. Best for portfolios.'],
['cover-card-to-fixed-header','Cover Card to Fixed Header','A tall cover shrinks into a slim header as you scroll. Best for articles.'],
- ['fly-in-fly-out-contact-list','Fly-in Fly-out Contact List','Rows translate and fade through entry, active, and exit zones as you scroll — bidirectional and continuous.'],
+ ['fly-in-fly-out-contact-list','Fly-in Fly-out Contact List','Rows fade and slide as they near the top or bottom edge. Best for long lists.'],
['stacking-cards','Stacking Cards','CSS Scroll-Driven Animations fan cards into a deck — per-index sticky offset creates the visible peek tab.'],
['scroll-trigger','ScrollTrigger Animation','The onEnter / onLeave lifecycle demonstrated with vanilla JS — four scroll trigger zones.'],
['scrub-animation','Scrub Animation','Scroll position is the playhead — a flight path doubles as its own timeline, seekable in either direction.'],