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: add 5 scroll-based animation demos (batch 1 — index.html only)

matinfaf13798a0fe
diff --git a/animations/01-scroll-based/pin-animation/index.html b/animations/01-scroll-based/pin-animation/index.html
new file mode 100644
index 00000000..f6e95d8d
--- /dev/null
+++ b/animations/01-scroll-based/pin-animation/index.html
@@ -0,0 +1,139 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <meta charset="UTF-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
+ <title>Pin Animation</title>
+ <style>
+ :root{--bg:#060a10;--ui-bg:#0d1117;--ui-border:#21262d;--ui-accent:#58a6ff;--ui-text:#c9d1d9;--ui-muted:#8b949e}
+ *,*::before,*::after{box-sizing:border-box;margin:0;padding:0}
+ body{background:var(--bg);color:var(--ui-text);font-family:monospace;padding:clamp(12px,3vw,24px)}
+ header{margin-bottom:20px}
+ header h1{font-size:clamp(11px,1.8vw,15px);letter-spacing:2px;text-transform:uppercase}
+ 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::-webkit-scrollbar{display:none}
+ /* Intro */
+ .intro{height:620px;display:flex;flex-direction:column;align-items:center;justify-content:center;text-align:center;padding:32px;border-bottom:1px solid var(--ui-border)}
+ .intro h2{font-size:clamp(20px,3vw,28px);margin-bottom:12px}
+ .intro p{font-size:13px;color:var(--ui-muted);max-width:340px;line-height:1.65}
+ /* Pin section */
+ .pin-section{height:1860px;position:relative}
+ .pin-inner{position:sticky;top:0;height:620px;display:flex;align-items:center;justify-content:center;gap:32px;padding:32px}
+ .phone-wrap{flex-shrink:0}
+ .copy-panel{flex:1;max-width:260px}
+ .feat-num{font-size:11px;letter-spacing:2px;text-transform:uppercase;color:var(--ui-accent);margin-bottom:10px}
+ .feat-title{font-size:clamp(18px,2.5vw,24px);font-weight:bold;margin-bottom:12px;line-height:1.2}
+ .feat-desc{font-size:12px;color:var(--ui-muted);line-height:1.7}
+ /* Outro */
+ .outro{height:620px;display:flex;flex-direction:column;align-items:center;justify-content:center;text-align:center;padding:32px;border-top:1px solid var(--ui-border)}
+ .outro h2{font-size:clamp(18px,2.5vw,24px);margin-bottom:10px}
+ .outro p{font-size:13px;color:var(--ui-muted);max-width:300px;line-height:1.6}
+ aside{width:clamp(200px,22vw,240px);flex-shrink:0;background:var(--ui-bg);border:1px solid var(--ui-border);border-radius:8px;padding:16px;display:flex;flex-direction:column;gap:10px}
+ .note{font-size:10px;color:var(--ui-muted);line-height:1.6;border-left:2px solid var(--ui-accent);padding-left:8px}
+ .lbl{font-size:10px;text-transform:uppercase;letter-spacing:1px;color:var(--ui-accent)}
+ .kv{display:flex;justify-content:space-between;font-size:10px;color:var(--ui-muted)}
+ .kv .v{color:var(--ui-text)}
+ .tbl{display:flex;flex-direction:column;gap:2px}
+ .div{height:1px;background:var(--ui-border)}
+ .feat-bar{display:flex;gap:4px;height:4px}
+ .feat-seg{flex:1;background:var(--ui-border);border-radius:2px;transition:background .3s}
+ .feat-seg.active{background:var(--ui-accent)}
+ 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{height:480px}.intro,.outro{height:480px}.pin-inner{flex-direction:column;gap:16px}.phone-wrap svg{transform:scale(.8)}}
+ @media(prefers-reduced-motion:reduce){.feat-seg{transition:none}}
+ </style>
+</head>
+<body>
+<header>
+ <h1>Pin Animation</h1>
+ <p>Element freezes in place while the page scrolls beneath it — CSS position: sticky, no JavaScript pinning.</p>
+</header>
+<div class="layout">
+ <div class="stage" id="stage">
+ <div class="intro">
+ <h2>Scroll to begin</h2>
+ <p>The phone mockup and feature copy below will pin to the viewport as you scroll through the section. CSS handles the pinning entirely.</p>
+ </div>
+ <div class="pin-section" id="pin-section">
+ <div class="pin-inner">
+ <div class="phone-wrap">
+ <svg width="110" height="200" viewBox="0 0 110 200">
+ <rect x="2" y="2" width="106" height="196" rx="16" fill="#1a1a2a" stroke="#3a3a5a" stroke-width="1.5"/>
+ <rect id="phone-screen" x="9" y="18" width="92" height="152" rx="8" fill="#0d2b3e"/>
+ <text id="phone-num" x="55" y="98" text-anchor="middle" font-family="monospace" font-size="28" font-weight="bold" fill="#58a6ff" opacity="0.5">01</text>
+ <text id="phone-icon" x="55" y="118" text-anchor="middle" font-family="monospace" font-size="11" fill="#c9d1d9" opacity="0.5">Instant Wake</text>
+ <rect x="38" y="183" width="34" height="4" rx="2" fill="#3a3a5a"/>
+ </svg>
+ </div>
+ <div class="copy-panel">
+ <div class="feat-num" id="feat-num">01 / 04</div>
+ <div class="feat-title" id="feat-title">Instant Wake</div>
+ <div class="feat-desc" id="feat-desc">The display responds in under 1ms. Always on, never waiting. The sensor layer never sleeps.</div>
+ </div>
+ </div>
+ </div>
+ <div class="outro">
+ <h2>Pin released</h2>
+ <p>Scroll continues normally. The phone and copy are back in the document flow — the pinned journey is complete.</p>
+ </div>
+ </div>
+ <aside>
+ <p class="note">Pinning makes an element stop scrolling with the page for a defined distance. The trick: the PARENT section must be taller than the viewport — the 'extra' height is the scroll distance during which the child stays pinned. CSS position: sticky handles this natively.</p>
+ <div><div class="lbl">Scroll state</div>
+ <div class="tbl">
+ <div class="kv"><span>Scroll</span><span class="v" id="scroll-prog">0%</span></div>
+ <div class="kv"><span>Lifecycle</span><span class="v" id="lifecycle">before pin</span></div>
+ <div class="kv"><span>Feature</span><span class="v" id="feat-ind">01 · Instant Wake</span></div>
+ </div>
+ </div>
+ <div class="div"></div>
+ <div><div class="lbl">Feature progress</div>
+ <div class="feat-bar" id="feat-bar">
+ <div class="feat-seg active"></div><div class="feat-seg"></div><div class="feat-seg"></div><div class="feat-seg"></div>
+ </div>
+ </div>
+ <button id="reset-btn">Reset scroll</button>
+ </aside>
+</div>
+<script>
+ const FEATURES=[
+ {num:'01',title:'Instant Wake', desc:'The display responds in under 1ms. Always on, never waiting. The sensor layer never sleeps.', color:'#0d2b3e',tcolor:'#58a6ff'},
+ {num:'02',title:'Computational Photography', desc:'Every frame processed by neural hardware in real time. Night mode renders before you lift the shutter.', color:'#1e3a1e',tcolor:'#3fb950'},
+ {num:'03',title:'On-Device Privacy', desc:'Face recognition, transcription, translation — all local. No data leaves the device.', color:'#2d1b3d',tcolor:'#bf91f3'},
+ {num:'04',title:'New Silicon Engine', desc:'Unified memory architecture. The gap between laptop and phone performance has effectively closed.', color:'#3d2000',tcolor:'#ffa657'},
+ ];
+ const stage=document.getElementById('stage'),pinSec=document.getElementById('pin-section');
+ const scrollProg=document.getElementById('scroll-prog'),lifecycleEl=document.getElementById('lifecycle');
+ const featNum=document.getElementById('feat-num'),featTitle=document.getElementById('feat-title'),featDesc=document.getElementById('feat-desc');
+ const featInd=document.getElementById('feat-ind'),featBar=document.getElementById('feat-bar');
+ const phoneScreen=document.getElementById('phone-screen'),phoneNum=document.getElementById('phone-num'),phoneIcon=document.getElementById('phone-icon');
+ const segs=[...featBar.children];
+ let ticking=false,lastFi=-1;
+ const clamp=(v,a,b)=>Math.min(Math.max(v,a),b);
+ function update(){
+ const st=stage.scrollTop,max=stage.scrollHeight-stage.clientHeight;
+ scrollProg.textContent=max>0?Math.round(st/max*100)+'%':'0%';
+ const ps=pinSec.offsetTop,ph=1860,vh=620;
+ let lifecycle='before pin',fi=0;
+ if(st>=ps&&st<ps+ph-vh){lifecycle='pinned · in section';const p=clamp((st-ps)/(ph-vh),0,1);fi=Math.min(3,Math.floor(p*4))}
+ else if(st>=ps+ph-vh){lifecycle='after release';fi=3}
+ lifecycleEl.textContent=lifecycle;
+ if(fi!==lastFi){
+ const f=FEATURES[fi];
+ featNum.textContent=`${f.num} / 04`;featTitle.textContent=f.title;featDesc.textContent=f.desc;
+ featInd.textContent=`${f.num} · ${f.title}`;
+ phoneScreen.setAttribute('fill',f.color);phoneNum.setAttribute('fill',f.tcolor);phoneNum.textContent=f.num;
+ phoneIcon.textContent=f.title.slice(0,16);phoneIcon.setAttribute('fill',f.tcolor);
+ segs.forEach((s,i)=>s.classList.toggle('active',i===fi));lastFi=fi;
+ }
+ ticking=false;
+ }
+ stage.addEventListener('scroll',()=>{if(!ticking){requestAnimationFrame(update);ticking=true}},{passive:true});
+ document.getElementById('reset-btn').addEventListener('click',()=>{stage.scrollTop=0;update()});
+ update();
+</script>
+</body>
+</html>
diff --git a/animations/01-scroll-based/scroll-trigger/index.html b/animations/01-scroll-based/scroll-trigger/index.html
new file mode 100644
index 00000000..5cebd5be
--- /dev/null
+++ b/animations/01-scroll-based/scroll-trigger/index.html
@@ -0,0 +1,184 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <meta charset="UTF-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
+ <title>ScrollTrigger Animation</title>
+ <style>
+ :root{--bg:#060a10;--ui-bg:#0d1117;--ui-border:#21262d;--ui-accent:#58a6ff;--ui-text:#c9d1d9;--ui-muted:#8b949e}
+ *,*::before,*::after{box-sizing:border-box;margin:0;padding:0}
+ body{background:var(--bg);color:var(--ui-text);font-family:monospace;padding:clamp(12px,3vw,24px)}
+ header{margin-bottom:20px}
+ header h1{font-size:clamp(11px,1.8vw,15px);letter-spacing:2px;text-transform:uppercase}
+ 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::-webkit-scrollbar{display:none}
+ .zone{min-height:550px;padding:32px 24px;border-top:1px dashed;border-bottom:1px dashed;position:relative;display:flex;flex-direction:column;justify-content:center}
+ .zone-tag{position:absolute;top:10px;left:12px;font-size:9px;letter-spacing:1px;text-transform:uppercase;padding:3px 8px;border-radius:4px;opacity:.8}
+ .z1{background:rgba(88,166,255,.06);border-color:rgba(88,166,255,.25)}
+ .z2{background:rgba(191,145,243,.06);border-color:rgba(191,145,243,.25)}
+ .z3{background:rgba(63,185,80,.06);border-color:rgba(63,185,80,.25)}
+ .z4{background:rgba(248,81,73,.06);border-color:rgba(248,81,73,.25)}
+ .z1 .zone-tag{background:rgba(88,166,255,.15);color:#58a6ff}
+ .z2 .zone-tag{background:rgba(191,145,243,.15);color:#bf91f3}
+ .z3 .zone-tag{background:rgba(63,185,80,.15);color:#3fb950}
+ .z4 .zone-tag{background:rgba(248,81,73,.15);color:#f85149}
+ /* Zone 1 */
+ .reveal-content{opacity:0;transform:translateY(30px);transition:opacity .5s,transform .5s}
+ .reveal-content.active{opacity:1;transform:none}
+ @media(prefers-reduced-motion:reduce){.reveal-content{transition:none}}
+ .reveal-title{font-size:clamp(18px,3vw,26px);font-weight:bold;margin-bottom:8px}
+ .reveal-sub{font-size:13px;color:var(--ui-muted);line-height:1.6}
+ /* Zone 2 */
+ .swatch{width:90px;height:90px;border-radius:12px;background:var(--ui-accent);will-change:transform,filter;margin:24px auto}
+ /* Zone 3 */
+ .pin-card{background:var(--ui-bg);border:1px solid var(--ui-border);border-radius:8px;padding:20px;max-width:340px;margin:0 auto}
+ .pin-step{font-size:12px;color:var(--ui-accent);margin-bottom:6px}
+ .pin-title{font-size:16px;font-weight:bold}
+ .pin-body{font-size:12px;color:var(--ui-muted);margin-top:8px;line-height:1.6}
+ /* Zone 4 */
+ .snap-dots-z4{display:flex;gap:14px;justify-content:center;margin:20px 0}
+ .snap-dot{width:10px;height:10px;border-radius:50%;background:var(--ui-border);transition:background .2s,transform .2s}
+ .snap-dot.lit{transform:scale(1.5)}
+ 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}
+ .pills{display:flex;flex-direction:column;gap:3px}
+ .pill{font-size:9px;padding:3px 8px;border-radius:10px;border:1px solid var(--ui-border);color:var(--ui-muted)}
+ .pill.active{border-color:var(--ui-accent);color:var(--ui-accent)}
+ .pill.past{border-color:var(--ui-border);color:var(--ui-muted);opacity:.45}
+ .div{height:1px;background:var(--ui-border)}
+ .cb-log{display:flex;flex-direction:column;gap:2px;font-size:9px;color:var(--ui-muted);font-family:monospace;min-height:70px}
+ 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{height:480px}}
+ </style>
+</head>
+<body>
+<header>
+ <h1>ScrollTrigger Animation</h1>
+ <p>Lifecycle callbacks — onEnter, onLeave, onEnterBack, onLeaveBack — demonstrated with vanilla JS.</p>
+</header>
+<div class="layout">
+ <div class="stage" id="stage">
+ <div class="zone z1" id="zone1">
+ <span class="zone-tag">Fade on Enter</span>
+ <div class="reveal-content" id="reveal">
+ <div class="reveal-title">Enter to Reveal</div>
+ <div class="reveal-sub">This content fades in when the zone enters the viewport, and resets when it leaves. That is the onEnter / onLeave lifecycle in action.</div>
+ </div>
+ </div>
+ <div class="zone z2" id="zone2">
+ <span class="zone-tag">Scrub</span>
+ <div style="text-align:center">
+ <div style="font-size:12px;color:var(--ui-muted);margin-bottom:4px">Scroll position drives rotation, scale, and hue</div>
+ <div class="swatch" id="swatch"></div>
+ <div style="font-size:11px;color:var(--ui-muted)" id="scrub-val">progress: 0%</div>
+ </div>
+ </div>
+ <div class="zone z3" id="zone3">
+ <span class="zone-tag">Pin + Scrub</span>
+ <div class="pin-card" id="pin-card">
+ <div class="pin-step" id="pin-step">Step 1 of 3</div>
+ <div class="pin-title" id="pin-title">Initialize</div>
+ <div class="pin-body" id="pin-body">The trigger fires. The animation begins. State is set.</div>
+ </div>
+ </div>
+ <div class="zone z4" id="zone4">
+ <span class="zone-tag">Snap</span>
+ <div style="text-align:center">
+ <div style="font-size:12px;color:var(--ui-muted);margin-bottom:4px">Scroll to light up snap points</div>
+ <div class="snap-dots-z4" id="snap-dots-z4">
+ <div class="snap-dot" style="--c:#f85149"></div>
+ <div class="snap-dot" style="--c:#f85149"></div>
+ <div class="snap-dot" style="--c:#f85149"></div>
+ <div class="snap-dot" style="--c:#f85149"></div>
+ <div class="snap-dot" style="--c:#f85149"></div>
+ </div>
+ <div style="font-size:11px;color:var(--ui-muted)" id="snap-val">0 / 5 lit</div>
+ </div>
+ </div>
+ </div>
+ <aside>
+ <p class="note">ScrollTrigger isn't an animation type — it's the MECHANISM that fires animations at the right scroll position. The four zones below show its core behaviors. In production, GSAP's ScrollTrigger plugin handles all of this.</p>
+ <div><div class="lbl">Scroll progress</div>
+ <div class="kv"><span>Overall</span><span class="v" id="scroll-prog">0%</span></div>
+ </div>
+ <div><div class="lbl">Zone status</div>
+ <div class="pills">
+ <div class="pill" id="pill1">Zone 1 · Fade on Enter · idle</div>
+ <div class="pill" id="pill2">Zone 2 · Scrub · idle</div>
+ <div class="pill" id="pill3">Zone 3 · Pin + Scrub · idle</div>
+ <div class="pill" id="pill4">Zone 4 · Snap · idle</div>
+ </div>
+ </div>
+ <div class="div"></div>
+ <div><div class="lbl">Callback log</div><div class="cb-log" id="cb-log"><span style="color:var(--ui-border)">— no events yet —</span></div></div>
+ <button id="reset-btn">Reset scroll</button>
+ </aside>
+</div>
+<script>
+ const stage=document.getElementById('stage'),scrollProg=document.getElementById('scroll-prog');
+ const zone1=document.getElementById('zone1'),zone2=document.getElementById('zone2');
+ const zone3=document.getElementById('zone3'),zone4=document.getElementById('zone4');
+ const reveal=document.getElementById('reveal'),swatch=document.getElementById('swatch');
+ const scrubVal=document.getElementById('scrub-val');
+ const pinStep=document.getElementById('pin-step'),pinTitle=document.getElementById('pin-title'),pinBody=document.getElementById('pin-body');
+ const snapDots4=[...document.getElementById('snap-dots-z4').children],snapVal=document.getElementById('snap-val');
+ const pills=[document.getElementById('pill1'),document.getElementById('pill2'),document.getElementById('pill3'),document.getElementById('pill4')];
+ const cbLog=document.getElementById('cb-log');
+ const PIN_STEPS=[['Step 1 of 3','Initialize','The trigger fires. The animation begins. State is set.'],['Step 2 of 3','Process','Scroll-linked progress drives every value. Each pixel is intentional.'],['Step 3 of 3','Complete','The trigger fires onLeave. State is captured. Callback logged.']];
+ let ticking=false,prevState=[null,null,null,null],cbEvents=[];
+ const clamp=(v,a,b)=>Math.min(Math.max(v,a),b);
+ const lerp=(a,b,t)=>a+(b-a)*t;
+ function zoneProgress(zone){const vt=stage.scrollTop,vb=vt+stage.clientHeight,zt=zone.offsetTop,zb=zt+zone.offsetHeight;if(vb<=zt||vt>=zb)return null;return clamp((vt-zt)/(zone.offsetHeight-stage.clientHeight),0,1)}
+ function zoneState(zone){const vt=stage.scrollTop,vb=vt+stage.clientHeight,zt=zone.offsetTop,zb=zt+zone.offsetHeight;if(vb<=zt)return'idle';if(vt>=zb)return'past';return'active'}
+ function logEvent(msg){cbEvents=[msg,...cbEvents].slice(0,5);cbLog.innerHTML=cbEvents.map(e=>`<span>${e}</span>`).join('')}
+ const NAMES=['Fade on Enter','Scrub','Pin + Scrub','Snap'];
+ function update(){
+ const st=stage.scrollTop,max=stage.scrollHeight-stage.clientHeight;
+ scrollProg.textContent=max>0?Math.round(st/max*100)+'%':'0%';
+ const states=[zoneState(zone1),zoneState(zone2),zoneState(zone3),zoneState(zone4)];
+ states.forEach((s,i)=>{
+ pills[i].textContent=`Zone ${i+1} · ${NAMES[i]} · ${s}`;
+ pills[i].className='pill'+(s==='active'?' active':s==='past'?' past':'');
+ if(s!==prevState[i]){
+ const ev=s==='active'?(prevState[i]==='idle'?'onEnter':'onEnterBack'):(s==='past'?'onLeave':'onLeaveBack');
+ logEvent(`${s==='active'?'→':'←'} zone ${i+1} · ${ev}`);
+ prevState[i]=s;
+ }
+ });
+ // Zone 1
+ reveal.classList.toggle('active',states[0]==='active');
+ // Zone 2
+ if(states[1]==='active'){
+ const p=clamp((st-zone2.offsetTop)/(zone2.offsetHeight-stage.clientHeight*.5),0,1);
+ swatch.style.transform=`rotate(${lerp(0,180,p)}deg) scale(${lerp(1,1.3,p)})`;
+ swatch.style.filter=`hue-rotate(${lerp(0,120,p)}deg)`;
+ scrubVal.textContent=`progress: ${Math.round(p*100)}%`;
+ }
+ // Zone 3
+ if(states[2]==='active'){
+ const p=clamp((st-zone3.offsetTop)/(zone3.offsetHeight-stage.clientHeight*.5),0,1);
+ const si=Math.min(2,Math.floor(p*3));
+ pinStep.textContent=PIN_STEPS[si][0];pinTitle.textContent=PIN_STEPS[si][1];pinBody.textContent=PIN_STEPS[si][2];
+ }
+ // Zone 4
+ if(states[3]==='active'||states[3]==='past'){
+ const p=clamp((st-zone4.offsetTop)/(zone4.offsetHeight),0,1);
+ const lit=Math.round(p*5);
+ snapDots4.forEach((d,i)=>{d.classList.toggle('lit',i<lit);d.style.background=i<lit?'#f85149':'var(--ui-border)'});
+ snapVal.textContent=`${lit} / 5 lit`;
+ }
+ ticking=false;
+ }
+ stage.addEventListener('scroll',()=>{if(!ticking){requestAnimationFrame(update);ticking=true}},{passive:true});
+ document.getElementById('reset-btn').addEventListener('click',()=>{stage.scrollTop=0;update()});
+ update();
+</script>
+</body>
+</html>
diff --git a/animations/01-scroll-based/scrub-animation/index.html b/animations/01-scroll-based/scrub-animation/index.html
new file mode 100644
index 00000000..91edb7f9
--- /dev/null
+++ b/animations/01-scroll-based/scrub-animation/index.html
@@ -0,0 +1,154 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <meta charset="UTF-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
+ <title>Scrub Animation</title>
+ <style>
+ :root{--bg:#060a10;--ui-bg:#0d1117;--ui-border:#21262d;--ui-accent:#58a6ff;--ui-text:#c9d1d9;--ui-muted:#8b949e}
+ *,*::before,*::after{box-sizing:border-box;margin:0;padding:0}
+ body{background:var(--bg);color:var(--ui-text);font-family:monospace;padding:clamp(12px,3vw,24px)}
+ header{margin-bottom:20px}
+ header h1{font-size:clamp(11px,1.8vw,15px);letter-spacing:2px;text-transform:uppercase}
+ 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::-webkit-scrollbar{display:none}
+ .scroll-space{height:1500px}
+ .scene{position:sticky;top:0;height:620px;display:flex;flex-direction:column;align-items:center;justify-content:center;overflow:hidden}
+ svg#lens{overflow:visible}
+ .caption{margin-top:24px;font-size:11px;color:var(--ui-muted);letter-spacing:1px;text-align:center;min-height:20px}
+ 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}
+ .div{height:1px;background:var(--ui-border)}
+ .timeline{position:relative;height:20px;background:var(--ui-border);border-radius:10px;margin-top:4px;overflow:hidden}
+ .tl-fill{height:100%;background:var(--ui-accent);border-radius:10px;width:0%;transition:none}
+ .tl-ticks{position:absolute;top:0;left:0;right:0;bottom:0;display:flex}
+ .tl-tick{flex:1;border-right:1px solid rgba(255,255,255,.12)}
+ .jump-btns{display:flex;gap:6px}
+ .jump-btn{flex:1;background:transparent;border:1px solid var(--ui-border);color:var(--ui-muted);font-family:monospace;font-size:9px;padding:10px 4px;border-radius:4px;cursor:pointer;min-height:44px}
+ @media(hover:hover){.jump-btn:hover{border-color:var(--ui-accent);color:var(--ui-accent)}}
+ @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}.stage{height:480px}.scene{height:480px}}
+ @media(prefers-reduced-motion:reduce){.tl-fill{transition:none}}
+ </style>
+</head>
+<body>
+<header>
+ <h1>Scrub Animation</h1>
+ <p>Timeline linked to scroll position — scrub backward and the animation reverses perfectly.</p>
+</header>
+<div class="layout">
+ <div class="stage" id="stage">
+ <div class="scroll-space">
+ <div class="scene">
+ <svg id="lens" width="220" height="220" viewBox="-110 -110 220 220">
+ <!-- Lens body (main barrel) -->
+ <g id="lens-body">
+ <circle r="98" fill="#1a1a2a" stroke="#3a3a5a" stroke-width="1.5"/>
+ <circle r="82" fill="#111120" stroke="#2a2a4a" stroke-width="1"/>
+ </g>
+ <!-- Hood (outer rim) -->
+ <g id="lens-hood">
+ <circle r="105" fill="none" stroke="#4a4a6a" stroke-width="8" stroke-dasharray="12 4"/>
+ <circle r="99" fill="none" stroke="#58a6ff" stroke-width="1" opacity="0.4"/>
+ </g>
+ <!-- Iris aperture blades -->
+ <g id="iris">
+ <ellipse rx="28" ry="8" fill="#2a2a3a" transform="rotate(0) translate(0,-38)"/>
+ <ellipse rx="28" ry="8" fill="#2a2a3a" transform="rotate(60) translate(0,-38)"/>
+ <ellipse rx="28" ry="8" fill="#2a2a3a" transform="rotate(120) translate(0,-38)"/>
+ <ellipse rx="28" ry="8" fill="#2a2a3a" transform="rotate(180) translate(0,-38)"/>
+ <ellipse rx="28" ry="8" fill="#2a2a3a" transform="rotate(240) translate(0,-38)"/>
+ <ellipse rx="28" ry="8" fill="#2a2a3a" transform="rotate(300) translate(0,-38)"/>
+ </g>
+ <!-- Front glass element -->
+ <g id="lens-glass">
+ <circle r="56" fill="#0d2040" stroke="#58a6ff" stroke-width="1.5" opacity="0.9"/>
+ <circle r="44" fill="#091828" stroke="#3a6a9a" stroke-width="1"/>
+ <circle r="28" fill="#060e18" stroke="#2a4a6a" stroke-width="1"/>
+ <ellipse cx="-12" cy="-12" rx="8" ry="5" fill="rgba(88,166,255,0.08)" transform="rotate(-20,-12,-12)"/>
+ </g>
+ <!-- Core / sensor -->
+ <g id="lens-core">
+ <circle r="14" fill="#58a6ff" opacity="0.15"/>
+ <circle r="9" fill="#58a6ff" opacity="0.3"/>
+ <circle r="5" fill="#58a6ff" opacity="0.6"/>
+ </g>
+ </svg>
+ <div class="caption" id="caption">01 · Assembled</div>
+ </div>
+ </div>
+ </div>
+ <aside>
+ <p class="note">Scrub is not a 'play' — it's a 'position'. The animation has no duration, no autoplay. Scroll IS the seek bar. Try scrolling halfway down, then back up — the parts reassemble perfectly.</p>
+ <div><div class="lbl">Playback</div>
+ <div class="tbl">
+ <div class="kv"><span>Scroll</span><span class="v" id="scroll-prog">0%</span></div>
+ <div class="kv"><span>Stage</span><span class="v" id="stage-label">01 · Assembled</span></div>
+ <div class="kv"><span>Direction</span><span class="v" id="direction">·</span></div>
+ </div>
+ </div>
+ <div class="div"></div>
+ <div><div class="lbl">Timeline</div>
+ <div class="timeline"><div class="tl-fill" id="tl-fill"></div><div class="tl-ticks"><div class="tl-tick"></div><div class="tl-tick"></div><div class="tl-tick"></div><div class="tl-tick"></div><div class="tl-tick"></div></div></div>
+ </div>
+ <div><div class="lbl">Jump to</div>
+ <div class="jump-btns">
+ <button class="jump-btn" id="j-start">Start</button>
+ <button class="jump-btn" id="j-mid">Middle</button>
+ <button class="jump-btn" id="j-end">End</button>
+ </div>
+ </div>
+ </aside>
+</div>
+<script>
+ const stage=document.getElementById('stage');
+ const hood=document.getElementById('lens-hood'),iris=document.getElementById('iris');
+ const glass=document.getElementById('lens-glass'),body_=document.getElementById('lens-body');
+ const core=document.getElementById('lens-core'),caption=document.getElementById('caption');
+ const scrollProg=document.getElementById('scroll-prog'),stageLabel=document.getElementById('stage-label');
+ const dirEl=document.getElementById('direction'),tlFill=document.getElementById('tl-fill');
+ const motionMQ=window.matchMedia('(prefers-reduced-motion: reduce)');
+ let ticking=false,lastSt=0;
+ const lerp=(a,b,t)=>a+(b-a)*t;
+ const clamp=(v,a,b)=>Math.min(Math.max(v,a),b);
+ const ease=(t)=>t;
+ const CAPTIONS=['01 · Assembled','01 · Hood lifts','02 · Glass forward','03 · Iris opens','04 · Body separates','05 · Core exposed'];
+ function update(){
+ const st=stage.scrollTop,max=stage.scrollHeight-stage.clientHeight;
+ const p=max>0?st/max:0;
+ scrollProg.textContent=Math.round(p*100)+'%';
+ tlFill.style.width=Math.round(p*100)+'%';
+ const ci=Math.round(p*5);stageLabel.textContent=CAPTIONS[ci];caption.textContent=CAPTIONS[ci];
+ dirEl.textContent=st>lastSt?'→ forward':st<lastSt?'← reverse':'· paused';lastSt=st;
+ if(motionMQ.matches){ticking=false;return}
+ // Stage 1 (0–18%): hood lifts
+ const t1=clamp(p/0.18,0,1);
+ hood.style.transform=`translateY(${lerp(0,-70,t1)}px)`;
+ hood.style.opacity=lerp(1,0,t1);
+ // Stage 2 (18–36%): glass forward
+ const t2=clamp((p-0.18)/0.18,0,1);
+ glass.style.transform=`translateY(${lerp(0,-45,t2)}px) scale(${lerp(1,1.15,t2)})`;
+ // Stage 3 (36–54%): iris rotates
+ const t3=clamp((p-0.36)/0.18,0,1);
+ iris.style.transform=`rotate(${lerp(0,90,t3)}deg)`;
+ // Stage 4 (54–72%): body separates
+ const t4=clamp((p-0.54)/0.18,0,1);
+ body_.style.transform=`translateX(${lerp(0,-65,t4)}px)`;body_.style.opacity=lerp(1,0.5,t4);
+ // Stage 5 (72–90%): core exposed
+ const t5=clamp((p-0.72)/0.18,0,1);
+ core.style.transform=`scale(${lerp(1,2,t5)})`;core.style.filter=`brightness(${lerp(1,2.5,t5)})`;
+ ticking=false;
+ }
+ stage.addEventListener('scroll',()=>{if(!ticking){requestAnimationFrame(update);ticking=true}},{passive:true});
+ document.getElementById('j-start').addEventListener('click',()=>stage.scrollTo({top:0,behavior:'smooth'}));
+ document.getElementById('j-mid').addEventListener('click',()=>stage.scrollTo({top:(stage.scrollHeight-stage.clientHeight)/2,behavior:'smooth'}));
+ document.getElementById('j-end').addEventListener('click',()=>stage.scrollTo({top:stage.scrollHeight-stage.clientHeight,behavior:'smooth'}));
+ update();
+</script>
+</body>
+</html>
diff --git a/animations/01-scroll-based/snap-scrolling/index.html b/animations/01-scroll-based/snap-scrolling/index.html
new file mode 100644
index 00000000..65202c2b
--- /dev/null
+++ b/animations/01-scroll-based/snap-scrolling/index.html
@@ -0,0 +1,129 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <meta charset="UTF-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
+ <title>Snap Scrolling</title>
+ <style>
+ :root{--bg:#060a10;--ui-bg:#0d1117;--ui-border:#21262d;--ui-accent:#58a6ff;--ui-text:#c9d1d9;--ui-muted:#8b949e}
+ *,*::before,*::after{box-sizing:border-box;margin:0;padding:0}
+ body{background:var(--bg);color:var(--ui-text);font-family:monospace;padding:clamp(12px,3vw,24px)}
+ header{margin-bottom:20px}
+ header h1{font-size:clamp(11px,1.8vw,15px);letter-spacing:2px;text-transform:uppercase}
+ 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-wrap{flex:1;min-width:0;position:relative}
+ .stage{height:620px;overflow-y:scroll;scrollbar-width:none;border:1px solid var(--ui-border);border-radius:8px;scroll-snap-type:y mandatory;scroll-behavior:smooth}
+ .stage::-webkit-scrollbar{display:none}
+ .section{height:620px;scroll-snap-align:start;display:flex;flex-direction:column;align-items:center;justify-content:center;padding:40px;text-align:center;position:relative}
+ .sec-num{font-size:11px;letter-spacing:2px;text-transform:uppercase;margin-bottom:16px}
+ .sec-title{font-size:clamp(20px,3vw,30px);font-weight:bold;margin-bottom:14px;line-height:1.2}
+ .sec-sub{font-size:13px;opacity:.65;max-width:360px;line-height:1.65}
+ .stats{display:flex;gap:24px;margin-top:20px}
+ .stat{text-align:center}
+ .stat-val{font-size:22px;font-weight:bold;color:var(--ui-accent)}
+ .stat-label{font-size:10px;color:var(--ui-muted);margin-top:3px}
+ .pull-quote{font-style:italic;font-size:clamp(16px,2.5vw,22px);line-height:1.5;max-width:420px;margin-bottom:12px}
+ .quote-attr{font-size:11px;opacity:.5}
+ .snap-dots{position:absolute;right:-28px;top:50%;transform:translateY(-50%);display:flex;flex-direction:column;gap:8px}
+ .dot{width:8px;height:8px;border-radius:50%;background:var(--ui-muted);cursor:pointer;transition:background .2s,transform .2s}
+ .dot.active{background:var(--ui-accent);transform:scale(1.4)}
+ 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}
+ .div{height:1px;background:var(--ui-border)}
+ .mode-btns{display:flex;flex-direction:column;gap:4px}
+ .mode-btn{background:transparent;border:1px solid var(--ui-border);color:var(--ui-muted);font-family:monospace;font-size:9px;padding:10px 8px;border-radius:4px;cursor:pointer;text-align:left;min-height:44px}
+ .mode-btn.active{border-color:var(--ui-accent);color:var(--ui-accent)}
+ .jump-btns{display:flex;flex-direction:column;gap:4px}
+ .jump-btn{background:transparent;border:1px solid var(--ui-border);color:var(--ui-muted);font-family:monospace;font-size:9px;padding:8px;border-radius:4px;cursor:pointer;min-height:36px}
+ @media(hover:hover){.mode-btn:hover,.jump-btn:hover{border-color:var(--ui-accent);color:var(--ui-accent)}}
+ @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}.stage{height:480px}.section{height:480px}.snap-dots{right:8px;position:fixed;top:auto;transform:none;bottom:120px}}
+ </style>
+</head>
+<body>
+<header>
+ <h1>Snap Scrolling</h1>
+ <p>Page snaps to defined sections — CSS scroll-snap-type creates a deliberate paginated feel.</p>
+</header>
+<div class="layout">
+ <div class="stage-wrap">
+ <div class="stage" id="stage"></div>
+ <div class="snap-dots" id="snap-dots"></div>
+ </div>
+ <aside>
+ <p class="note">Snap scrolling is native CSS — three lines and zero JavaScript do the magnetism. 'mandatory' forces a snap on every scroll. 'proximity' only snaps when close to a point. 'none' disables it. Switch modes and feel the difference.</p>
+ <div><div class="lbl">Current section</div>
+ <div class="tbl">
+ <div class="kv"><span>Position</span><span class="v" id="sec-pos">01 / 05</span></div>
+ <div class="kv"><span>Title</span><span class="v" id="sec-title-el" style="text-align:right;max-width:130px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap">Pages, not pixels</span></div>
+ <div class="kv"><span>Status</span><span class="v" id="status">locked on snap point</span></div>
+ </div>
+ </div>
+ <div class="div"></div>
+ <div><div class="lbl">Snap mode</div>
+ <div class="mode-btns" id="mode-btns">
+ <button class="mode-btn active" data-mode="y mandatory">y mandatory</button>
+ <button class="mode-btn" data-mode="y proximity">y proximity</button>
+ <button class="mode-btn" data-mode="none">none</button>
+ </div>
+ </div>
+ <div class="div"></div>
+ <div><div class="lbl">Jump to section</div>
+ <div class="jump-btns" id="jump-btns"></div>
+ </div>
+ </aside>
+</div>
+<script>
+ const SECTIONS=[
+ {num:'01',title:'Pages, not pixels', bg:'linear-gradient(160deg,#050e08,#0c2820)',accent:'#3fb950',type:'hero', sub:'Snap scrolling divides continuous scroll into deliberate stops. Each section is a destination.'},
+ {num:'02',title:'Magnetic edges', bg:'linear-gradient(160deg,#060a10,#0a1628)',accent:'#58a6ff',type:'default',sub:'The browser engine pulls the viewport to the nearest snap point on scroll-end.'},
+ {num:'03',title:'Pagination feel', bg:'linear-gradient(160deg,#0a0610,#1a0c28)',accent:'#bf91f3',type:'stats', sub:'Design for sections, not infinite scroll. Each stop is a chapter.'},
+ {num:'04',title:'"The feeling of deliberate motion is hard to achieve with code alone."',bg:'linear-gradient(160deg,#100806,#281808)',accent:'#ffa657',type:'quote',sub:'— on scroll design'},
+ {num:'05',title:"That's the whole trick", bg:'linear-gradient(160deg,#060810,#0c1020)',accent:'#79c0ff',type:'default',sub:'Three CSS properties. Zero JavaScript. Instant section-based UX.'},
+ ];
+ const stage=document.getElementById('stage'),snapDots=document.getElementById('snap-dots');
+ SECTIONS.forEach((s,i)=>{
+ const sec=document.createElement('div');sec.className='section';sec.style.background=s.bg;
+ let inner=`<div class="sec-num" style="color:${s.accent}">${s.num} / 05</div>`;
+ if(s.type==='quote'){
+ inner+=`<div class="pull-quote" style="color:${s.accent}">${s.title}</div><div class="quote-attr">${s.sub}</div>`;
+ } else {
+ inner+=`<div class="sec-title">${s.title}</div><div class="sec-sub">${s.sub}</div>`;
+ if(s.type==='stats') inner+=`<div class="stats"><div class="stat"><div class="stat-val" style="color:${s.accent}">5</div><div class="stat-label">Snap points</div></div><div class="stat"><div class="stat-val" style="color:${s.accent}">3</div><div class="stat-label">Lines of CSS</div></div><div class="stat"><div class="stat-val" style="color:${s.accent}">0</div><div class="stat-label">JS needed</div></div></div>`;
+ }
+ sec.innerHTML=inner;stage.appendChild(sec);
+ const dot=document.createElement('div');dot.className='dot'+(i===0?' active':'');
+ dot.addEventListener('click',()=>stage.scrollTo({top:i*620,behavior:'smooth'}));
+ snapDots.appendChild(dot);
+ });
+ const jumpBtns=document.getElementById('jump-btns');
+ SECTIONS.forEach((s,i)=>{
+ const btn=document.createElement('button');btn.className='jump-btn';
+ btn.textContent=`${s.num} · ${s.title.slice(0,20)}${s.title.length>20?'…':''}`;
+ btn.addEventListener('click',()=>stage.scrollTo({top:i*620,behavior:'smooth'}));
+ jumpBtns.appendChild(btn);
+ });
+ document.querySelectorAll('.mode-btn').forEach(btn=>{
+ btn.addEventListener('click',()=>{
+ stage.style.scrollSnapType=btn.dataset.mode==='none'?'none':btn.dataset.mode;
+ document.querySelectorAll('.mode-btn').forEach(b=>b.classList.remove('active'));
+ btn.classList.add('active');
+ });
+ });
+ const secPos=document.getElementById('sec-pos'),secTitleEl=document.getElementById('sec-title-el'),statusEl=document.getElementById('status');
+ const dots=snapDots.querySelectorAll('.dot');
+ function getStatus(st){const snap=Math.round(st/620)*620;if(Math.abs(st-snap)<2)return'locked on snap point';if(Math.abs(st-snap)<60)return'snapping…';return'scrolling freely'}
+ stage.addEventListener('scroll',()=>{
+ const st=stage.scrollTop,idx=Math.min(Math.round(st/620),4);
+ secPos.textContent=SECTIONS[idx].num+' / 05';
+ secTitleEl.textContent=SECTIONS[idx].title.length>22?SECTIONS[idx].title.slice(0,22)+'…':SECTIONS[idx].title;
+ statusEl.textContent=getStatus(st);
+ dots.forEach((d,i)=>d.classList.toggle('active',i===idx));
+ },{passive:true});
+</script>
+</body>
+</html>
diff --git a/animations/01-scroll-based/stacking-cards/index.html b/animations/01-scroll-based/stacking-cards/index.html
new file mode 100644
index 00000000..23327752
--- /dev/null
+++ b/animations/01-scroll-based/stacking-cards/index.html
@@ -0,0 +1,114 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <meta charset="UTF-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
+ <title>Stacking Cards</title>
+ <style>
+ :root{--bg:#060a10;--ui-bg:#0d1117;--ui-border:#21262d;--ui-accent:#58a6ff;--ui-text:#c9d1d9;--ui-muted:#8b949e}
+ *,*::before,*::after{box-sizing:border-box;margin:0;padding:0}
+ body{background:var(--bg);color:var(--ui-text);font-family:monospace;padding:clamp(12px,3vw,24px)}
+ header{margin-bottom:20px}
+ header h1{font-size:clamp(11px,1.8vw,15px);letter-spacing:2px;text-transform:uppercase}
+ 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::-webkit-scrollbar{display:none}
+ .stack{height:3000px}
+ .card{position:sticky;top:0;height:600px;overflow:hidden;border-radius:8px;padding:32px;display:flex;flex-direction:column;justify-content:flex-end;will-change:transform,filter}
+ .card-num{font-size:72px;font-weight:bold;opacity:.18;line-height:1;margin-bottom:8px}
+ .card-title{font-size:clamp(20px,3vw,28px);font-weight:bold;margin-bottom:6px}
+ .card-sub{font-size:13px;opacity:.65;margin-bottom:14px}
+ .card-body{font-size:12px;opacity:.55;max-width:380px;line-height:1.65}
+ .depth-badge{position:absolute;top:14px;right:14px;font-size:9px;background:rgba(0,0,0,.5);padding:3px 9px;border-radius:10px;display:none}
+ .depth-badge.on{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)}
+ .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{height:480px}}
+ @media(prefers-reduced-motion:reduce){.card{will-change:auto}}
+ </style>
+</head>
+<body>
+<header>
+ <h1>Stacking Cards</h1>
+ <p>Cards stack as they overlap — position: sticky does the work, scroll drives the depth cues.</p>
+</header>
+<div class="layout">
+ <div class="stage" id="stage"><div class="stack" id="stack"></div></div>
+ <aside>
+ <p class="note">This entire effect is built on position: sticky. The CSS does most of the work — JavaScript only adds the depth cues. Try setting all sliders to their max (1.00 / 1.0) to see the pure CSS-only version, then bring them down to feel how depth cues add physicality.</p>
+ <div><div class="lbl">Stack status</div>
+ <div class="tbl">
+ <div class="kv"><span>Scroll</span><span class="v" id="scroll-prog">0%</span></div>
+ <div class="kv"><span>Topmost card</span><span class="v" id="topmost">01</span></div>
+ </div>
+ </div>
+ <div class="div"></div>
+ <div><div class="lbl" id="scale-lbl">Scale floor</div>
+ <div class="sr"><input type="range" id="scale-sl" aria-labelledby="scale-lbl" min="85" max="100" value="94"><span class="sv" id="scale-val">0.94</span></div>
+ </div>
+ <div><div class="lbl" id="bright-lbl">Brightness floor</div>
+ <div class="sr"><input type="range" id="bright-sl" aria-labelledby="bright-lbl" min="60" max="100" value="85"><span class="sv" id="bright-val">0.85</span></div>
+ </div>
+ <div class="div"></div>
+ <label class="tog" for="depth-tog"><input type="checkbox" id="depth-tog"><span>Show stack depth</span></label>
+ <button id="reset-btn">Reset scroll</button>
+ </aside>
+</div>
+<script>
+ const CARDS=[
+ {num:'01',title:'The Foundation', sub:'Where everything begins', body:'Every scroll-driven animation starts with a structural decision. Position: sticky provides the base stacking without any JavaScript.', bg:'linear-gradient(135deg,#0d2b3e,#1a3a5c)'},
+ {num:'02',title:'Layer by Layer', sub:'Building depth through CSS', body:'Each card occupies one viewport height. As the next card scrolls up, the previous stays beneath — the stacking itself needs no JavaScript.', bg:'linear-gradient(135deg,#2d1b3d,#3d2a5c)'},
+ {num:'03',title:'Depth Perception', sub:'Visual cues add physicality', body:'Scale and brightness reduction on buried cards simulate depth. The eye reads smaller and darker as farther away.', bg:'linear-gradient(135deg,#1e3a1e,#2d5c2d)'},
+ {num:'04',title:'The Scroll Loop', sub:'rAF keeps it smooth', body:"A requestAnimationFrame callback computes each card's depth on scroll. Only transform and filter change — the compositor handles everything.", bg:'linear-gradient(135deg,#3d2000,#5c3400)'},
+ {num:'05',title:'The Full Stack', sub:'CSS and JS in balance', body:'You are looking at all five cards now. This one is topmost — full scale, full brightness. The four below are quietly buried, waiting.', bg:'linear-gradient(135deg,#1a3a3a,#2a5c5c)'},
+ ];
+ const stack=document.getElementById('stack');
+ const cards=CARDS.map((c,i)=>{
+ const el=document.createElement('div');
+ el.className='card';el.style.cssText=`background:${c.bg};z-index:${i+1}`;
+ el.innerHTML=`<div class="depth-badge" id="db${i}">depth 0</div><div class="card-num">${c.num}</div><div class="card-title">${c.title}</div><div class="card-sub">${c.sub}</div><div class="card-body">${c.body}</div>`;
+ stack.appendChild(el);return el;
+ });
+ const stage=document.getElementById('stage'),scrollProg=document.getElementById('scroll-prog'),topmostEl=document.getElementById('topmost');
+ const scaleSl=document.getElementById('scale-sl'),scaleVal=document.getElementById('scale-val');
+ const brightSl=document.getElementById('bright-sl'),brightVal=document.getElementById('bright-val');
+ const depthTog=document.getElementById('depth-tog'),resetBtn=document.getElementById('reset-btn');
+ const motionMQ=window.matchMedia('(prefers-reduced-motion: reduce)');
+ let ticking=false;
+ const lerp=(a,b,t)=>a+(b-a)*t;
+ function update(){
+ const st=stage.scrollTop,max=stage.scrollHeight-stage.clientHeight;
+ scrollProg.textContent=max>0?Math.round(st/max*100)+'%':'0%';
+ const top=Math.min(Math.floor(st/600),4),SF=scaleSl.value/100,BF=brightSl.value/100;
+ cards.forEach((el,i)=>{
+ const depth=Math.max(0,top-i),t=depth/4;
+ const sc=motionMQ.matches?1:lerp(1,SF,t),br=motionMQ.matches?1:lerp(1,BF,t),ty=motionMQ.matches?0:depth*5;
+ el.style.transform=`translateY(${ty}px) scale(${sc.toFixed(3)})`;
+ el.style.filter=`brightness(${br.toFixed(3)})`;
+ const db=document.getElementById('db'+i);
+ db.textContent=`depth ${depth}`;db.classList.toggle('on',depthTog.checked);
+ });
+ topmostEl.textContent=CARDS[top].num;ticking=false;
+ }
+ stage.addEventListener('scroll',()=>{if(!ticking){requestAnimationFrame(update);ticking=true}},{passive:true});
+ scaleSl.addEventListener('input',()=>{scaleVal.textContent=(scaleSl.value/100).toFixed(2);update()});
+ brightSl.addEventListener('input',()=>{brightVal.textContent=(brightSl.value/100).toFixed(2);update()});
+ depthTog.addEventListener('change',update);
+ resetBtn.addEventListener('click',()=>{stage.scrollTop=0;update()});
+ update();
+</script>
+</body>
+</html>