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 Reverse-Scrolling Columns to the guided-steps page

matindd060da8cb43
diff --git a/animations/01-scroll-based/reverse-scrolling-columns/README.md b/animations/01-scroll-based/reverse-scrolling-columns/README.md
index 07d7340b..3d6d3c24 100644
--- a/animations/01-scroll-based/reverse-scrolling-columns/README.md
+++ b/animations/01-scroll-based/reverse-scrolling-columns/README.md
@@ -4,12 +4,10 @@
## What it is
-Reverse-scrolling columns place a normally-scrolling center column between
-two flanking columns that scroll in the opposite direction. All three columns
-loop infinitely using a two-set DOM structure and modulo offset math. The
-opposing motion amplifies perceived depth: the brain interprets counter-motion
-as evidence of different distances — the same cue used in parallax, but made
-explicit and exaggerated.
+Reverse-scrolling columns put a column that scrolls normally between two
+columns that move the opposite way. The counter-motion makes the layout feel
+deep and lively, the same cue parallax uses, made stronger. Each column holds
+two copies of its cards and wraps around, so the columns never run out.
## When to use it
@@ -30,7 +28,7 @@ const cOff = -(scrollTop % singleSetH);
centerInner.style.transform = `translate3d(0, ${cOff}px, 0)`;
// Side columns — negative mult reverses direction; magnitude sets speed
-// (margin-top pre-offsets them by -singleSetH so there is content above)
+// (moving down, margin-top pre-offsets them by -singleSetH so there is content above; moving up, it is 0)
const sideOff = (scrollTop * Math.abs(mult)) % singleSetH;
const sideY = mult >= 0 ? -sideOff : sideOff; // negative = up, positive = down
sideInner.style.transform = `translate3d(0, ${sideY}px, 0)`;
@@ -47,10 +45,8 @@ seamless wrap when the second set aligns exactly with where the first started.
| Parameter | Default | Effect |
|-----------|---------|--------|
-| `mult` | −1.0 | Side-column direction and speed; negative = reverse |
-| `singleSetH` | measured | Height of one card set; determines loop period |
-| Card count | 12 | More cards = longer loop period |
-| Scene height | 2000px | Total scroll travel (max scroll = scene − viewport height) |
+| Side columns go | Opposite way | Opposite way makes the side columns flow against the scroll; same way moves all three together, so the effect disappears |
+| Side column speed | Same | The side columns' speed compared with the middle one: slower is half, same is equal and faster is one and a half times; above that the motion gets uncomfortable |
## Production notes
@@ -72,7 +68,5 @@ seamless wrap when the second set aligns exactly with where the first started.
## See also
-- [Parallax Scrolling](../parallax-scrolling/) — speed-ratio depth without
- opposing direction; the foundation this technique builds on.
-- [Parallax Depth-of-Field](../parallax-depth-of-field/) — depth via blur
- rather than directional contrast.
+- [Parallax Scrolling](../parallax-scrolling/) — layers move at different speeds as you scroll
+- [Parallax Depth-of-Field](../parallax-depth-of-field/) — layers move and blur as the focus shifts
diff --git a/animations/01-scroll-based/reverse-scrolling-columns/index.html b/animations/01-scroll-based/reverse-scrolling-columns/index.html
index 623565cc..5d0b29d1 100644
--- a/animations/01-scroll-based/reverse-scrolling-columns/index.html
+++ b/animations/01-scroll-based/reverse-scrolling-columns/index.html
@@ -4,7 +4,7 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Reverse-Scrolling Columns — Animation Handbook</title>
- <meta name="description" content="A center column that scrolls normally while two flanking columns scroll in the opposite direction.">
+ <meta name="description" content="Side columns run the opposite way to the middle one. Best for portfolios.">
<link rel="canonical" href="https://matinmonshizadeh.github.io/animation-handbook/animations/01-scroll-based/reverse-scrolling-columns/">
<link rel="icon" type="image/png" sizes="96x96" href="../../../favicon.png">
<link rel="icon" type="image/svg+xml" href="../../../favicon.svg">
@@ -12,46 +12,21 @@
<meta property="og:type" content="article">
<meta property="og:site_name" content="Animation Handbook">
<meta property="og:title" content="Reverse-Scrolling Columns — Animation Handbook">
- <meta property="og:description" content="A center column that scrolls normally while two flanking columns scroll in the opposite direction.">
+ <meta property="og:description" content="Side columns run the opposite way to the middle one. Best for portfolios.">
<meta property="og:url" content="https://matinmonshizadeh.github.io/animation-handbook/animations/01-scroll-based/reverse-scrolling-columns/">
<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="Reverse-Scrolling Columns — Animation Handbook">
- <meta name="twitter:description" content="A center column that scrolls normally while two flanking columns scroll in the opposite direction.">
+ <meta name="twitter:description" content="Side columns run the opposite way to the middle one. Best for portfolios.">
<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": "Reverse-Scrolling Columns", "name": "Reverse-Scrolling Columns", "description": "A center column that scrolls normally while two flanking columns scroll in the opposite direction.", "url": "https://matinmonshizadeh.github.io/animation-handbook/animations/01-scroll-based/reverse-scrolling-columns/", "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, Reverse-Scrolling Columns"}</script>
+ <script type="application/ld+json">{"@context": "https://schema.org", "@type": "TechArticle", "headline": "Reverse-Scrolling Columns", "name": "Reverse-Scrolling Columns", "description": "Side columns run the opposite way to the middle one. Best for portfolios.", "url": "https://matinmonshizadeh.github.io/animation-handbook/animations/01-scroll-based/reverse-scrolling-columns/", "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, Reverse-Scrolling Columns"}</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;
- --card-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);--card-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;
- }
+ .stage{position:relative;overflow-y:auto;scrollbar-width:none;container-type:size;background:#0b0b0d}
.stage::-webkit-scrollbar{display:none}
- .scene{height:2000px}
- .columns{
- position:sticky;top:0;height:620px;
- display:flex;gap:8px;overflow:hidden;padding:8px;
- }
+ .scene{height:320cqh}
+ .columns{position:sticky;top:0;height:100cqh;display:flex;gap:8px;overflow:hidden;padding:8px}
.col{flex:1;overflow:hidden}
.col-inner{display:flex;flex-direction:column;gap:8px;will-change:transform}
.card-set{display:flex;flex-direction:column;gap:8px}
@@ -65,125 +40,116 @@
width:28px;height:28px;border-radius:4px;flex-shrink:0;
display:flex;align-items:center;justify-content:center;
}
- .card-label{font-size:11px;color:var(--ui-text);letter-spacing:.3px}
- .card-meta{font-size:10px;color:var(--ui-muted);margin-top:2px}
-
- aside{
- width:clamp(200px,22vw,240px);flex-shrink:0;
- background:var(--ui-bg);border:1px solid var(--ui-border);
- border-radius:8px;padding:16px;
- display:flex;flex-direction:column;gap:10px;
- }
- .note{
- font-size:10px;color:var(--ui-muted);line-height:1.6;
- border-left:2px solid var(--ui-accent);padding-left:8px;
- }
- .lbl{font-size:10px;text-transform:uppercase;letter-spacing:1px;color:var(--ui-accent)}
- .row{display:flex;justify-content:space-between;font-size:10px}
- .row .v{color:var(--ui-text)}
- .tbl{display:flex;flex-direction:column;gap:2px}
- .tbl .row{font-size:10px;color:var(--ui-muted)}
- .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:40px;text-align:right;color:var(--ui-text)}
- .div{height:1px;background:var(--ui-border)}
- .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%;
- }
- button:hover{border-color:var(--ui-accent);color:var(--ui-accent)}
+ .card-label{font-size:13px;color:var(--ui-text);letter-spacing:.3px}
+ .card-meta{font-size:12px;color:var(--ui-muted);margin-top:2px}
- @media(max-width:600px){
- .layout{flex-direction:column}
- aside{width:100%}.stage{flex:none;width:100%}
- .stage{height:480px}
- .columns{height:480px}
- .col-right{display:none}
- }
+ @media(max-width:600px){.col-right{display:none}}
@media(prefers-reduced-motion:reduce){.col-inner{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="../parallax-scrolling/" rel="prev" title="Previous">‹ Prev</a><a class="ah-hideSm" href="../cover-card-to-fixed-header/" 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/reverse-scrolling-columns/index.html" target="_blank" rel="noopener noreferrer">Source ↗</a></span></div>
-
-<header>
- <h1>Reverse-Scrolling Columns</h1>
- <p>A center column that scrolls normally while two flanking columns scroll in the opposite direction.</p>
-</header>
-
-<div class="layout">
-
- <div class="stage" id="stage">
- <div class="scene">
- <div class="columns">
- <div class="col">
- <div class="col-inner" id="inner-left"></div>
- </div>
- <div class="col">
- <div class="col-inner" id="inner-center"></div>
- </div>
- <div class="col col-right">
- <div class="col-inner" id="inner-right"></div>
+<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="../parallax-scrolling/" rel="prev" aria-label="Previous: Parallax Scrolling"><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>Parallax Scrolling</span></a><a href="../cover-card-to-fixed-header/" rel="next" aria-label="Next: Cover Card to Fixed Header"><span><span class="hb-dir">Next: </span>Cover Card to Fixed Header</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.03 · Scroll-Based</p>
+ <h1>Reverse-Scrolling Columns</h1>
+ <p class="hb-lede">Side columns run the opposite way to the middle one. Best for portfolios.</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="Three columns of project cards">
+ <div class="scene">
+ <div class="columns">
+ <div class="col">
+ <div class="col-inner" id="inner-left"></div>
+ </div>
+ <div class="col">
+ <div class="col-inner" id="inner-center"></div>
+ </div>
+ <div class="col col-right">
+ <div class="col-inner" id="inner-right"></div>
+ </div>
</div>
</div>
</div>
- </div>
-
- <aside>
- <p class="note">The illusion of the side columns 'flowing the other way' is purely visual — they scroll at the same speed as your input, just in the opposite direction. Setting the multiplier to +1.0× makes them move with you and the effect disappears.</p>
-
- <div>
- <div class="lbl">Scroll Progress</div>
- <div class="row"><span>Progress</span><span class="v" id="progress">0%</span></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>
- <div class="lbl">Column Offsets</div>
- <div class="tbl">
- <div class="row"><span>Left</span><span class="v" id="off-left">0px</span></div>
- <div class="row"><span>Center</span><span class="v" id="off-center">0px</span></div>
- <div class="row"><span>Right</span><span class="v" id="off-right">0px</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 class="hb-settings">
+ <div class="hb-setting">
+ <p class="hb-setting-name" id="dir-lbl">Side columns go</p>
+ <div class="seg" id="dir-seg" role="group" aria-labelledby="dir-lbl">
+ <button type="button" data-dir="-1" class="on" aria-pressed="true">Opposite way</button>
+ <button type="button" data-dir="1" aria-pressed="false">Same way</button>
+ </div>
+ <p class="hb-hint">Same way shows the plain scroll, for comparison.</p>
+ </div>
+ <div class="hb-setting">
+ <p class="hb-setting-name" id="speed-lbl">Side column speed</p>
+ <div class="seg" id="speed-seg" role="group" aria-labelledby="speed-lbl">
+ <button type="button" data-speed="0.5" aria-pressed="false">Slower</button>
+ <button type="button" data-speed="1" class="on" aria-pressed="true">Same</button>
+ <button type="button" data-speed="1.5" aria-pressed="false">Faster</button>
+ </div>
+ <p class="hb-hint">Their speed compared with the middle column.</p>
</div>
</div>
+ </section>
- <div class="div"></div>
-
- <div>
- <div class="lbl" id="mult-label">Speed Multiplier</div>
- <div class="sr">
- <input type="range" id="mult-slider" aria-labelledby="mult-label" min="-200" max="200" step="10" value="-100">
- <span class="sv" id="mult-val">−1.0×</span>
+ <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 reverse-scrolling columns to [your grid of project cards or images]. Lay the cards out in three columns and hold them in view while the visitor scrolls through a taller section. Move the middle column up with the scroll, and move the two side columns in the direction and at the speed given in the settings; running them the opposite way makes them seem to flow against the scroll. Put two copies of the cards in each column and wrap the movement by exactly one copy's height, so the columns never run out. If the visitor has reduced motion turned on, keep the columns still. 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="match-tog">
- <input type="checkbox" id="match-tog">
- <span>Match direction (+1.0×)</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>Portfolios</li><li>Agency sites</li><li>Image galleries</li></ul>
+ <h3>Avoid on</h3>
+ <ul class="hb-tags hb-avoid"><li>Reading pages</li><li>Forms</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 CARDS = [
{s:'grid', l:'Project Alpha', m:'Design · 2024', a:'#58a6ff'},
@@ -220,65 +186,51 @@ body{padding-top:46px}
div.innerHTML = CARDS.map(c =>
`<div class="card">` +
`<div class="icon-box" style="background:${c.a}22;color:${c.a}">` +
- `<svg width="14" height="14" viewBox="0 0 14 14">${SVG[c.s]}</svg></div>` +
+ `<svg width="14" height="14" viewBox="0 0 14 14" aria-hidden="true">${SVG[c.s]}</svg></div>` +
`<div><div class="card-label">${c.l}</div>` +
`<div class="card-meta">${c.m}</div></div></div>`
).join('');
return div;
}
+ const stage = document.getElementById('stage');
const leftInner = document.getElementById('inner-left');
const centerInner = document.getElementById('inner-center');
const rightInner = document.getElementById('inner-right');
+ const motionMQ = window.matchMedia('(prefers-reduced-motion: reduce)');
[leftInner, centerInner, rightInner].forEach(el => {
el.appendChild(makeSet());
el.appendChild(makeSet());
});
+ // Side columns: dir -1 runs them the opposite way, +1 the same way; speed is their share of the middle column's.
+ let dir = -1, speed = 1, mult = -1;
+ let ticking = false;
+
// Loop period = one card-set plus the 8px col-inner gap. Re-measured after
- // webfonts land and on resize, because card height changes with the font.
+ // the webfont lands and on resize, because card height changes with the font.
let singleSetH = 0;
function measure() {
- singleSetH = leftInner.children[0].offsetHeight + 8;
- // Side columns travel downward by default: pre-offset them so set A sits
- // above the viewport and set B starts visible.
- leftInner.style.marginTop = `-${singleSetH}px`;
- rightInner.style.marginTop = `-${singleSetH}px`;
+ singleSetH = leftInner.children[0].getBoundingClientRect().height + 8;
+ // Moving down, the side columns are pre-offset so set A sits above the box
+ // and set B starts visible. Moving up they start at their own top: the
+ // pre-offset would leave up to a box of empty column below the last card.
+ const pre = mult < 0 ? `-${singleSetH}px` : '0px';
+ leftInner.style.marginTop = pre;
+ rightInner.style.marginTop = pre;
}
- const stage = document.getElementById('stage');
- const progEl = document.getElementById('progress');
- const offLeft = document.getElementById('off-left');
- const offCtr = document.getElementById('off-center');
- const offRight = document.getElementById('off-right');
- const slider = document.getElementById('mult-slider');
- const multVal = document.getElementById('mult-val');
- const matchTog = document.getElementById('match-tog');
- const resetBtn = document.getElementById('reset-btn');
- const motionMQ = window.matchMedia('(prefers-reduced-motion: reduce)');
- let mult = -1.0;
- let ticking = false;
-
- function fmt(n) { return (n > 0 ? '+' : n < 0 ? '−' : '') + Math.abs(n).toFixed(1) + '×'; }
-
function update() {
- const st = stage.scrollTop;
- const max = stage.scrollHeight - stage.clientHeight;
- progEl.textContent = max > 0 ? Math.round(st / max * 100) + '%' : '0%';
+ const st = stage.scrollTop;
ticking = false;
- // Reduced motion: columns stay put, but the readouts stay honest
- if (motionMQ.matches) {
- offCtr.textContent = offLeft.textContent = offRight.textContent = '0px';
- return;
- }
+ // Reduced motion: columns stay put
+ if (motionMQ.matches) return;
// Center: scrolls with the input — content travels up as you scroll down
- const cOff = -(st % singleSetH);
- centerInner.style.transform = `translate3d(0,${cOff}px,0)`;
- offCtr.textContent = Math.round(cOff) + 'px';
+ centerInner.style.transform = `translate3d(0,${-(st % singleSetH)}px,0)`;
// Sides: magnitude = speed, sign = direction (negative = down = reverse)
const sideRaw = st * Math.abs(mult);
@@ -286,44 +238,30 @@ body{padding-top:46px}
const sideY = mult >= 0 ? -sideOff : sideOff;
leftInner.style.transform = `translate3d(0,${sideY}px,0)`;
rightInner.style.transform = `translate3d(0,${sideY}px,0)`;
- offLeft.textContent = Math.round(sideY) + 'px';
- offRight.textContent = Math.round(sideY) + 'px';
}
stage.addEventListener('scroll', () => {
if (!ticking) { requestAnimationFrame(update); ticking = true; }
}, { passive: true });
- slider.addEventListener('input', () => {
- if (matchTog.checked) return;
- mult = slider.value / 100;
- multVal.textContent = fmt(mult);
- update();
- });
-
- matchTog.addEventListener('change', () => {
- mult = matchTog.checked ? 1.0 : slider.value / 100;
- multVal.textContent = fmt(mult);
- update();
- });
-
- resetBtn.addEventListener('click', () => {
- matchTog.checked = false;
- slider.value = -100;
- mult = -1.0;
- multVal.textContent = '−1.0×';
- stage.scrollTop = 0;
- 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);
+ }));
+ }
+ choices('dir-seg', d => { dir = +d.dir; mult = dir * speed; measure(); update(); });
+ choices('speed-seg', d => { speed = +d.speed; mult = dir * speed; update(); });
window.addEventListener('resize', () => { measure(); update(); });
- if (document.fonts && document.fonts.ready) {
- document.fonts.ready.then(() => { measure(); update(); });
- }
measure();
update();
+ // The site font can land after the first measure and change the card height, so measure again once the fonts are ready
+ if (document.fonts && document.fonts.ready) {
+ document.fonts.ready.then(() => { measure(); 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 0c154153..a6b7e078 100644
--- a/index.html
+++ b/index.html
@@ -881,7 +881,7 @@ const CATS=[
entries:[
['parallax-depth-of-field','Parallax Depth-of-Field','Layers move at their own speed as the focus shifts. Best for cinematic intros.'],
['parallax-scrolling','Parallax Scrolling','Far layers move slower than near ones as you scroll. Best for hero scenes.'],
- ['reverse-scrolling-columns','Reverse-Scrolling Columns','A center column scrolls normally while two flanking columns scroll in reverse, looping infinitely.'],
+ ['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 full-page hero morphs into a compact fixed header — every visual property scrubbed to a single progress value.'],
['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.'],
['stacking-cards','Stacking Cards','CSS Scroll-Driven Animations fan cards into a deck — per-index sticky offset creates the visible peek tab.'],