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 9 scroll-based animation demos (batch 2 — index.html only)

matinb623302a0d24
diff --git a/animations/01-scroll-based/counter-animation/index.html b/animations/01-scroll-based/counter-animation/index.html
new file mode 100644
index 00000000..fcd653b3
--- /dev/null
+++ b/animations/01-scroll-based/counter-animation/index.html
@@ -0,0 +1,157 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <meta charset="UTF-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
+ <title>Counter Animation</title>
+ <style>
+ :root{--bg:#060a10;--ui-bg:#0d1117;--ui-border:#21262d;--ui-accent:#58a6ff;--ui-text:#c9d1d9;--ui-muted:#8b949e;--stage-h:600px}
+ *,*::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:var(--stage-h);overflow-y:scroll;scrollbar-width:none;border:1px solid var(--ui-border);border-radius:8px}
+ .stage::-webkit-scrollbar{display:none}
+ .spacer{height:220px;display:flex;align-items:center;justify-content:center;font-size:11px;opacity:.25;letter-spacing:2px}
+ #stats{display:grid;grid-template-columns:1fr 1fr;gap:clamp(10px,2vw,16px);padding:clamp(16px,3vw,32px)}
+ .tile{background:#0d1117;border:1px solid #21262d;border-radius:12px;padding:clamp(18px,3vw,28px);display:flex;flex-direction:column;gap:8px}
+ .tile-icon{font-size:22px;opacity:.6}
+ .tile-num{font-size:clamp(28px,4.5vw,44px);font-weight:bold;font-variant-numeric:tabular-nums;line-height:1;color:var(--ui-accent)}
+ .tile-label{font-size:10px;opacity:.5;text-transform:uppercase;letter-spacing:1.5px}
+ 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);font-variant-numeric:tabular-nums}
+ .div{height:1px;background:var(--ui-border)}
+ .sr{display:flex;align-items:center;gap:6px;font-size:10px}
+ .sr input[type=range]{flex:1;accent-color:var(--ui-accent);min-height:44px}
+ .sv{width:38px;text-align:right;color:var(--ui-text)}
+ .seg{display:flex;gap:3px;flex-wrap:wrap}
+ .seg button{flex:1;background:none;border:1px solid var(--ui-border);color:var(--ui-muted);font-family:monospace;font-size:9px;padding:8px 4px;border-radius:4px;cursor:pointer;min-height:36px}
+ .seg button.on{border-color:var(--ui-accent);color:var(--ui-accent);background:#0d2040}
+ .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.rst{background:transparent;border:1px solid var(--ui-border);color:var(--ui-text);font-family:monospace;font-size:10px;padding:14px 8px;border-radius:4px;cursor:pointer;width:100%}
+ @media(hover:hover){button.rst:hover{border-color:var(--ui-accent);color:var(--ui-accent)}}
+ @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}:root{--stage-h:460px}#stats{grid-template-columns:1fr 1fr}}
+ @media(prefers-reduced-motion:reduce){.tile-num{transition:none}}
+ </style>
+</head>
+<body>
+<header>
+ <h1>Counter Animation</h1>
+ <p>Numbers count from 0 to target on scroll entry, with easing and per-format rendering every frame.</p>
+</header>
+<div class="layout">
+ <div class="stage" id="stage">
+ <div class="spacer">scroll down to trigger ↓</div>
+ <div id="stats">
+ <div class="tile"><div class="tile-icon">◉</div><div class="tile-num" id="cn0">0</div><div class="tile-label">active users</div></div>
+ <div class="tile"><div class="tile-icon">◈</div><div class="tile-num" id="cn1">0.0%</div><div class="tile-label">uptime</div></div>
+ <div class="tile"><div class="tile-icon">◆</div><div class="tile-num" id="cn2">$0</div><div class="tile-label">revenue</div></div>
+ <div class="tile"><div class="tile-icon">◇</div><div class="tile-num" id="cn3">0 yrs</div><div class="tile-label">experience</div></div>
+ </div>
+ <div class="spacer"></div>
+ </div>
+ <aside>
+ <p class="note">Counters need easing — linear count-ups feel mechanical. easeOutExpo makes numbers settle into place. Format the value every frame, not just at the end.</p>
+ <div><div class="lbl" id="thr-lbl">Trigger threshold</div>
+ <div class="sr"><input type="range" id="thr-sl" aria-labelledby="thr-lbl" min="10" max="90" value="60" step="5"><span class="sv" id="thr-val">60%</span></div>
+ </div>
+ <div><div class="lbl" id="dur-lbl">Duration</div>
+ <div class="sr"><input type="range" id="dur-sl" aria-labelledby="dur-lbl" min="500" max="3000" value="1800" step="100"><span class="sv" id="dur-val">1.8s</span></div>
+ </div>
+ <div class="div"></div>
+ <div class="lbl">Easing</div>
+ <div class="seg" id="ease-seg">
+ <button data-e="linear">Linear</button>
+ <button data-e="outCubic" class="on">Cubic</button>
+ <button data-e="outExpo">Expo</button>
+ <button data-e="outBack">Back</button>
+ </div>
+ <div class="div"></div>
+ <label class="tog" for="stagger-tog"><input type="checkbox" id="stagger-tog" checked><span>Stagger counters</span></label>
+ <div class="div"></div>
+ <div class="lbl">Live values</div>
+ <div class="kv"><span>Users</span><span class="v" id="lv0">0</span></div>
+ <div class="kv"><span>Uptime</span><span class="v" id="lv1">0.0%</span></div>
+ <div class="kv"><span>Revenue</span><span class="v" id="lv2">$0</span></div>
+ <div class="kv"><span>Experience</span><span class="v" id="lv3">0 yrs</span></div>
+ <div class="div"></div>
+ <button class="rst" id="replay">Replay counters</button>
+ </aside>
+</div>
+<script>
+ const stage=document.getElementById('stage');
+ const thrSl=document.getElementById('thr-sl'),thrVal=document.getElementById('thr-val');
+ const durSl=document.getElementById('dur-sl'),durVal=document.getElementById('dur-val');
+ const staggerTog=document.getElementById('stagger-tog');
+ const TARGETS=[12847,98.4,2400000,8];
+ const FORMATS=[
+ v=>Math.round(v).toLocaleString(),
+ v=>v.toFixed(1)+'%',
+ v=>{if(v>=1e6)return'$'+(v/1e6).toFixed(1)+'M';return'$'+Math.round(v).toLocaleString()},
+ v=>Math.floor(v)+' yrs'
+ ];
+ const EASE={
+ linear:t=>t,
+ outCubic:t=>1-(1-t)**3,
+ outExpo:t=>t===1?1:1-Math.pow(2,-10*t),
+ outBack:t=>{const c=1.70158,c3=c+1;return 1+c3*Math.pow(t-1,3)+c*Math.pow(t-1,2)}
+ };
+ let duration=1800,easing='outCubic',observer,running=false;
+
+ const cnEls=TARGETS.map((_,i)=>document.getElementById('cn'+i));
+ const lvEls=TARGETS.map((_,i)=>document.getElementById('lv'+i));
+
+ function animateCounters(motionOk){
+ if(running)return;running=true;
+ const start=performance.now();
+ const delays=staggerTog.checked?TARGETS.map((_,i)=>i*200):[0,0,0,0];
+ const ef=EASE[easing]||EASE.outCubic;
+ function frame(now){
+ let anyActive=false;
+ TARGETS.forEach((target,i)=>{
+ const elapsed=now-start-delays[i];
+ if(elapsed<0){anyActive=true;return;}
+ const t=motionOk?Math.min(elapsed/duration,1):1;
+ const v=target*ef(t);
+ const str=FORMATS[i](v);
+ cnEls[i].textContent=str;lvEls[i].textContent=str;
+ if(t<1)anyActive=true;
+ });
+ if(anyActive)requestAnimationFrame(frame);else running=false;
+ }
+ requestAnimationFrame(frame);
+ }
+
+ function buildObserver(){
+ if(observer)observer.disconnect();
+ const margin=-(100-+thrSl.value);
+ const motionOk=!window.matchMedia('(prefers-reduced-motion:reduce)').matches;
+ observer=new IntersectionObserver(([e])=>{
+ if(e.isIntersecting&&!running)animateCounters(motionOk);
+ },{root:stage,rootMargin:`0px 0px ${margin}% 0px`,threshold:0});
+ observer.observe(document.getElementById('stats'));
+ }
+
+ thrSl.addEventListener('input',()=>{thrVal.textContent=thrSl.value+'%';buildObserver()});
+ durSl.addEventListener('input',()=>{duration=+durSl.value;durVal.textContent=(duration/1000).toFixed(1)+'s'});
+ document.querySelectorAll('#ease-seg button').forEach(b=>{
+ b.addEventListener('click',()=>{
+ document.querySelectorAll('#ease-seg button').forEach(x=>x.classList.remove('on'));
+ b.classList.add('on');easing=b.dataset.e;
+ });
+ });
+ document.getElementById('replay').addEventListener('click',()=>{
+ running=false;cnEls.forEach((el,i)=>{el.textContent=FORMATS[i](0);lvEls[i].textContent=FORMATS[i](0)});
+ const motionOk=!window.matchMedia('(prefers-reduced-motion:reduce)').matches;
+ setTimeout(()=>animateCounters(motionOk),50);
+ });
+ buildObserver();
+</script>
+</body>
+</html>
diff --git a/animations/01-scroll-based/horizontal-scroll/index.html b/animations/01-scroll-based/horizontal-scroll/index.html
new file mode 100644
index 00000000..7499abcd
--- /dev/null
+++ b/animations/01-scroll-based/horizontal-scroll/index.html
@@ -0,0 +1,134 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <meta charset="UTF-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
+ <title>Horizontal Scroll</title>
+ <style>
+ :root{--bg:#060a10;--ui-bg:#0d1117;--ui-border:#21262d;--ui-accent:#58a6ff;--ui-text:#c9d1d9;--ui-muted:#8b949e;--stage-h:620px;--panels:5}
+ *,*::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:var(--stage-h);overflow-y:scroll;scrollbar-width:none;border:1px solid var(--ui-border);border-radius:8px}
+ .stage::-webkit-scrollbar{display:none}
+ /* Intro / outro spacers */
+ .spacer{height:calc(var(--stage-h) * 0.6);display:flex;align-items:center;justify-content:center;font-size:11px;opacity:.3;letter-spacing:2px}
+ /* The pin section — tall to provide scroll budget */
+ #pin-section{height:calc(var(--stage-h) * var(--panels));position:relative}
+ /* Sticky inner */
+ #pin-inner{position:sticky;top:0;height:var(--stage-h);overflow:hidden}
+ /* Horizontal track */
+ #h-track{display:flex;height:100%;will-change:transform;width:calc(var(--panels) * 100%)}
+ .panel{flex:0 0 calc(100% / var(--panels));height:100%;display:flex;flex-direction:column;justify-content:center;padding:clamp(24px,5vw,60px)}
+ .panel-num{font-size:clamp(60px,10vw,100px);font-weight:bold;opacity:.1;line-height:1;margin-bottom:12px}
+ .panel-title{font-size:clamp(22px,3.5vw,36px);font-weight:bold;margin-bottom:14px}
+ .panel-body{font-size:clamp(12px,1.4vw,14px);opacity:.6;line-height:1.7;max-width:480px}
+ .panel-tag{font-size:10px;text-transform:uppercase;letter-spacing:2px;margin-bottom:12px;opacity:.5}
+ /* Panel progress dots */
+ #panel-dots{position:absolute;bottom:16px;left:50%;transform:translateX(-50%);display:flex;gap:8px;pointer-events:none}
+ .dot{width:6px;height:6px;border-radius:50%;background:#21262d;transition:background .3s,transform .3s}
+ .dot.on{background:var(--ui-accent);transform:scale(1.3)}
+ aside{width:clamp(200px,22vw,240px);flex-shrink:0;background:var(--ui-bg);border:1px solid var(--ui-border);border-radius:8px;padding:16px;display:flex;flex-direction:column;gap:10px}
+ .note{font-size:10px;color:var(--ui-muted);line-height:1.6;border-left:2px solid var(--ui-accent);padding-left:8px}
+ .lbl{font-size:10px;text-transform:uppercase;letter-spacing:1px;color:var(--ui-accent)}
+ .kv{display:flex;justify-content:space-between;font-size:10px;color:var(--ui-muted)}
+ .kv .v{color:var(--ui-text)}
+ .div{height:1px;background:var(--ui-border)}
+ .jlist{display:flex;flex-direction:column;gap:3px}
+ .jbtn{background:none;border:1px solid var(--ui-border);color:var(--ui-muted);font-family:monospace;font-size:9px;padding:7px 8px;border-radius:4px;cursor:pointer;text-align:left;width:100%;min-height:36px}
+ .jbtn.on{border-color:var(--ui-accent);color:var(--ui-accent)}
+ @media(hover:hover){.jbtn:hover{border-color:var(--ui-accent)}}
+ button.rst{background:transparent;border:1px solid var(--ui-border);color:var(--ui-text);font-family:monospace;font-size:10px;padding:14px 8px;border-radius:4px;cursor:pointer;width:100%}
+ @media(hover:hover){button.rst:hover{border-color:var(--ui-accent);color:var(--ui-accent)}}
+ @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}:root{--stage-h:480px}.panel{padding:24px}}
+ @media(prefers-reduced-motion:reduce){#h-track{transition:none!important}}
+ </style>
+</head>
+<body>
+<header>
+ <h1>Horizontal Scroll</h1>
+ <p>Vertical scroll translates a horizontal track — a pin section provides the scroll budget.</p>
+</header>
+<div class="layout">
+ <div class="stage" id="stage">
+ <div class="spacer">↓ scroll to enter</div>
+ <div id="pin-section">
+ <div id="pin-inner">
+ <div id="h-track"></div>
+ <div id="panel-dots"></div>
+ </div>
+ </div>
+ <div class="spacer">↓ released</div>
+ </div>
+ <aside>
+ <p class="note">A tall section provides the scroll budget. translateX = −progress × (trackWidth − stageWidth). Two formulas — pin distance and horizontal offset — do all the work.</p>
+ <div class="lbl">Progress</div>
+ <div class="kv"><span>Overall scroll</span><span class="v" id="sc-pct">0%</span></div>
+ <div class="kv"><span>Track progress</span><span class="v" id="tr-pct">0%</span></div>
+ <div class="kv"><span>Panel</span><span class="v" id="panel-id">—</span></div>
+ <div class="div"></div>
+ <div class="lbl">Jump to panel</div>
+ <div class="jlist" id="jlist"></div>
+ <div class="div"></div>
+ <button class="rst" id="rst">Reset scroll</button>
+ </aside>
+</div>
+<script>
+ const PANELS=[
+ {title:'Pin & Translate', body:'The outer container is taller than the viewport. The inner container sticks. Translating the horizontal track converts vertical scroll into horizontal motion.',bg:'linear-gradient(135deg,#0d2b3e,#1a3a5c)',ac:'#79c0ff'},
+ {title:'One Scroll Input', body:'A single scrollTop value drives everything. No separate horizontal scroll container, no wheel hijacking. The user\'s native scroll behaviour is preserved.', bg:'linear-gradient(135deg,#2d1b3d,#3d2a5c)',ac:'#d2a8ff'},
+ {title:'Panel Jump Links', body:'Clicking a panel in the sidebar computes the scroll position that centers it: panelIndex × scrollBudget / (panels − 1). Smooth scroll does the rest.', bg:'linear-gradient(135deg,#1e3a1e,#2d5c2d)',ac:'#56d364'},
+ {title:'Exit Detection', body:'Panel index = Math.round(trackProgress × (panels − 1)). As the track progress crosses 0.5, 1.5, 2.5... panel transitions fire without any event listener.', bg:'linear-gradient(135deg,#3d2000,#5c3400)',ac:'#ffa657'},
+ {title:'Momentum & Snapping',body:'GSAP ScrollTrigger adds optional snapping to the nearest panel. Lenis and Locomotive Scroll provide momentum-based easing for a physical feel.', bg:'linear-gradient(135deg,#1a3a3a,#2a5c5c)',ac:'#58a6ff'},
+ ];
+ const stage=document.getElementById('stage'),track=document.getElementById('h-track');
+ const scPct=document.getElementById('sc-pct'),trPct=document.getElementById('tr-pct'),panelId=document.getElementById('panel-id');
+ const dotsEl=document.getElementById('panel-dots'),jlist=document.getElementById('jlist');
+ let ticking=false;
+
+ PANELS.forEach((p,i)=>{
+ const el=document.createElement('div');el.className='panel';
+ el.style.background=p.bg;
+ el.innerHTML=`<div class="panel-num">0${i+1}</div>
+ <div class="panel-tag" style="color:${p.ac}">Panel ${String(i+1).padStart(2,'0')}</div>
+ <div class="panel-title" style="color:${p.ac}">${p.title}</div>
+ <div class="panel-body">${p.body}</div>`;
+ track.appendChild(el);
+ const dot=document.createElement('div');dot.className='dot';dotsEl.appendChild(dot);
+ const btn=document.createElement('button');btn.className='jbtn';
+ btn.textContent=`0${i+1} ${p.title}`;
+ btn.addEventListener('click',()=>{
+ const pin=document.getElementById('pin-section');
+ const budget=pin.offsetHeight-stage.clientHeight;
+ stage.scrollTo({top:pin.offsetTop+Math.round(i/(PANELS.length-1)*budget),behavior:'smooth'});
+ });
+ jlist.appendChild(btn);
+ });
+
+ const clamp=(v,a,b)=>Math.min(Math.max(v,a),b);
+
+ function update(){
+ const st=stage.scrollTop,max=stage.scrollHeight-stage.clientHeight;
+ scPct.textContent=max>0?Math.round(st/max*100)+'%':'0%';
+ const pin=document.getElementById('pin-section');
+ const budget=pin.offsetHeight-stage.clientHeight;
+ const progress=clamp((st-pin.offsetTop)/budget,0,1);
+ const maxShift=track.offsetWidth-stage.clientWidth;
+ track.style.transform=`translateX(${(-progress*maxShift).toFixed(2)}px)`;
+ trPct.textContent=Math.round(progress*100)+'%';
+ const panel=Math.min(Math.round(progress*(PANELS.length-1)),PANELS.length-1);
+ panelId.textContent=`0${panel+1} — ${PANELS[panel].title}`;
+ document.querySelectorAll('.dot').forEach((d,i)=>d.classList.toggle('on',i===panel));
+ document.querySelectorAll('.jbtn').forEach((b,i)=>b.classList.toggle('on',i===panel));
+ ticking=false;
+ }
+
+ stage.addEventListener('scroll',()=>{if(!ticking){requestAnimationFrame(update);ticking=true}},{passive:true});
+ document.getElementById('rst').addEventListener('click',()=>{stage.scrollTop=0;update()});
+ update();
+</script>
+</body>
+</html>
diff --git a/animations/01-scroll-based/progress-bar/index.html b/animations/01-scroll-based/progress-bar/index.html
new file mode 100644
index 00000000..c3424c04
--- /dev/null
+++ b/animations/01-scroll-based/progress-bar/index.html
@@ -0,0 +1,178 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <meta charset="UTF-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
+ <title>Progress Bar</title>
+ <style>
+ :root{--bg:#060a10;--ui-bg:#0d1117;--ui-border:#21262d;--ui-accent:#58a6ff;--ui-text:#c9d1d9;--ui-muted:#8b949e;--stage-h:600px;--bar-color:#58a6ff;--bar-thick:3px}
+ *,*::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;overflow:hidden;border-radius:8px}
+ .stage{width:100%;height:var(--stage-h);overflow-y:scroll;scrollbar-width:none;border:1px solid var(--ui-border);border-radius:8px}
+ .stage::-webkit-scrollbar{display:none}
+ /* Top bar */
+ #top-bar{position:absolute;top:0;left:0;right:0;height:var(--bar-thick);background:var(--bar-color);transform-origin:left;transform:scaleX(0);z-index:10;display:none;border-radius:0}
+ /* Side rail */
+ #side-rail{position:absolute;top:0;right:0;bottom:0;width:var(--bar-thick);z-index:10;display:none;overflow:hidden}
+ #side-fill{position:absolute;top:0;left:0;right:0;background:var(--bar-color);height:0%}
+ /* Circular */
+ #circ{position:absolute;top:8px;right:8px;z-index:10;display:none}
+ .circ-bg{fill:none;stroke:#21262d;stroke-width:3}
+ .circ-fg{fill:none;stroke:var(--bar-color);stroke-width:3;stroke-linecap:round;stroke-dasharray:100.53;stroke-dashoffset:100.53;transform:rotate(-90deg);transform-origin:50% 50%}
+ .circ-text{font-size:5px;fill:var(--ui-text);text-anchor:middle;dominant-baseline:central;font-family:monospace}
+ /* Article */
+ .article{padding:clamp(20px,4vw,40px);max-width:600px}
+ .art-title{font-size:clamp(20px,3vw,28px);font-weight:bold;line-height:1.2;margin-bottom:8px}
+ .art-byline{font-size:10px;opacity:.4;margin-bottom:28px;text-transform:uppercase;letter-spacing:1px}
+ .art-body{font-size:13px;line-height:1.85;opacity:.7;margin-bottom:18px}
+ .art-pull{border-left:3px solid var(--bar-color);padding-left:16px;font-size:15px;line-height:1.6;margin:24px 0;opacity:.8}
+ .art-h2{font-size:clamp(16px,2vw,20px);font-weight:bold;margin:28px 0 12px;opacity:.9}
+ aside{width:clamp(200px,22vw,240px);flex-shrink:0;background:var(--ui-bg);border:1px solid var(--ui-border);border-radius:8px;padding:16px;display:flex;flex-direction:column;gap:10px}
+ .note{font-size:10px;color:var(--ui-muted);line-height:1.6;border-left:2px solid var(--ui-accent);padding-left:8px}
+ .lbl{font-size:10px;text-transform:uppercase;letter-spacing:1px;color:var(--ui-accent)}
+ .kv{display:flex;justify-content:space-between;font-size:10px;color:var(--ui-muted)}
+ .kv .v{color:var(--ui-text)}
+ .div{height:1px;background:var(--ui-border)}
+ .sr{display:flex;align-items:center;gap:6px;font-size:10px}
+ .sr input[type=range]{flex:1;accent-color:var(--ui-accent);min-height:44px}
+ .sv{width:34px;text-align:right;color:var(--ui-text)}
+ .seg{display:flex;gap:3px}
+ .seg button{flex:1;background:none;border:1px solid var(--ui-border);color:var(--ui-muted);font-family:monospace;font-size:9px;padding:8px 4px;border-radius:4px;cursor:pointer;min-height:36px}
+ .seg button.on{border-color:var(--ui-accent);color:var(--ui-accent);background:#0d2040}
+ .swatches{display:flex;gap:6px}
+ .swatch{width:28px;height:28px;border-radius:4px;cursor:pointer;border:2px solid transparent}
+ .swatch.on{border-color:#fff}
+ button.rst{background:transparent;border:1px solid var(--ui-border);color:var(--ui-text);font-family:monospace;font-size:10px;padding:14px 8px;border-radius:4px;cursor:pointer;width:100%}
+ @media(hover:hover){button.rst:hover{border-color:var(--ui-accent);color:var(--ui-accent)}}
+ @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}:root{--stage-h:460px}}
+ </style>
+</head>
+<body>
+<header>
+ <h1>Progress Bar</h1>
+ <p>Reading progress across three indicator styles — top bar, circular ring, and side rail.</p>
+</header>
+<div class="layout">
+ <div class="stage-wrap">
+ <div id="top-bar"></div>
+ <div id="side-rail"><div id="side-fill"></div></div>
+ <svg id="circ" width="40" height="40" viewBox="0 0 36 36">
+ <circle class="circ-bg" cx="18" cy="18" r="16"/>
+ <circle class="circ-fg" id="circ-fg" cx="18" cy="18" r="16"/>
+ <text class="circ-text" id="circ-txt" x="18" y="18">0%</text>
+ </svg>
+ <div class="stage" id="stage">
+ <div class="article" id="article"></div>
+ </div>
+ </div>
+ <aside>
+ <p class="note">The formula is constant: scrollTop / (scrollHeight − clientHeight). The design choice is WHERE you place the indicator — top bars are loudest, side rails most editorial.</p>
+ <div class="lbl">Progress</div>
+ <div class="kv"><span>Read</span><span class="v" id="prog-pct">0%</span></div>
+ <div class="kv"><span>Reading time</span><span class="v" id="read-time">—</span></div>
+ <div class="div"></div>
+ <div class="lbl">Indicator style</div>
+ <div class="seg" id="style-seg">
+ <button data-s="top" class="on">Top bar</button>
+ <button data-s="circ">Circle</button>
+ <button data-s="rail">Side rail</button>
+ </div>
+ <div class="div"></div>
+ <div class="lbl">Bar color</div>
+ <div class="swatches" id="swatches">
+ <div class="swatch on" data-c="#58a6ff" style="background:#58a6ff"></div>
+ <div class="swatch" data-c="#56d364" style="background:#56d364"></div>
+ <div class="swatch" data-c="#ffa657" style="background:#ffa657"></div>
+ <div class="swatch" data-c="#d2a8ff" style="background:#d2a8ff"></div>
+ </div>
+ <div><div class="lbl" id="thick-lbl">Bar thickness</div>
+ <div class="sr"><input type="range" id="thick-sl" aria-labelledby="thick-lbl" min="2" max="8" value="3"><span class="sv" id="thick-val">3px</span></div>
+ </div>
+ <div class="div"></div>
+ <button class="rst" id="rst">Reset scroll</button>
+ </aside>
+</div>
+<script>
+ const stage=document.getElementById('stage'),topBar=document.getElementById('top-bar');
+ const sideFill=document.getElementById('side-fill'),circFg=document.getElementById('circ-fg');
+ const circTxt=document.getElementById('circ-txt'),progPct=document.getElementById('prog-pct');
+ let style='top',ticking=false;
+
+ const PARAS=[
+ "The browser's scroll events fire dozens of times per second. Naively attaching a progress bar update directly to the scroll handler means dozens of style recalculations per second — a guaranteed frame-rate killer. The fix is a single requestAnimationFrame dirty flag, and it's two lines of code.",
+ "Most progress bar implementations compute progress as scrollTop divided by the difference between scrollHeight and clientHeight. This ratio lands precisely on 1.0 when the last pixel of content is visible — not when you've scrolled past a fake scroll container, but when the actual reading distance is exhausted.",
+ "The top-of-page bar is the loudest choice. It occupies the most visually prominent real estate and signals 'this is long content' to any reader. Editorial sites often prefer the side rail — it communicates the same information without interrupting the reading axis. Either choice is defensible; the question is how much attention you want to draw to the indicator itself.",
+ "The circular indicator places progress in a compact corner element. SVG stroke-dashoffset drives the fill: the dasharray equals the circle circumference (2πr), and subtracting progress × circumference from that value animates the ring. It is the same arithmetic as a pie chart, expressed as an outline rather than a filled sector.",
+ "Bar thickness is a design signal. A 2px rule is almost subliminal — it says 'I am here if you want me.' A 6–8px bar is assertive. Neither is wrong; the choice depends on how prominently the site wants to communicate document length. Reading progress indicators on news sites tend toward thin; documentation sites often use bolder fills because the reader actively wants to track position.",
+ "Performance is the invisible constraint. A progress bar that causes layout recalculation on every scroll event will degrade the reading experience on mobile. The requestAnimationFrame dirty-flag pattern — set a boolean on scroll, clear it in the rAF callback — reduces DOM writes to one per frame regardless of how fast the user scrolls.",
+ ];
+ const article=document.getElementById('article');
+ article.innerHTML=`<div class="art-title">The Anatomy of a Reading Progress Bar</div>
+ <div class="art-byline">Animation Atlas · Reference</div>
+ <div class="art-body">${PARAS[0]}</div>
+ <div class="art-pull">"Two lines of JavaScript, a transform, and a single CSS custom property — that is the entire implementation."</div>
+ <div class="art-body">${PARAS[1]}</div>
+ <div class="art-h2">Placement and Visual Weight</div>
+ <div class="art-body">${PARAS[2]}</div>
+ <div class="art-body">${PARAS[3]}</div>
+ <div class="art-h2">Thickness as a Design Choice</div>
+ <div class="art-body">${PARAS[4]}</div>
+ <div class="art-h2">Performance</div>
+ <div class="art-body">${PARAS[5]}</div>`;
+
+ const CIRC=100.53;
+ document.getElementById('read-time').textContent=
+ Math.ceil(article.innerText.split(/\s+/).length/250)+' min read';
+
+ function setStyle(s){
+ style=s;
+ topBar.style.display=s==='top'?'block':'none';
+ document.getElementById('circ').style.display=s==='circ'?'block':'none';
+ document.getElementById('side-rail').style.display=s==='rail'?'block':'none';
+ }
+
+ function update(){
+ const st=stage.scrollTop,max=stage.scrollHeight-stage.clientHeight;
+ const p=max>0?st/max:0;
+ const pct=Math.round(p*100);
+ progPct.textContent=pct+'%';
+ topBar.style.transform=`scaleX(${p})`;
+ sideFill.style.height=pct+'%';
+ circFg.style.strokeDashoffset=CIRC-(p*CIRC);
+ circTxt.textContent=pct+'%';
+ ticking=false;
+ }
+
+ stage.addEventListener('scroll',()=>{if(!ticking){requestAnimationFrame(update);ticking=true}},{passive:true});
+
+ document.querySelectorAll('#style-seg button').forEach(b=>{
+ b.addEventListener('click',()=>{
+ document.querySelectorAll('#style-seg button').forEach(x=>x.classList.remove('on'));
+ b.classList.add('on');setStyle(b.dataset.s);
+ });
+ });
+ document.querySelectorAll('.swatch').forEach(s=>{
+ s.addEventListener('click',()=>{
+ document.querySelectorAll('.swatch').forEach(x=>x.classList.remove('on'));
+ s.classList.add('on');
+ const c=s.dataset.c;
+ document.documentElement.style.setProperty('--bar-color',c);
+ });
+ });
+ const thickSl=document.getElementById('thick-sl'),thickVal=document.getElementById('thick-val');
+ thickSl.addEventListener('input',()=>{
+ const v=thickSl.value+'px';thickVal.textContent=v;
+ document.documentElement.style.setProperty('--bar-thick',v);
+ circFg.setAttribute('stroke-width',thickSl.value);
+ document.querySelector('.circ-bg').setAttribute('stroke-width',thickSl.value);
+ });
+ document.getElementById('rst').addEventListener('click',()=>{stage.scrollTop=0;update()});
+ setStyle('top');update();
+</script>
+</body>
+</html>
diff --git a/animations/01-scroll-based/reveal-on-scroll/index.html b/animations/01-scroll-based/reveal-on-scroll/index.html
new file mode 100644
index 00000000..058988aa
--- /dev/null
+++ b/animations/01-scroll-based/reveal-on-scroll/index.html
@@ -0,0 +1,193 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <meta charset="UTF-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
+ <title>Reveal on Scroll</title>
+ <style>
+ :root{--bg:#060a10;--ui-bg:#0d1117;--ui-border:#21262d;--ui-accent:#58a6ff;--ui-text:#c9d1d9;--ui-muted:#8b949e;--stage-h:600px}
+ *,*::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{width:100%;height:var(--stage-h);overflow-y:scroll;scrollbar-width:none;border:1px solid var(--ui-border);border-radius:8px;position:relative}
+ .stage::-webkit-scrollbar{display:none}
+ #trigger-line{position:absolute;left:0;right:0;height:1px;background:none;border-top:2px dashed var(--ui-accent);pointer-events:none;z-index:10;opacity:.7}
+ #trigger-label{position:absolute;right:8px;top:-18px;font-size:9px;color:var(--ui-accent);letter-spacing:1px;opacity:.7}
+ .cards-list{padding:40px 24px;display:flex;flex-direction:column;gap:18px;padding-bottom:200px}
+ .card{background:#0d1117;border:1px solid #21262d;border-radius:10px;padding:22px 24px;transition:border-color .3s}
+ .card.revealed{border-color:#21262d}
+ .card-tag{font-size:9px;text-transform:uppercase;letter-spacing:2px;color:var(--ui-accent);margin-bottom:8px;opacity:.7}
+ .card-title{font-size:clamp(14px,1.8vw,17px);font-weight:bold;margin-bottom:6px}
+ .card-body{font-size:11px;opacity:.5;line-height:1.6}
+ /* Pre-reveal states */
+ .card[data-fx="fade"]{opacity:0;transition:opacity .6s ease}
+ .card[data-fx="slide-up"]{opacity:0;transform:translateY(28px);transition:opacity .6s ease,transform .6s ease}
+ .card[data-fx="slide-left"]{opacity:0;transform:translateX(-44px);transition:opacity .6s ease,transform .6s ease}
+ .card[data-fx="scale"]{opacity:0;transform:scale(.86);transition:opacity .6s ease,transform .6s ease}
+ .card[data-fx="blur"]{opacity:0;filter:blur(12px);transition:opacity .6s ease,filter .6s ease}
+ .card[data-fx="mask"]{clip-path:inset(0 100% 0 0);transition:clip-path .7s ease}
+ .card[data-fx="stagger"]{opacity:1}
+ .card[data-fx="stagger"] .stagger-child{opacity:0;transform:translateY(16px);transition:opacity .5s ease,transform .5s ease}
+ /* Revealed states */
+ .card.revealed[data-fx="fade"]{opacity:1}
+ .card.revealed[data-fx="slide-up"]{opacity:1;transform:translateY(0)}
+ .card.revealed[data-fx="slide-left"]{opacity:1;transform:translateX(0)}
+ .card.revealed[data-fx="scale"]{opacity:1;transform:scale(1)}
+ .card.revealed[data-fx="blur"]{opacity:1;filter:blur(0)}
+ .card.revealed[data-fx="mask"]{clip-path:inset(0 0% 0 0)}
+ .card.revealed[data-fx="stagger"] .stagger-child{opacity:1;transform:translateY(0)}
+ .stagger-row{display:flex;gap:10px;flex-wrap:wrap;margin-top:8px}
+ .stagger-chip{background:#161b22;border:1px solid #21262d;border-radius:6px;padding:6px 12px;font-size:10px}
+ 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);font-size:10px}
+ .div{height:1px;background:var(--ui-border)}
+ .sr{display:flex;align-items:center;gap:6px;font-size:10px}
+ .sr input[type=range]{flex:1;accent-color:var(--ui-accent);min-height:44px}
+ .sv{width:34px;text-align:right;color:var(--ui-text)}
+ .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}
+ .code-block{background:#0d1117;border:1px solid #21262d;border-radius:4px;padding:8px;font-size:9px;color:#56d364;line-height:1.6;overflow-x:auto}
+ .log{display:flex;flex-direction:column;gap:2px;max-height:80px;overflow:hidden}
+ .log-row{font-size:9px;opacity:.6}
+ .state-list{display:flex;flex-direction:column;gap:2px}
+ .state-row{display:flex;justify-content:space-between;font-size:9px;color:var(--ui-muted)}
+ .state-row .state-v{color:var(--ui-text)}
+ button.rst{background:transparent;border:1px solid var(--ui-border);color:var(--ui-text);font-family:monospace;font-size:10px;padding:14px 8px;border-radius:4px;cursor:pointer;width:100%}
+ @media(hover:hover){button.rst:hover{border-color:var(--ui-accent);color:var(--ui-accent)}}
+ @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}:root{--stage-h:480px}}
+ @media(prefers-reduced-motion:reduce){.card,.card .stagger-child{transition:none!important}}
+ </style>
+</head>
+<body>
+<header>
+ <h1>Reveal on Scroll</h1>
+ <p>7 reveal techniques fired by IntersectionObserver — dashed line marks the trigger threshold.</p>
+</header>
+<div class="layout">
+ <div class="stage-wrap">
+ <div class="stage" id="stage">
+ <div id="trigger-line"><div id="trigger-label">trigger</div></div>
+ <div class="cards-list" id="cards-list"></div>
+ </div>
+ </div>
+ <aside>
+ <p class="note">IntersectionObserver fires at the compositor level — no JS per scroll frame. rootMargin shifts the viewport boundary to match the trigger line position.</p>
+ <div><div class="lbl" id="thr-lbl">Trigger position</div>
+ <div class="sr"><input type="range" id="thr-sl" aria-labelledby="thr-lbl" min="30" max="90" value="70" step="5"><span class="sv" id="thr-val">70%</span></div>
+ </div>
+ <div class="div"></div>
+ <div class="lbl">Observer config</div>
+ <div class="code-block" id="obs-code"></div>
+ <div class="div"></div>
+ <label class="tog" for="repeat-tog"><input type="checkbox" id="repeat-tog"><span>Repeat on re-enter</span></label>
+ <div class="div"></div>
+ <div class="lbl">Event log</div>
+ <div class="log" id="event-log"></div>
+ <div class="div"></div>
+ <div class="lbl">Card states</div>
+ <div class="state-list" id="state-list"></div>
+ <div class="div"></div>
+ <button class="rst" id="reset-btn">Reset all cards</button>
+ </aside>
+</div>
+<script>
+ const CARDS=[
+ {fx:'fade', title:'Fade', body:'opacity 0 → 1', tag:'Technique 01'},
+ {fx:'slide-up', title:'Slide Up', body:'translateY 28px → 0 + fade', tag:'Technique 02'},
+ {fx:'slide-left',title:'Slide from Left',body:'translateX −44px → 0 + fade', tag:'Technique 03'},
+ {fx:'scale', title:'Scale In', body:'scale 0.86 → 1 + fade', tag:'Technique 04'},
+ {fx:'blur', title:'Blur In', body:'filter blur 12px → 0 + fade', tag:'Technique 05'},
+ {fx:'mask', title:'Mask Reveal', body:'clip-path inset(0 100% 0 0) → inset(0 0% 0 0)', tag:'Technique 06'},
+ {fx:'stagger', title:'Stagger Group','body':'4 children with cascading 80ms delays', tag:'Technique 07'},
+ ];
+ const stage=document.getElementById('stage');
+ const thrSl=document.getElementById('thr-sl'),thrVal=document.getElementById('thr-val');
+ const repeatTog=document.getElementById('repeat-tog'),obsCode=document.getElementById('obs-code');
+ const eventLog=document.getElementById('event-log'),stateList=document.getElementById('state-list');
+ const triggerLine=document.getElementById('trigger-line');
+ let observer,threshold=70,events=[];
+
+ // Build cards
+ const cardEls=CARDS.map((c,i)=>{
+ const el=document.createElement('div');
+ el.className='card';el.dataset.fx=c.fx;el.dataset.i=i;
+ let inner=`<div class="card-tag" style="color:var(--ui-accent)">${c.tag} · ${c.fx}</div>
+ <div class="card-title">${c.title}</div>`;
+ if(c.fx==='stagger'){
+ inner+=`<div class="stagger-row">${['Alpha','Beta','Gamma','Delta'].map(n=>`<div class="stagger-chip stagger-child">${n}</div>`).join('')}</div>`;
+ }else{inner+=`<div class="card-body">${c.body}</div>`;}
+ el.innerHTML=inner;
+ document.getElementById('cards-list').appendChild(el);
+ // State row in panel
+ const sr=document.createElement('div');sr.className='state-row';sr.id='sr-'+i;
+ sr.innerHTML=`<span>${c.fx}</span><span class="state-v" id="sv-${i}">idle</span>`;
+ stateList.appendChild(sr);
+ return el;
+ });
+
+ function buildObserver(){
+ if(observer)observer.disconnect();
+ const margin=-(100-threshold);
+ obsCode.textContent=`new IntersectionObserver(cb,{\n root: stage,\n rootMargin: "0px 0px ${margin}% 0px",\n threshold: 0\n})`;
+ observer=new IntersectionObserver(entries=>{
+ entries.forEach(e=>{
+ const i=+e.target.dataset.i,fx=e.target.dataset.fx;
+ if(e.isIntersecting){
+ reveal(e.target,fx,i);
+ logEvent(`→ enter: ${fx}`);
+ if(!repeatTog.checked)observer.unobserve(e.target);
+ }else if(repeatTog.checked){
+ hide(e.target,fx,i);
+ logEvent(`← leave: ${fx}`);
+ }
+ });
+ },{root:stage,rootMargin:`0px 0px ${margin}% 0px`,threshold:0});
+ cardEls.forEach(el=>observer.observe(el));
+ }
+
+ function reveal(el,fx,i){
+ el.classList.add('revealed');
+ document.getElementById('sv-'+i).textContent='revealed';
+ if(fx==='stagger'){
+ el.querySelectorAll('.stagger-child').forEach((c,j)=>{
+ setTimeout(()=>{c.style.opacity='1';c.style.transform='translateY(0)';},j*80);
+ });
+ }
+ }
+ function hide(el,fx,i){
+ el.classList.remove('revealed');
+ document.getElementById('sv-'+i).textContent='idle';
+ if(fx==='stagger'){
+ el.querySelectorAll('.stagger-child').forEach(c=>{c.style.opacity='';c.style.transform='';});
+ }
+ }
+ function logEvent(msg){
+ events.unshift(msg);if(events.length>5)events.pop();
+ eventLog.innerHTML=events.map(e=>`<div class="log-row">${e}</div>`).join('');
+ }
+ function updateLine(){
+ triggerLine.style.top=(threshold/100*stage.clientHeight)+'px';
+ thrVal.textContent=threshold+'%';
+ obsCode.textContent=`new IntersectionObserver(cb,{\n root: stage,\n rootMargin: "0px 0px ${-(100-threshold)}% 0px",\n threshold: 0\n})`;
+ }
+
+ thrSl.addEventListener('input',()=>{threshold=+thrSl.value;updateLine();buildObserver()});
+ repeatTog.addEventListener('change',buildObserver);
+ document.getElementById('reset-btn').addEventListener('click',()=>{
+ cardEls.forEach((el,i)=>{hide(el,el.dataset.fx,i)});
+ stage.scrollTop=0;events=[];eventLog.innerHTML='';
+ setTimeout(buildObserver,50);
+ });
+
+ stage.addEventListener('scroll',updateLine,{passive:true});
+ updateLine();buildObserver();
+</script>
+</body>
+</html>
diff --git a/animations/01-scroll-based/scrollytelling/index.html b/animations/01-scroll-based/scrollytelling/index.html
new file mode 100644
index 00000000..d2d305be
--- /dev/null
+++ b/animations/01-scroll-based/scrollytelling/index.html
@@ -0,0 +1,148 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <meta charset="UTF-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
+ <title>Scrollytelling</title>
+ <style>
+ :root{--bg:#020b14;--ui-bg:#031018;--ui-border:#0a2030;--ui-accent:#00c8ff;--ui-text:#b0d4e8;--ui-muted:#4a7090;--stage-h:640px}
+ *,*::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:var(--stage-h);overflow-y:scroll;scrollbar-width:none;border:1px solid var(--ui-border);border-radius:8px;display:flex}
+ .stage::-webkit-scrollbar{display:none}
+ .vis{position:sticky;top:0;width:45%;height:var(--stage-h);flex-shrink:0;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:20px;padding:28px;overflow:hidden}
+ .chapters{flex:1;padding:20px 28px}
+ .ch{min-height:calc(var(--stage-h) * 0.9);display:flex;flex-direction:column;justify-content:center;padding:40px 0;border-bottom:1px solid #0a2030}
+ .ch:last-child{border-bottom:none}
+ .ch-eye{font-size:10px;text-transform:uppercase;letter-spacing:2px;margin-bottom:8px;opacity:.6}
+ .ch-head{font-size:clamp(18px,2.6vw,26px);font-weight:bold;line-height:1.2;margin-bottom:14px}
+ .ch-body{font-size:12px;line-height:1.7;opacity:.65;max-width:300px;margin-bottom:12px}
+ .ch-fact{border-left:3px solid var(--ui-accent);padding-left:12px;font-size:10px;opacity:.5;font-style:italic;line-height:1.6}
+ #porthole{width:min(220px,85%);aspect-ratio:1;border-radius:50%;border:4px solid #00c8ff;overflow:hidden;flex-shrink:0;position:relative}
+ #ph-bg{position:absolute;inset:0;transition:background 1.2s ease}
+ #ph-shimmer{position:absolute;inset:0;background:linear-gradient(145deg,rgba(255,255,255,.06) 0%,transparent 50%)}
+ #depth-num{font-size:clamp(26px,3.5vw,42px);font-weight:bold;letter-spacing:2px;font-variant-numeric:tabular-nums;text-align:center}
+ #depth-lbl{font-size:10px;opacity:.4;letter-spacing:3px;text-transform:uppercase;text-align:center}
+ aside{width:clamp(180px,20vw,220px);flex-shrink:0;background:var(--ui-bg);border:1px solid var(--ui-border);border-radius:8px;padding:14px;display:flex;flex-direction:column;gap:9px}
+ .note{font-size:10px;color:var(--ui-muted);line-height:1.6;border-left:2px solid var(--ui-accent);padding-left:8px}
+ .lbl{font-size:10px;text-transform:uppercase;letter-spacing:1px;color:var(--ui-accent)}
+ .kv{display:flex;justify-content:space-between;font-size:10px;color:var(--ui-muted)}
+ .kv .v{color:var(--ui-text)}
+ .div{height:1px;background:var(--ui-border)}
+ .jlist{display:flex;flex-direction:column;gap:3px}
+ .jbtn{background:none;border:1px solid var(--ui-border);color:var(--ui-muted);font-family:monospace;font-size:9px;padding:6px 8px;border-radius:4px;cursor:pointer;text-align:left;min-height:36px;width:100%}
+ .jbtn.on{border-color:var(--ui-accent);color:var(--ui-accent)}
+ @media(hover:hover){.jbtn:hover{border-color:var(--ui-accent)}}
+ button.rst{background:transparent;border:1px solid var(--ui-border);color:var(--ui-text);font-family:monospace;font-size:10px;padding:14px 8px;border-radius:4px;cursor:pointer;width:100%}
+ @media(hover:hover){button.rst:hover{border-color:var(--ui-accent);color:var(--ui-accent)}}
+ @media(max-width:600px){
+ .layout{flex-direction:column}aside{width:100%}:root{--stage-h:560px}
+ .stage{flex-direction:column}.vis{position:sticky;top:0;width:100%;height:200px;flex-direction:row;gap:16px;z-index:2}
+ #porthole{width:140px}.chapters{padding:12px 16px}
+ }
+ @media(prefers-reduced-motion:reduce){#ph-bg{transition:none!important}}
+ </style>
+</head>
+<body>
+<header>
+ <h1>Scrollytelling</h1>
+ <p>Fractional chapter progress drives depth readout and ocean-layer crossfades continuously, not in steps.</p>
+</header>
+<div class="layout">
+ <div class="stage" id="stage">
+ <div class="vis" id="vis">
+ <div id="porthole"><div id="ph-bg"></div><div id="ph-shimmer"></div></div>
+ <div><div id="depth-num">0</div><div id="depth-lbl">metres depth</div></div>
+ </div>
+ <div class="chapters" id="chapters"></div>
+ </div>
+ <aside>
+ <p class="note">Scrollytelling synchronizes multiple media types to a single scroll input. Fractional progress drives smooth transitions — the reader experiences a continuous journey, not a slideshow.</p>
+ <div class="lbl">Position</div>
+ <div class="kv"><span>Scroll</span><span class="v" id="sc-pct">0%</span></div>
+ <div class="kv"><span>Chapter</span><span class="v" id="sc-ch">—</span></div>
+ <div class="div"></div>
+ <div class="lbl">Jump to chapter</div>
+ <div class="jlist" id="jlist"></div>
+ <div class="div"></div>
+ <button class="rst" id="rst">Return to surface</button>
+ </aside>
+</div>
+<script>
+ const CHS=[
+ {depth:0, head:'The Surface', eye:'01 · 0 m', bg:'#1a4a8c',ac:'#40d8ff',
+ body:'Sunlight refracts through wave patterns, scattering blue and gold. This threshold separates two entirely different worlds.',
+ fact:'Light penetrates here at full intensity — photosynthesis sustains nearly all ocean life above this line.'},
+ {depth:200, head:'The Sunlit Zone', eye:'02 · 0–200 m', bg:'#0d2e5c',ac:'#00aadd',
+ body:'The euphotic zone receives enough light for photosynthesis. Plankton, sardines, and sea turtles move through filtered, shifting blue.',
+ fact:'95% of all commercial fish species live in this zone. Below this depth, no plant can survive.'},
+ {depth:1000, head:'The Twilight Zone', eye:'03 · 200–1000 m', bg:'#050e20',ac:'#006688',
+ body:'Bioluminescent flashes replace sunlight. Creatures have evolved enormous eyes. Pressure climbs to 100 atmospheres.',
+ fact:'The mesopelagic zone holds more fish biomass than all surface fisheries combined — almost entirely uncounted.'},
+ {depth:4000, head:'The Midnight Zone', eye:'04 · 1000–4000 m', bg:'#020810',ac:'#003d55',
+ body:'Total darkness. 2–4°C. Marine snow drifts down from the sunlit world above — the only food source for creatures that have never seen light.',
+ fact:'This zone covers more Earth surface area than any other habitat, and remains largely unexplored.'},
+ {depth:6000, head:'The Abyssal Plain', eye:'05 · 4000–6000 m', bg:'#010508',ac:'#001f30',
+ body:'Sediment plains stretch thousands of kilometres. Pressure exceeds 600 atmospheres. Sea cucumbers and snailfish move through crushing cold.',
+ fact:'Manganese nodules blanket the abyss — each the size of a potato, formed over millions of years.'},
+ {depth:10935,head:'The Hadal Zone', eye:'06 · 6000–11000 m',bg:'#010204',ac:'#000e18',
+ body:'Challenger Deep. Three vessels have ever visited. More humans have walked on the Moon. The snailfish survives here — the deepest vertebrate on Earth.',
+ fact:'1,100 atmospheres of pressure. Equivalent to 50 jumbo jets stacked on your thumbnail.'},
+ ];
+ const stage=document.getElementById('stage'),chs=document.getElementById('chapters');
+ const phBg=document.getElementById('ph-bg'),porthole=document.getElementById('porthole');
+ const depNum=document.getElementById('depth-num'),vis=document.getElementById('vis');
+ let ticking=false;
+
+ function lerpCol(h1,h2,t){
+ const p=s=>[parseInt(s.slice(1,3),16),parseInt(s.slice(3,5),16),parseInt(s.slice(5,7),16)];
+ const a=p(h1),b=p(h2);
+ return`#${[0,1,2].map(i=>Math.round(a[i]+(b[i]-a[i])*t).toString(16).padStart(2,'0')).join('')}`;
+ }
+ const clamp=(v,a,b)=>Math.min(Math.max(v,a),b),lerp=(a,b,t)=>a+(b-a)*t;
+
+ CHS.forEach((c,i)=>{
+ const d=document.createElement('div');d.className='ch';
+ d.innerHTML=`<div class="ch-eye" style="color:${c.ac}">${c.eye}</div>
+ <div class="ch-head">${c.head}</div><div class="ch-body">${c.body}</div>
+ <div class="ch-fact">${c.fact}</div>`;
+ chs.appendChild(d);
+ const b=document.createElement('button');b.className='jbtn';b.textContent=c.eye;
+ b.addEventListener('click',()=>stage.scrollTo({top:chs.children[i].offsetTop,behavior:'smooth'}));
+ document.getElementById('jlist').appendChild(b);
+ });
+
+ function update(){
+ const st=stage.scrollTop,max=stage.scrollHeight-stage.clientHeight;
+ document.getElementById('sc-pct').textContent=max>0?Math.round(st/max*100)+'%':'0%';
+ const els=[...chs.children],N=els.length,sr=stage.getBoundingClientRect();
+ let frac=0;
+ for(let i=N-1;i>=0;i--){
+ const r=els[i].getBoundingClientRect();
+ const rel=r.top-sr.top;
+ if(rel<=sr.height*0.42){frac=clamp(i+(-rel/r.height),i,i+1);break;}
+ if(i===0)frac=0;
+ }
+ frac=clamp(frac,0,N-0.001);
+ const ci=Math.floor(frac),cf=frac-ci;
+ const c=CHS[ci],cn=CHS[Math.min(ci+1,N-1)];
+ const col=lerpCol(c.ac,cn.ac,cf);
+ depNum.textContent=Math.round(lerp(c.depth,cn.depth,cf)).toLocaleString();
+ depNum.style.color=col;
+ phBg.style.background=`radial-gradient(circle at 50% 40%,${lerpCol(c.bg,cn.bg,cf)},#000 80%)`;
+ porthole.style.borderColor=col;
+ document.getElementById('sc-ch').textContent=c.eye;
+ document.querySelectorAll('.jbtn').forEach((b,i)=>b.classList.toggle('on',i===ci));
+ ticking=false;
+ }
+
+ stage.addEventListener('scroll',()=>{if(!ticking){requestAnimationFrame(update);ticking=true}},{passive:true});
+ document.getElementById('rst').addEventListener('click',()=>{stage.scrollTop=0;update()});
+ update();
+</script>
+</body>
+</html>
diff --git a/animations/01-scroll-based/section-wipe/index.html b/animations/01-scroll-based/section-wipe/index.html
new file mode 100644
index 00000000..214127b7
--- /dev/null
+++ b/animations/01-scroll-based/section-wipe/index.html
@@ -0,0 +1,131 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <meta charset="UTF-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
+ <title>Section Wipe</title>
+ <style>
+ :root{--bg:#060a10;--ui-bg:#0d1117;--ui-border:#21262d;--ui-accent:#58a6ff;--ui-text:#c9d1d9;--ui-muted:#8b949e;--stage-h:600px;--scale-floor:0.96;--wipe-range:1.0}
+ *,*::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:var(--stage-h);overflow-y:scroll;scrollbar-width:none;border:1px solid var(--ui-border);border-radius:8px}
+ .stage::-webkit-scrollbar{display:none}
+ /* Each section is sticky + full stage height + ascending z-index */
+ .section{position:sticky;top:0;height:var(--stage-h);overflow:hidden}
+ .sec-content{width:100%;height:100%;display:flex;flex-direction:column;justify-content:center;padding:clamp(24px,5vw,56px);transform-origin:center center;will-change:transform}
+ .sec-num{font-size:clamp(70px,12vw,120px);font-weight:bold;opacity:.1;line-height:1;margin-bottom:12px}
+ .sec-title{font-size:clamp(22px,3.5vw,38px);font-weight:bold;margin-bottom:16px;line-height:1.2}
+ .sec-body{font-size:clamp(12px,1.4vw,14px);opacity:.65;line-height:1.7;max-width:480px}
+ /* Spacer after all sections — provides scroll exit */
+ .end-spacer{height:calc(var(--stage-h) * 0.8);display:flex;align-items:center;justify-content:center;font-size:11px;opacity:.25;letter-spacing: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)}
+ .kv{display:flex;justify-content:space-between;font-size:10px;color:var(--ui-muted)}
+ .kv .v{color:var(--ui-text)}
+ .div{height:1px;background:var(--ui-border)}
+ .sr{display:flex;align-items:center;gap:6px;font-size:10px}
+ .sr input[type=range]{flex:1;accent-color:var(--ui-accent);min-height:44px}
+ .sv{width:38px;text-align:right;color:var(--ui-text)}
+ button.rst{background:transparent;border:1px solid var(--ui-border);color:var(--ui-text);font-family:monospace;font-size:10px;padding:14px 8px;border-radius:4px;cursor:pointer;width:100%}
+ @media(hover:hover){button.rst:hover{border-color:var(--ui-accent);color:var(--ui-accent)}}
+ @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}:root{--stage-h:460px}}
+ @media(prefers-reduced-motion:reduce){.sec-content{will-change:auto}}
+ </style>
+</head>
+<body>
+<header>
+ <h1>Section Wipe</h1>
+ <p>Stacked sticky sections with ascending z-index — the next section rises over the current one as you scroll.</p>
+</header>
+<div class="layout">
+ <div class="stage" id="stage">
+ <div class="section" id="s0" style="z-index:1">
+ <div class="sec-content" id="sc0" style="background:linear-gradient(135deg,#0d2b3e,#1a3a5c)">
+ <div class="sec-num">01</div>
+ <div class="sec-title" style="color:#79c0ff">Position, Not JavaScript</div>
+ <div class="sec-body">Section wipe is entirely structural. Each section is sticky at top:0. The next section has a higher z-index and rises naturally as the user scrolls past the first section's height. No animation code for the wipe itself.</div>
+ </div>
+ </div>
+ <div class="section" id="s1" style="z-index:2">
+ <div class="sec-content" id="sc1" style="background:linear-gradient(135deg,#2d1b3d,#3d2a5c)">
+ <div class="sec-num">02</div>
+ <div class="sec-title" style="color:#d2a8ff">The Receding Layer</div>
+ <div class="sec-body">The only JavaScript-driven effect is the scale-down on the section being covered. As section 3 rises over this one, scale compresses from 1.0 toward the scale floor — making it feel like it's sliding behind the incoming section.</div>
+ </div>
+ </div>
+ <div class="section" id="s2" style="z-index:3">
+ <div class="sec-content" id="sc2" style="background:linear-gradient(135deg,#1e3a1e,#2d5c2d)">
+ <div class="sec-num">03</div>
+ <div class="sec-title" style="color:#56d364">Scrubbed Coverage</div>
+ <div class="sec-body">The scale animates proportionally to how much of the viewport the next section has covered. Mid-scroll, the transition is frozen at an intermediate value — no snap, no jump. Drag the scroll bar slowly to inspect the overlap.</div>
+ </div>
+ </div>
+ <div class="section" id="s3" style="z-index:4">
+ <div class="sec-content" id="sc3" style="background:linear-gradient(135deg,#3d2000,#5c3400)">
+ <div class="sec-num">04</div>
+ <div class="sec-title" style="color:#ffa657">Final Section</div>
+ <div class="sec-body">This section never recedes — it's the topmost layer. GSAP ScrollTrigger can implement this same pattern with scrub:true on a scale tween, adding the ease that CSS alone can't provide here.</div>
+ </div>
+ </div>
+ <div class="end-spacer">end of stack</div>
+ </div>
+ <aside>
+ <p class="note">Section wipe = stacked sticky elements with ascending z-index. The next section rises over the current one naturally. Scale-down on outgoing sections is the only JS addition.</p>
+ <div class="lbl">State</div>
+ <div class="kv"><span>Scroll</span><span class="v" id="sc-pct">0%</span></div>
+ <div class="kv"><span>Top section</span><span class="v" id="top-sec">01</span></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="96" step="1"><span class="sv" id="scale-val">0.96</span></div>
+ </div>
+ <div><div class="lbl" id="wipe-lbl">Wipe range</div>
+ <div class="sr"><input type="range" id="wipe-sl" aria-labelledby="wipe-lbl" min="20" max="100" value="100" step="5"><span class="sv" id="wipe-val">100%</span></div>
+ </div>
+ <div class="div"></div>
+ <button class="rst" id="rst">Reset scroll</button>
+ </aside>
+</div>
+<script>
+ const stage=document.getElementById('stage');
+ const scPct=document.getElementById('sc-pct'),topSec=document.getElementById('top-sec');
+ const scaleSl=document.getElementById('scale-sl'),scaleVal=document.getElementById('scale-val');
+ const wipeSl=document.getElementById('wipe-sl'),wipeVal=document.getElementById('wipe-val');
+ const sections=[...document.querySelectorAll('.section')];
+ const contents=sections.map(s=>s.querySelector('.sec-content'));
+ let scaleFloor=0.96,wipeRange=1.0,ticking=false;
+ const clamp=(v,a,b)=>Math.min(Math.max(v,a),b),lerp=(a,b,t)=>a+(b-a)*t;
+ const motionOk=!window.matchMedia('(prefers-reduced-motion:reduce)').matches;
+
+ function update(){
+ const st=stage.scrollTop,max=stage.scrollHeight-stage.clientHeight,sr=stage.getBoundingClientRect();
+ scPct.textContent=max>0?Math.round(st/max*100)+'%':'0%';
+ let top=0;
+ sections.forEach((s,i)=>{
+ const r=s.querySelector('.sec-content').getBoundingClientRect();
+ if(r.top<=sr.top+2)top=i;
+ });
+ topSec.textContent=String(top+1).padStart(2,'0');
+ if(!motionOk){ticking=false;return;}
+ sections.forEach((s,i)=>{
+ if(i===sections.length-1)return;
+ const nextR=sections[i+1].getBoundingClientRect();
+ const coverage=sr.height-(nextR.top-sr.top);
+ const t=clamp(coverage/(sr.height*wipeRange),0,1);
+ contents[i].style.transform=`scale(${lerp(1,scaleFloor,t).toFixed(4)})`;
+ });
+ ticking=false;
+ }
+
+ stage.addEventListener('scroll',()=>{if(!ticking){requestAnimationFrame(update);ticking=true}},{passive:true});
+ scaleSl.addEventListener('input',()=>{scaleFloor=scaleSl.value/100;scaleVal.textContent=scaleFloor.toFixed(2);update()});
+ wipeSl.addEventListener('input',()=>{wipeRange=wipeSl.value/100;wipeVal.textContent=wipeSl.value+'%';update()});
+ document.getElementById('rst').addEventListener('click',()=>{stage.scrollTop=0;update()});
+ update();
+</script>
+</body>
+</html>
diff --git a/animations/01-scroll-based/stagger-reveal/index.html b/animations/01-scroll-based/stagger-reveal/index.html
new file mode 100644
index 00000000..e12c5309
--- /dev/null
+++ b/animations/01-scroll-based/stagger-reveal/index.html
@@ -0,0 +1,198 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <meta charset="UTF-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
+ <title>Stagger Reveal</title>
+ <style>
+ :root{--bg:#060a10;--ui-bg:#0d1117;--ui-border:#21262d;--ui-accent:#58a6ff;--ui-text:#c9d1d9;--ui-muted:#8b949e;--stage-h:620px}
+ *,*::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:var(--stage-h);overflow-y:scroll;scrollbar-width:none;border:1px solid var(--ui-border);border-radius:8px}
+ .stage::-webkit-scrollbar{display:none}
+ .section{padding:40px 24px;border-bottom:1px solid var(--ui-border)}
+ .section:last-child{padding-bottom:80px;border:none}
+ .sec-head{font-size:12px;text-transform:uppercase;letter-spacing:2px;color:var(--ui-accent);margin-bottom:20px;opacity:.7}
+ /* Grid */
+ .grid{display:grid;grid-template-columns:repeat(4,1fr);gap:10px}
+ .grid-cell{background:#0d1117;border:1px solid #21262d;border-radius:8px;padding:14px 10px;font-size:10px;text-align:center;position:relative}
+ .delay-badge{position:absolute;top:4px;right:5px;font-size:8px;color:var(--ui-accent);opacity:.5}
+ /* List */
+ .list-row{display:flex;align-items:center;gap:12px;padding:10px 0;border-bottom:1px solid #0d1117}
+ .list-row:last-child{border:none}
+ .avatar{width:32px;height:32px;border-radius:50%;flex-shrink:0;background:var(--ui-accent)}
+ .list-label{flex:1;font-size:11px}
+ .list-meta{font-size:10px;opacity:.4}
+ /* Chips */
+ .chips{display:flex;flex-wrap:wrap;gap:8px}
+ .chip{background:#0d1117;border:1px solid #21262d;border-radius:20px;padding:6px 14px;font-size:10px}
+ /* Stagger states */
+ .item{opacity:0;transform:translateY(20px);transition:opacity .4s ease,transform .4s ease}
+ .item.in{opacity:1;transform:translateY(0)}
+ aside{width:clamp(200px,22vw,240px);flex-shrink:0;background:var(--ui-bg);border:1px solid var(--ui-border);border-radius:8px;padding:16px;display:flex;flex-direction:column;gap:10px}
+ .note{font-size:10px;color:var(--ui-muted);line-height:1.6;border-left:2px solid var(--ui-accent);padding-left:8px}
+ .lbl{font-size:10px;text-transform:uppercase;letter-spacing:1px;color:var(--ui-accent)}
+ .kv{display:flex;justify-content:space-between;font-size:10px;color:var(--ui-muted)}
+ .kv .v{color:var(--ui-text)}
+ .div{height:1px;background:var(--ui-border)}
+ .sr{display:flex;align-items:center;gap:6px;font-size:10px}
+ .sr input[type=range]{flex:1;accent-color:var(--ui-accent);min-height:44px}
+ .sv{width:38px;text-align:right;color:var(--ui-text)}
+ .seg{display:flex;gap:3px;flex-wrap:wrap}
+ .seg button{flex:1;background:none;border:1px solid var(--ui-border);color:var(--ui-muted);font-family:monospace;font-size:9px;padding:8px 4px;border-radius:4px;cursor:pointer;min-height:36px}
+ .seg button.on{border-color:var(--ui-accent);color:var(--ui-accent);background:#0d2040}
+ .matrix{display:grid;grid-template-columns:repeat(4,1fr);gap:3px}
+ .mdot{width:100%;aspect-ratio:1;border-radius:3px;background:#21262d;display:flex;align-items:center;justify-content:center;font-size:8px;color:#8b949e;transition:background .1s}
+ button.rst{background:transparent;border:1px solid var(--ui-border);color:var(--ui-text);font-family:monospace;font-size:10px;padding:14px 8px;border-radius:4px;cursor:pointer;width:100%}
+ @media(hover:hover){button.rst:hover{border-color:var(--ui-accent);color:var(--ui-accent)}}
+ @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}:root{--stage-h:480px}.grid{grid-template-columns:repeat(2,1fr)}}
+ @media(prefers-reduced-motion:reduce){.item{transition:none!important}}
+ </style>
+</head>
+<body>
+<header>
+ <h1>Stagger Reveal</h1>
+ <p>Groups of elements reveal sequentially — the preview matrix shows cascade order before you scroll.</p>
+</header>
+<div class="layout">
+ <div class="stage" id="stage">
+ <div class="section" id="sec-grid">
+ <div class="sec-head">01 · Card Grid (4 × 3)</div>
+ <div class="grid" id="grid"></div>
+ </div>
+ <div class="section" id="sec-list">
+ <div class="sec-head">02 · List Rows</div>
+ <div id="list"></div>
+ </div>
+ <div class="section" id="sec-chips">
+ <div class="sec-head">03 · Tag Chips</div>
+ <div class="chips" id="chips"></div>
+ </div>
+ </div>
+ <aside>
+ <p class="note">40–60ms is the sweet spot. Below 30ms the eye can't separate items. Above 100ms it feels sluggish. Cap total stagger time at ~600ms on long lists.</p>
+ <div><div class="lbl" id="delay-lbl">Stagger delay</div>
+ <div class="sr"><input type="range" id="delay-sl" aria-labelledby="delay-lbl" min="0" max="150" value="50" step="10"><span class="sv" id="delay-val">50ms</span></div>
+ </div>
+ <div class="div"></div>
+ <div class="lbl">Cascade direction</div>
+ <div class="seg" id="dir-seg">
+ <button data-d="forward" class="on">→ Forward</button>
+ <button data-d="reverse">← Reverse</button>
+ <button data-d="center">↔ Center</button>
+ <button data-d="random">⁂ Random</button>
+ </div>
+ <div class="div"></div>
+ <div class="lbl">Preview matrix (grid)</div>
+ <div class="matrix" id="matrix"></div>
+ <div class="div"></div>
+ <button class="rst" id="replay-btn">Replay all groups</button>
+ </aside>
+</div>
+<script>
+ const stage=document.getElementById('stage');
+ const delaySl=document.getElementById('delay-sl'),delayVal=document.getElementById('delay-val');
+ const matrix=document.getElementById('matrix');
+ let staggerMs=50,direction='forward',observers=[];
+
+ const GRID_ITEMS=['Alpha','Beta','Gamma','Delta','Epsilon','Zeta','Eta','Theta','Iota','Kappa','Lambda','Mu'];
+ const LIST_ITEMS=[
+ {name:'Ada Lovelace',meta:'Algorithmics','color':'#79c0ff'},
+ {name:'Grace Hopper',meta:'Compilation','color':'#56d364'},
+ {name:'Alan Turing',meta:'Computation','color':'#d2a8ff'},
+ {name:'Claude Shannon',meta:'Information theory','color':'#ffa657'},
+ {name:'Tim Berners-Lee',meta:'WWW Protocol','color':'#58a6ff'},
+ {name:'Margaret Hamilton',meta:'Software engineering','color':'#f78166'},
+ ];
+ const CHIPS=['CSS Grid','Flexbox','Sticky','IntersectionObserver','clip-path','rAF','View Transitions','WAAPI'];
+
+ function buildGrid(){
+ const g=document.getElementById('grid');g.innerHTML='';
+ return GRID_ITEMS.map((t,i)=>{
+ const el=document.createElement('div');el.className='grid-cell item';
+ el.innerHTML=`<div class="delay-badge" id="db${i}">0ms</div>${t}`;
+ g.appendChild(el);return el;
+ });
+ }
+ function buildList(){
+ const l=document.getElementById('list');l.innerHTML='';
+ return LIST_ITEMS.map((d,i)=>{
+ const el=document.createElement('div');el.className='list-row item';
+ el.innerHTML=`<div class="avatar" style="background:${d.color}"></div>
+ <div class="list-label">${d.name}</div><div class="list-meta">${d.meta}</div>`;
+ l.appendChild(el);return el;
+ });
+ }
+ function buildChips(){
+ const c=document.getElementById('chips');c.innerHTML='';
+ return CHIPS.map((t,i)=>{
+ const el=document.createElement('div');el.className='chip item';el.textContent=t;
+ c.appendChild(el);return el;
+ });
+ }
+
+ function getOrder(n){
+ if(direction==='forward')return Array.from({length:n},(_,i)=>i);
+ if(direction==='reverse')return Array.from({length:n},(_,i)=>n-1-i);
+ if(direction==='center'){const c=Math.floor(n/2);return Array.from({length:n},(_,i)=>Math.abs(i-c));}
+ const a=Array.from({length:n},(_,i)=>i);for(let i=a.length-1;i>0;i--){const j=Math.floor(Math.random()*(i+1));[a[i],a[j]]=[a[j],a[i]];}return a;
+ }
+
+ function staggerIn(items,updateBadges){
+ const order=getOrder(items.length);
+ items.forEach((el,i)=>{
+ const d=order[i]*staggerMs;
+ if(updateBadges){const b=el.querySelector('.delay-badge');if(b)b.textContent=d+'ms';}
+ setTimeout(()=>el.classList.add('in'),d);
+ });
+ }
+ function staggerOut(items){items.forEach(el=>{el.classList.remove('in');});}
+
+ function updateMatrix(){
+ const order=getOrder(12);const max=Math.max(...order)||1;
+ [...matrix.children].forEach((d,i)=>{
+ const norm=order[i]/max;
+ d.style.background=`rgba(88,166,255,${0.15+norm*0.8})`;
+ d.textContent=order[i]+1;
+ });
+ }
+
+ let gridItems=buildGrid(),listItems=buildList(),chipItems=buildChips();
+ // Build matrix dots
+ for(let i=0;i<12;i++){const d=document.createElement('div');d.className='mdot';matrix.appendChild(d);}
+ updateMatrix();
+
+ function attachObservers(){
+ observers.forEach(o=>o.disconnect());observers=[];
+ [[document.getElementById('sec-grid'),gridItems,true],
+ [document.getElementById('sec-list'),listItems,false],
+ [document.getElementById('sec-chips'),chipItems,false]].forEach(([sec,items,badges])=>{
+ const o=new IntersectionObserver(([e])=>{if(e.isIntersecting)staggerIn(items,badges)},{root:stage,threshold:.05});
+ o.observe(sec);observers.push(o);
+ });
+ }
+ attachObservers();
+
+ delaySl.addEventListener('input',()=>{staggerMs=+delaySl.value;delayVal.textContent=staggerMs+'ms';updateMatrix();});
+ document.querySelectorAll('#dir-seg button').forEach(b=>{
+ b.addEventListener('click',()=>{
+ document.querySelectorAll('#dir-seg button').forEach(x=>x.classList.remove('on'));
+ b.classList.add('on');direction=b.dataset.d;updateMatrix();
+ });
+ });
+ document.getElementById('replay-btn').addEventListener('click',()=>{
+ gridItems=buildGrid();listItems=buildList();chipItems=buildChips();
+ stage.scrollTop=0;
+ observers.forEach(o=>o.disconnect());observers=[];
+ setTimeout(()=>{
+ attachObservers();
+ setTimeout(()=>staggerIn(gridItems,true),100);
+ },50);
+ });
+</script>
+</body>
+</html>
diff --git a/animations/01-scroll-based/sticky-section/index.html b/animations/01-scroll-based/sticky-section/index.html
new file mode 100644
index 00000000..435e95eb
--- /dev/null
+++ b/animations/01-scroll-based/sticky-section/index.html
@@ -0,0 +1,178 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <meta charset="UTF-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
+ <title>Sticky Section</title>
+ <style>
+ :root{--bg:#060a10;--ui-bg:#0d1117;--ui-border:#21262d;--ui-accent:#58a6ff;--ui-text:#c9d1d9;--ui-muted:#8b949e;--stage-h:620px}
+ *,*::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:var(--stage-h);overflow-y:scroll;scrollbar-width:none;border:1px solid var(--ui-border);border-radius:8px}
+ .stage::-webkit-scrollbar{display:none}
+ .spacer{height:var(--stage-h);display:flex;align-items:center;justify-content:center;font-size:11px;opacity:.25;letter-spacing:2px;text-align:center;padding:20px}
+ /* Sticky section — 4× stage height for scroll budget */
+ #sticky-wrap{height:calc(var(--stage-h) * 4);position:relative}
+ #sticky-inner{position:sticky;top:0;height:var(--stage-h);overflow:hidden;display:grid;grid-template-columns:1fr 1fr;gap:0}
+ /* States */
+ .state{position:absolute;inset:0;display:flex;flex-direction:column;justify-content:center;padding:clamp(24px,4vw,48px);opacity:0;pointer-events:none;transition:opacity .5s ease}
+ .state.visible{opacity:1;pointer-events:auto}
+ .state-eye{font-size:10px;text-transform:uppercase;letter-spacing:2px;margin-bottom:12px;opacity:.6}
+ .state-head{font-size:clamp(20px,3vw,32px);font-weight:bold;line-height:1.2;margin-bottom:16px}
+ .state-body{font-size:12px;opacity:.6;line-height:1.7;max-width:340px}
+ .state-cta{margin-top:20px;align-self:flex-start;border:1px solid var(--ui-accent);color:var(--ui-accent);font-family:monospace;font-size:10px;padding:10px 16px;border-radius:4px;letter-spacing:1px}
+ /* Visual column */
+ #vis-col{position:sticky;top:0;height:var(--stage-h);background:#0d1117;display:flex;align-items:center;justify-content:center;overflow:hidden}
+ .illus{position:absolute;width:min(280px,80%);aspect-ratio:1;opacity:0;transition:opacity .6s ease;display:flex;align-items:center;justify-content:center}
+ .illus.visible{opacity:1}
+ /* Text column */
+ #text-col{position:relative;height:var(--stage-h);background:#060a10}
+ /* Progress bar */
+ #seg-bar{display:flex;gap:3px;margin-top:8px}
+ .seg-fill{flex:1;height:4px;border-radius:2px;background:#21262d;overflow:hidden}
+ .seg-inner{height:100%;background:var(--ui-accent);width:0%;transition:width .1s}
+ aside{width:clamp(200px,22vw,240px);flex-shrink:0;background:var(--ui-bg);border:1px solid var(--ui-border);border-radius:8px;padding:16px;display:flex;flex-direction:column;gap:10px}
+ .note{font-size:10px;color:var(--ui-muted);line-height:1.6;border-left:2px solid var(--ui-accent);padding-left:8px}
+ .lbl{font-size:10px;text-transform:uppercase;letter-spacing:1px;color:var(--ui-accent)}
+ .kv{display:flex;justify-content:space-between;font-size:10px;color:var(--ui-muted)}
+ .kv .v{color:var(--ui-text)}
+ .div{height:1px;background:var(--ui-border)}
+ button.rst{background:transparent;border:1px solid var(--ui-border);color:var(--ui-text);font-family:monospace;font-size:10px;padding:14px 8px;border-radius:4px;cursor:pointer;width:100%}
+ @media(hover:hover){button.rst:hover{border-color:var(--ui-accent);color:var(--ui-accent)}}
+ @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}:root{--stage-h:480px}#sticky-inner{grid-template-columns:1fr}#vis-col{display:none}}
+ @media(prefers-reduced-motion:reduce){.state,.illus{transition:none!important}}
+ </style>
+</head>
+<body>
+<header>
+ <h1>Sticky Section</h1>
+ <p>The whole section pins to the viewport while its interior morphs through 4 states — scrubbed to scroll position.</p>
+</header>
+<div class="layout">
+ <div class="stage" id="stage">
+ <div class="spacer">Scroll down to enter the sticky section ↓</div>
+ <div id="sticky-wrap">
+ <div id="sticky-inner">
+ <div id="text-col">
+ <div class="state" id="s0">
+ <div class="state-eye" style="color:#79c0ff">State 01 · Foundation</div>
+ <div class="state-head">Everything starts with structure.</div>
+ <div class="state-body">Before any animation, there is layout. CSS sticky positioning transforms a single section into an extended viewport experience without JavaScript pinning.</div>
+ </div>
+ <div class="state" id="s1">
+ <div class="state-eye" style="color:#56d364">State 02 · Transition</div>
+ <div class="state-head">Scroll becomes the timeline.</div>
+ <div class="state-body">Progress through the sticky section is computed as a 0–1 value. Each state occupies 25% of that range. State boundaries are thresholds, not events.</div>
+ </div>
+ <div class="state" id="s2">
+ <div class="state-eye" style="color:#ffa657">State 03 · Interpolation</div>
+ <div class="state-head">Between states, values blend.</div>
+ <div class="state-body">Crossfades between opacity values, illustration swaps, and text transitions happen in the fractional space between integer state indices — smooth, not stepped.</div>
+ </div>
+ <div class="state" id="s3">
+ <div class="state-eye" style="color:#d2a8ff">State 04 · Release</div>
+ <div class="state-head">When the budget runs out, scroll continues.</div>
+ <div class="state-body">The sticky wrapper ends and the section scrolls away. Content after it resumes normal flow. The pin is defined entirely by the wrapper's height.</div>
+ <div class="state-cta">Continue scrolling →</div>
+ </div>
+ </div>
+ <div id="vis-col">
+ <div class="illus" id="il0">
+ <svg viewBox="0 0 200 200" width="200" height="200" xmlns="http://www.w3.org/2000/svg">
+ <rect x="30" y="30" width="140" height="140" rx="12" fill="none" stroke="#79c0ff" stroke-width="2" opacity=".4"/>
+ <rect x="55" y="55" width="90" height="90" rx="8" fill="none" stroke="#79c0ff" stroke-width="2" opacity=".6"/>
+ <rect x="80" y="80" width="40" height="40" rx="4" fill="#79c0ff" opacity=".3"/>
+ <circle cx="100" cy="100" r="8" fill="#79c0ff"/>
+ </svg>
+ </div>
+ <div class="illus" id="il1">
+ <svg viewBox="0 0 200 200" width="200" height="200" xmlns="http://www.w3.org/2000/svg">
+ <line x1="100" y1="20" x2="100" y2="180" stroke="#56d364" stroke-width="2" opacity=".4"/>
+ <line x1="20" y1="100" x2="180" y2="100" stroke="#56d364" stroke-width="2" opacity=".4"/>
+ <circle cx="100" cy="40" r="12" fill="#56d364" opacity=".6"/>
+ <circle cx="160" cy="100" r="12" fill="#56d364" opacity=".5"/>
+ <circle cx="100" cy="160" r="12" fill="#56d364" opacity=".4"/>
+ <circle cx="40" cy="100" r="12" fill="#56d364" opacity=".3"/>
+ <circle cx="100" cy="100" r="6" fill="#56d364"/>
+ </svg>
+ </div>
+ <div class="illus" id="il2">
+ <svg viewBox="0 0 200 200" width="200" height="200" xmlns="http://www.w3.org/2000/svg">
+ <polygon points="100,20 180,170 20,170" fill="none" stroke="#ffa657" stroke-width="2" opacity=".5"/>
+ <polygon points="100,55 155,155 45,155" fill="none" stroke="#ffa657" stroke-width="2" opacity=".5"/>
+ <polygon points="100,90 130,140 70,140" fill="#ffa657" opacity=".2"/>
+ <circle cx="100" cy="110" r="6" fill="#ffa657"/>
+ </svg>
+ </div>
+ <div class="illus" id="il3">
+ <svg viewBox="0 0 200 200" width="200" height="200" xmlns="http://www.w3.org/2000/svg">
+ <circle cx="100" cy="100" r="70" fill="none" stroke="#d2a8ff" stroke-width="2" opacity=".3"/>
+ <circle cx="100" cy="100" r="50" fill="none" stroke="#d2a8ff" stroke-width="2" opacity=".4"/>
+ <circle cx="100" cy="100" r="30" fill="none" stroke="#d2a8ff" stroke-width="2" opacity=".6"/>
+ <circle cx="100" cy="100" r="8" fill="#d2a8ff" opacity=".8"/>
+ </svg>
+ </div>
+ </div>
+ </div>
+ </div>
+ <div class="spacer">Released — normal scroll resumes ↓</div>
+ </div>
+ <aside>
+ <p class="note">Sticky section pins the whole section, not a single element. Contents morph through states. Distinct from pin-animation, which pins one element while siblings scroll past.</p>
+ <div class="lbl">Scroll state</div>
+ <div class="kv"><span>Overall</span><span class="v" id="ov-pct">0%</span></div>
+ <div class="kv"><span>Lifecycle</span><span class="v" id="lifecycle">approaching</span></div>
+ <div class="kv"><span>State</span><span class="v" id="state-id">—</span></div>
+ <div class="kv"><span>Internal</span><span class="v" id="int-pct">—</span></div>
+ <div class="div"></div>
+ <div class="lbl">State segments</div>
+ <div id="seg-bar">
+ <div class="seg-fill"><div class="seg-inner" id="sg0"></div></div>
+ <div class="seg-fill"><div class="seg-inner" id="sg1"></div></div>
+ <div class="seg-fill"><div class="seg-inner" id="sg2"></div></div>
+ <div class="seg-fill"><div class="seg-inner" id="sg3"></div></div>
+ </div>
+ <div class="div"></div>
+ <button class="rst" id="rst">Reset scroll</button>
+ </aside>
+</div>
+<script>
+ const stage=document.getElementById('stage'),wrap=document.getElementById('sticky-wrap');
+ const states=[...document.querySelectorAll('.state')],illus=[...document.querySelectorAll('.illus')];
+ const lifecycle=document.getElementById('lifecycle'),stateId=document.getElementById('state-id');
+ const intPct=document.getElementById('int-pct'),ovPct=document.getElementById('ov-pct');
+ const STATE_NAMES=['Foundation','Transition','Interpolation','Release'];
+ let ticking=false;
+ const clamp=(v,a,b)=>Math.min(Math.max(v,a),b);
+
+ function update(){
+ const st=stage.scrollTop,max=stage.scrollHeight-stage.clientHeight,stageH=stage.clientHeight;
+ ovPct.textContent=max>0?Math.round(st/max*100)+'%':'0%';
+ const pinStart=wrap.offsetTop,pinH=wrap.offsetHeight;
+ const p=clamp((st-pinStart)/(pinH-stageH),0,1);
+ const before=st<pinStart,after=st>pinStart+pinH-stageH;
+ lifecycle.textContent=before?'approaching':after?'released':`stuck · ${Math.round(p*100)}%`;
+ intPct.textContent=before||after?'—':Math.round(p*100)+'%';
+ const si=Math.min(Math.floor(p*4),3),sf=p*4-si;
+ stateId.textContent=before||after?'—':`0${si+1} · ${STATE_NAMES[si]}`;
+ states.forEach((s,i)=>s.classList.toggle('visible',i===si));
+ illus.forEach((il,i)=>il.classList.toggle('visible',i===si));
+ for(let i=0;i<4;i++){
+ const bar=document.getElementById('sg'+i);
+ if(i<si)bar.style.width='100%';
+ else if(i===si)bar.style.width=Math.round(sf*100)+'%';
+ else bar.style.width='0%';
+ }
+ ticking=false;
+ }
+
+ stage.addEventListener('scroll',()=>{if(!ticking){requestAnimationFrame(update);ticking=true}},{passive:true});
+ document.getElementById('rst').addEventListener('click',()=>{stage.scrollTop=0;update()});
+ update();
+</script>
+</body>
+</html>
diff --git a/animations/01-scroll-based/zoom-into-image/index.html b/animations/01-scroll-based/zoom-into-image/index.html
new file mode 100644
index 00000000..992edbda
--- /dev/null
+++ b/animations/01-scroll-based/zoom-into-image/index.html
@@ -0,0 +1,166 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <meta charset="UTF-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
+ <title>Zoom Into Image</title>
+ <style>
+ :root{--bg:#060a10;--ui-bg:#0d1117;--ui-border:#21262d;--ui-accent:#58a6ff;--ui-text:#c9d1d9;--ui-muted:#8b949e;--stage-h:600px;--start-pct:30;--br-start:16}
+ *,*::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:var(--stage-h);overflow-y:scroll;scrollbar-width:none;border:1px solid var(--ui-border);border-radius:8px}
+ .stage::-webkit-scrollbar{display:none}
+ .spacer{height:calc(var(--stage-h) * 0.6);display:flex;align-items:center;justify-content:center;font-size:11px;opacity:.25;letter-spacing:2px;text-align:center;padding:16px}
+ #zoom-section{height:calc(var(--stage-h) * 2.5);position:relative}
+ #zoom-sticky{position:sticky;top:0;height:var(--stage-h);display:flex;align-items:center;justify-content:center;overflow:hidden}
+ /* Frame shown when showFrame is on */
+ #frame{position:absolute;inset:0;display:flex;align-items:center;justify-content:center;pointer-events:none;opacity:1;transition:opacity .4s}
+ .frame-border{position:absolute;border:1px solid rgba(255,255,255,.15);border-radius:calc(var(--br-start) * 1px + 2px);pointer-events:none}
+ /* The landscape image (clip-path drives the reveal) */
+ #zoom-img{width:100%;height:100%;clip-path:inset(30% round 16px);will-change:clip-path}
+ #zoom-img svg{width:100%;height:100%}
+ /* Caption overlay */
+ #caption{position:absolute;inset:0;display:flex;flex-direction:column;align-items:center;justify-content:flex-end;padding-bottom:40px;opacity:0;pointer-events:none;background:linear-gradient(transparent 60%,rgba(0,0,0,.6))}
+ #caption h2{font-size:clamp(18px,3vw,28px);font-weight:bold;letter-spacing:3px;text-transform:uppercase;text-align:center}
+ #caption p{font-size:11px;opacity:.6;margin-top:6px;letter-spacing:2px;text-transform:uppercase}
+ aside{width:clamp(200px,22vw,240px);flex-shrink:0;background:var(--ui-bg);border:1px solid var(--ui-border);border-radius:8px;padding:16px;display:flex;flex-direction:column;gap:10px}
+ .note{font-size:10px;color:var(--ui-muted);line-height:1.6;border-left:2px solid var(--ui-accent);padding-left:8px}
+ .lbl{font-size:10px;text-transform:uppercase;letter-spacing:1px;color:var(--ui-accent)}
+ .kv{display:flex;justify-content:space-between;font-size:10px;color:var(--ui-muted)}
+ .kv .v{color:var(--ui-text)}
+ .div{height:1px;background:var(--ui-border)}
+ .sr{display:flex;align-items:center;gap:6px;font-size:10px}
+ .sr input[type=range]{flex:1;accent-color:var(--ui-accent);min-height:44px}
+ .sv{width:38px;text-align:right;color:var(--ui-text)}
+ .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.rst{background:transparent;border:1px solid var(--ui-border);color:var(--ui-text);font-family:monospace;font-size:10px;padding:14px 8px;border-radius:4px;cursor:pointer;width:100%}
+ @media(hover:hover){button.rst:hover{border-color:var(--ui-accent);color:var(--ui-accent)}}
+ @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}:root{--stage-h:460px}}
+ @media(prefers-reduced-motion:reduce){#zoom-img{clip-path:inset(0% round 0px)!important}#caption{opacity:1!important}}
+ </style>
+</head>
+<body>
+<header>
+ <h1>Zoom Into Image</h1>
+ <p>clip-path: inset() expands from a framed card to full-bleed as you scroll — the portal effect.</p>
+</header>
+<div class="layout">
+ <div class="stage" id="stage">
+ <div class="spacer">Scroll to enter the portal ↓</div>
+ <div id="zoom-section">
+ <div id="zoom-sticky">
+ <div id="zoom-img">
+ <svg viewBox="0 0 800 600" xmlns="http://www.w3.org/2000/svg" preserveAspectRatio="xMidYMid slice">
+ <defs>
+ <linearGradient id="sky-grad" x1="0" y1="0" x2="0" y2="1">
+ <stop offset="0%" stop-color="#060a18"/>
+ <stop offset="45%" stop-color="#0d1f3c"/>
+ <stop offset="100%" stop-color="#1a3050"/>
+ </linearGradient>
+ <linearGradient id="water-grad" x1="0" y1="0" x2="0" y2="1">
+ <stop offset="0%" stop-color="#0e2040"/>
+ <stop offset="100%" stop-color="#06111e"/>
+ </linearGradient>
+ <radialGradient id="moon-glow" cx="50%" cy="50%" r="50%">
+ <stop offset="0%" stop-color="#e8dca0" stop-opacity="0.4"/>
+ <stop offset="100%" stop-color="transparent"/>
+ </radialGradient>
+ </defs>
+ <!-- Sky -->
+ <rect width="800" height="420" fill="url(#sky-grad)"/>
+ <!-- Moon glow -->
+ <circle cx="600" cy="90" r="80" fill="url(#moon-glow)"/>
+ <!-- Moon -->
+ <circle cx="600" cy="90" r="28" fill="#e8dca0" opacity=".92"/>
+ <!-- Stars -->
+ <circle cx="80" cy="40" r="1.2" fill="white" opacity=".9"/>
+ <circle cx="220" cy="70" r="1" fill="white" opacity=".7"/>
+ <circle cx="340" cy="25" r="1.5" fill="white" opacity=".8"/>
+ <circle cx="460" cy="55" r="1" fill="white" opacity=".6"/>
+ <circle cx="150" cy="120" r="1" fill="white" opacity=".5"/>
+ <circle cx="700" cy="40" r="1.2" fill="white" opacity=".8"/>
+ <circle cx="760" cy="130" r="1" fill="white" opacity=".4"/>
+ <circle cx="50" cy="180" r="1" fill="white" opacity=".6"/>
+ <!-- Distant mountains -->
+ <polygon points="0,420 150,260 280,330 420,220 560,300 680,230 800,290 800,420" fill="#0a1a30" opacity=".9"/>
+ <!-- Near mountains -->
+ <polygon points="0,420 80,330 180,360 300,300 420,340 520,290 640,320 750,280 800,310 800,420" fill="#060e1c"/>
+ <!-- Reflection base -->
+ <rect y="420" width="800" height="180" fill="url(#water-grad)"/>
+ <!-- Water shimmer lines -->
+ <line x1="0" y1="440" x2="800" y2="440" stroke="rgba(255,255,255,.04)" stroke-width="1"/>
+ <line x1="0" y1="460" x2="800" y2="460" stroke="rgba(255,255,255,.03)" stroke-width="1"/>
+ <line x1="0" y1="485" x2="800" y2="485" stroke="rgba(255,255,255,.03)" stroke-width="1"/>
+ <!-- Moon reflection -->
+ <ellipse cx="600" cy="470" rx="18" ry="8" fill="#e8dca0" opacity=".25"/>
+ <ellipse cx="600" cy="500" rx="12" ry="4" fill="#e8dca0" opacity=".12"/>
+ </svg>
+ </div>
+ <div id="caption"><h2>Through the Portal</h2><p>Scroll to exit</p></div>
+ <div id="frame"><div class="frame-border" style="inset:28%"></div></div>
+ </div>
+ </div>
+ <div class="spacer">Through the portal ↓</div>
+ </div>
+ <aside>
+ <p class="note">clip-path: inset() starts at ~30% on each side (showing 40% width/height) and collapses to 0. Combined with sticky positioning, it reads as the camera flying INTO the image.</p>
+ <div class="lbl">Zoom progress</div>
+ <div class="kv"><span>Section</span><span class="v" id="zp">0%</span></div>
+ <div class="div"></div>
+ <div><div class="lbl" id="ss-lbl">Start size</div>
+ <div class="sr"><input type="range" id="ss-sl" aria-labelledby="ss-lbl" min="20" max="60" value="30"><span class="sv" id="ss-val">30%</span></div>
+ </div>
+ <div><div class="lbl" id="br-lbl">Border radius start</div>
+ <div class="sr"><input type="range" id="br-sl" aria-labelledby="br-lbl" min="0" max="32" value="16"><span class="sv" id="br-val">16px</span></div>
+ </div>
+ <div class="div"></div>
+ <label class="tog" for="portal-tog"><input type="checkbox" id="portal-tog" checked><span>Portal clip-path mode</span></label>
+ <label class="tog" for="frame-tog"><input type="checkbox" id="frame-tog" checked><span>Show frame</span></label>
+ <div class="div"></div>
+ <button class="rst" id="rst">Reset scroll</button>
+ </aside>
+</div>
+<script>
+ const stage=document.getElementById('stage'),zoomSec=document.getElementById('zoom-section');
+ const zoomImg=document.getElementById('zoom-img'),caption=document.getElementById('caption');
+ const zp=document.getElementById('zp'),frameEl=document.getElementById('frame');
+ const ssSl=document.getElementById('ss-sl'),ssVal=document.getElementById('ss-val');
+ const brSl=document.getElementById('br-sl'),brVal=document.getElementById('br-val');
+ const portalTog=document.getElementById('portal-tog'),frameTog=document.getElementById('frame-tog');
+ let startPct=30,brStart=16,ticking=false;
+ const clamp=(v,a,b)=>Math.min(Math.max(v,a),b),lerp=(a,b,t)=>a+(b-a)*t;
+ const motionOk=!window.matchMedia('(prefers-reduced-motion:reduce)').matches;
+
+ function update(){
+ const st=stage.scrollTop,stageH=stage.clientHeight;
+ const pinStart=zoomSec.offsetTop,budget=zoomSec.offsetHeight-stageH;
+ const p=clamp((st-pinStart)/budget,0,1);
+ zp.textContent=Math.round(p*100)+'%';
+ if(!motionOk){ticking=false;return;}
+ const inset=lerp(startPct,0,p);
+ const radius=lerp(brStart,0,p);
+ if(portalTog.checked){
+ zoomImg.style.clipPath=`inset(${inset.toFixed(2)}% round ${radius.toFixed(1)}px)`;
+ }else{
+ zoomImg.style.clipPath=`inset(${inset.toFixed(2)}%)`;
+ }
+ caption.style.opacity=p>0.88?((p-0.88)/0.12).toFixed(3):'0';
+ ticking=false;
+ }
+
+ stage.addEventListener('scroll',()=>{if(!ticking){requestAnimationFrame(update);ticking=true}},{passive:true});
+ ssSl.addEventListener('input',()=>{startPct=+ssSl.value;ssVal.textContent=startPct+'%';
+ frameEl.querySelector('.frame-border').style.inset=startPct+'%';update()});
+ brSl.addEventListener('input',()=>{brStart=+brSl.value;brVal.textContent=brStart+'px';update()});
+ portalTog.addEventListener('change',update);
+ frameTog.addEventListener('change',()=>{frameEl.style.opacity=frameTog.checked?'1':'0'});
+ document.getElementById('rst').addEventListener('click',()=>{stage.scrollTop=0;update()});
+ update();
+</script>
+</body>
+</html>