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: Progress Bar shows a map of the whole article with a frame for the box and a bracket for the distance scrolled (See inside) and the article with no indicator above the same article with one (Compare)

Claude27f8b594dc6f
diff --git a/animations/01-scroll-based/progress-bar/index.html b/animations/01-scroll-based/progress-bar/index.html
index 81deacc5..414d2a3b 100644
--- a/animations/01-scroll-based/progress-bar/index.html
+++ b/animations/01-scroll-based/progress-bar/index.html
@@ -48,6 +48,48 @@
.art-body{font-size:15px;line-height:1.8;color:#adadb2;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;color:#d6d6da}
.art-h2{font-size:clamp(16px,2vw,20px);font-weight:700;margin:28px 0 12px}
+ /* See inside and Compare draw in one layer of the stage, outside the scroller and above it, so nothing scrolls away; it ignores the pointer */
+ .fx,.fx-in,.fx-cmp{display:none;position:absolute;inset:0}
+ .fx{z-index:6;overflow:hidden;pointer-events:none}
+ .stage[data-hb-mode="inside"] .fx,.stage[data-hb-mode="compare"] .fx,.stage[data-hb-mode="inside"] .fx-in,.stage[data-hb-mode="compare"] .fx-cmp{display:block}
+ .cap{position:absolute;padding:2px 7px;border-radius:999px;white-space:nowrap;background:rgba(11,11,13,.95);color:#f4f4f2;
+ border:1px solid rgba(244,244,242,.3);font:600 13px/1.3 var(--hb-font)}
+ /* See inside: a map of the whole article (its blocks drawn from measured offsets) with a frame the height of the box sliding
+ down it, a faint dashed frame where it started (the slide is shrunk: ruling 2), and a bracket as long as the frame can
+ travel, filled in the indicator's color as far as it has gone. The map sits below the ring and left of the rail. */
+ .stage[data-hb-mode="inside"] .scroller{opacity:.4}
+ .mwrap{position:absolute;right:16px;top:var(--mt,38px);bottom:14px;width:78px}
+ @media(min-width:601px){.mwrap{width:90px}}
+ .map{position:absolute;inset:0;background:rgba(11,11,13,.95);box-shadow:0 0 0 1px rgba(244,244,242,.25)}
+ .mb{position:absolute;left:5px;right:5px;margin-top:1px;background:#6f6f78}
+ .mb.hd{background:#f4f4f2;right:30%}
+ .mb.by{right:55%}
+ .mb.qt{background:var(--bar-color);right:25%}
+ .mframe,.mstart{position:absolute;left:0;right:0;top:0}
+ .mframe{border:3px solid #fff;background:rgba(255,255,255,.14);box-shadow:0 0 0 1px #0b0b0d}
+ .mstart{border:2px dashed rgba(244,244,242,.7)}
+ .mframe .cap{top:50%;left:50%;translate:-50% -50%;padding:1px 4px}
+ .brk{position:absolute;right:calc(100% + 8px);top:0;width:12px;border-left:2px solid rgba(244,244,242,.6)}
+ .brk::before,.brk::after{content:"";position:absolute;left:-2px;width:12px;height:2px;background:rgba(244,244,242,.6)}
+ .brk::after{bottom:0}
+ .brk i{position:absolute;left:3px;top:0;bottom:0;width:var(--bar-thick);background:var(--bar-color);transform-origin:top;transform:scaleY(0)}
+ .cap-map{right:0;bottom:calc(100% + 6px)}
+ .cap-sc,.cap-far{right:calc(100% + 28px)}
+ .cap-sc{top:0}
+ .cap-far{translate:0 -100%}
+ /* Compare: the article twice, stacked (side by side it would wrap taller and change the scroll). Both halves are copies
+ moved by how far the one real scroll has gone, from the title to the last line, so they always show the same lines;
+ the real scroller stays under them for input. The indicator moves into the lower half. */
+ .half{position:absolute;left:0;right:0;overflow:hidden;background:#0b0b0d}
+ .h1{top:0;height:calc(50% - 1px)}
+ .h2{bottom:0;height:calc(50% - 1px)}
+ .half .cap{top:4px;left:10px}
+ /* each half has a name band on top, and the article moves in the window under it, so the name never covers a line */
+ .win{position:absolute;left:0;right:0;top:28px;bottom:0;overflow:hidden;border-top:1px solid rgba(244,244,242,.14)}
+ .split{position:absolute;left:0;right:0;top:calc(50% - 1px);height:2px;background:rgba(244,244,242,.5)}
+ .stage[data-hb-mode="compare"] #top-bar,.stage[data-hb-mode="compare"] #side-rail{top:calc(50% + 1px)}
+ .stage[data-hb-mode="compare"] #circ{top:calc(50% + 9px)}
+ .stage[data-hb-mode="compare"] .scroller:focus-visible+.fx::after{content:"";position:absolute;inset:0;outline:2px solid var(--ui-accent);outline-offset:-2px}
</style>
<link rel="stylesheet" href="../../../assets/css/demo-page.css?v=10">
<script src="../../../assets/js/demo-page.js?v=10" defer></script>
@@ -70,6 +112,11 @@
<span class="hb-num" aria-hidden="true">1</span>
<div><h2 id="hb-watch-title">Scroll it</h2><p>Scroll inside the box, or press Play and it scrolls for you.</p></div>
</div>
+ <div class="seg hb-modes" role="group" aria-label="What the box shows" data-hb-modes>
+ <button type="button" data-hb-mode="normal" class="on" aria-pressed="true">Normal</button>
+ <button type="button" data-hb-mode="inside" aria-pressed="false">See inside</button>
+ <button type="button" data-hb-mode="compare" aria-pressed="false">Compare</button>
+ </div>
<div class="stage">
<div id="top-bar" aria-hidden="true"></div>
<div id="side-rail" aria-hidden="true"><div id="side-fill"></div></div>
@@ -94,11 +141,31 @@
<p class="art-body">Whatever it looks like, the indicator should move with the scroll and never make the page stutter, especially on phones.</p>
</div>
</div>
+ <div class="fx" inert aria-hidden="true">
+ <div class="fx-in">
+ <div class="mwrap">
+ <div class="map"><i class="mstart"></i><i class="mframe"><span class="cap" data-hb-caption>In the box</span></i></div>
+ <div class="brk"><i></i></div>
+ <p class="cap cap-map" data-hb-caption>Whole article</p>
+ <p class="cap cap-sc" data-hb-caption>Scrolled</p>
+ <p class="cap cap-far" data-hb-caption>How far it can scroll</p>
+ </div>
+ </div>
+ <div class="fx-cmp">
+ <div class="half h1"><p class="cap" data-hb-caption>No indicator</p></div>
+ <div class="half h2"><p class="cap" data-hb-caption>With a bar</p></div>
+ <i class="split"></i>
+ </div>
+ </div>
</div>
<div class="hb-player">
<button class="hb-play" type="button" id="btn-scroll" data-hb-autoscroll><svg class="hb-ic" viewBox="0 0 24 24" aria-hidden="true"><path d="M12 5v14M19 12l-7 7-7-7"/></svg>Play</button>
<button class="hb-play" type="button" id="btn-top" data-hb-top><svg class="hb-ic" viewBox="0 0 24 24" aria-hidden="true"><path d="M12 19V5M5 12l7-7 7 7"/></svg>Back to top</button>
</div>
+ <div class="hb-mode-notes" aria-live="polite">
+ <p data-hb-for="inside" hidden>Inside, the strip is the whole article and the frame is the box; the fill is the distance scrolled out of the distance it can scroll. Scroll the box or press Play to watch.</p>
+ <p data-hb-for="compare" hidden>No indicator gives no sign of how much is left; With a bar fills as the same text scrolls, full when the last line shows. Scroll the box or press Play to watch.</p>
+ </div>
</section>
<section class="hb-step hb-try" aria-labelledby="hb-try-title">
@@ -190,6 +257,9 @@
let ticking=false,shown=-1;
function setStyle(s){
+ stage.style.setProperty('--mt',s==='circ'?'86px':'38px'); // See inside: the map sits below the ring
+ capName.textContent=NAMES[s];
+ compareNote.textContent=NOTE.replace(NAMES.top,NAMES[s]);
topBar.style.display=s==='top'?'block':'none';
circ.style.display=s==='circ'?'block':'none';
rail.style.display=s==='rail'?'block':'none';
@@ -206,12 +276,66 @@
sideFill.style.transform=`scaleY(${p})`;
circFg.style.strokeDashoffset=CIRC-(p*CIRC);
circTxt.textContent=Math.round(p*100)+'%';
+ if(mode==='inside'){
+ // the frame slides down the map as far as the box has scrolled, and the bracket fills the same share
+ mframe.style.transform=`translateY(${Math.round(p*travel)}px)`;
+ brkFill.style.transform=`scaleY(${p})`;
+ capSc.hidden=p*travel<24; // "Scrolled" shows once the filled part is taller than its label
+ }else if(mode==='compare'){
+ // both copies show the article from its title (share 0) to its last line (share 1), so the halves always match
+ const off=-Math.round(p*Math.max(0,contentH-halfH));
+ copies.forEach(c=>{c.style.transform=`translate3d(0,${off}px,0)`});
+ }
}
+ // ── See inside and Compare ──
+ const stage=document.querySelector('.stage'),fx=stage.querySelector('.fx');
+ const mwrap=fx.querySelector('.mwrap'),map=fx.querySelector('.map'),mframe=fx.querySelector('.mframe'),mstart=fx.querySelector('.mstart');
+ const brk=fx.querySelector('.brk'),brkFill=brk.firstElementChild,capSc=fx.querySelector('.cap-sc'),capFar=fx.querySelector('.cap-far');
+ const halves=[...fx.querySelectorAll('.half')],capName=halves[1].querySelector('.cap');
+ const compareNote=document.querySelector('[data-hb-for="compare"]'),NOTE=compareNote.textContent;
+ const NAMES={top:'With a bar',circ:'With a ring',rail:'With a rail'};
+ const LABELS={
+ normal:'An article with a reading progress indicator',
+ inside:'The article with a map of the whole text, the part in the box framed, and how far it has scrolled out of how far it can',
+ compare:'The article twice, one above the other: with no indicator, and with the reading progress indicator'
+ };
+ // Compare's copies are made once: inert, hidden from screen readers and without ids (the article has none)
+ const article=scroller.querySelector('.article');
+ const wins=halves.map(h=>{const w=document.createElement('div'),c=document.createElement('div');w.className='win';c.append(article.cloneNode(true));w.append(c);h.append(w);return w});
+ const copies=wins.map(w=>w.firstChild);
+ // the map's blocks: one per part of the article
+ const blocks=[...article.children].map(el=>{
+ const b=document.createElement('i');
+ b.className='mb '+(el.matches('.art-title,.art-h2')?'hd':el.matches('.art-byline')?'by':el.matches('.art-pull')?'qt':'');
+ map.prepend(b);return [el,b];
+ });
+ let mode='normal',contentH=0,boxH=0,halfH=0,travel=0;
+
+ // Measured at load, on resize, when the font arrives and when the mode or the indicator changes: never once per scroll frame
+ function measure(){
+ shown=-1;
+ if(mode==='normal')return;
+ contentH=scroller.scrollHeight;boxH=scroller.clientHeight;
+ if(mode==='inside'){
+ const r=boxH/contentH,pct=(r*100)+'%';
+ travel=mwrap.clientHeight*(1-r);
+ mframe.style.height=mstart.style.height=pct;
+ brk.style.height=capFar.style.top=((1-r)*100)+'%';
+ blocks.forEach(([el,b])=>{b.style.top=(el.offsetTop/contentH*100)+'%';b.style.height=`calc(${el.offsetHeight/contentH*100}% - 1px)`});
+ }else halfH=wins[0].clientHeight;
+ }
+
+ document.addEventListener('hb:mode',e=>{
+ mode=e.detail.mode;
+ scroller.setAttribute('aria-label',LABELS[mode]);
+ measure();update();
+ });
+
scroller.addEventListener('scroll',()=>{if(!ticking){requestAnimationFrame(update);ticking=true}},{passive:true});
// The range depends on the box and the text: measure again when the box changes size or the site font arrives.
- addEventListener('resize',()=>{shown=-1;update()});
- if(document.fonts&&document.fonts.ready)document.fonts.ready.then(()=>{shown=-1;update()});
+ addEventListener('resize',()=>{measure();update()});
+ if(document.fonts&&document.fonts.ready)document.fonts.ready.then(()=>{measure();update()});
function choices(id,pick){
const buttons=document.querySelectorAll('#'+id+' button');
@@ -220,7 +344,7 @@
pick(b.dataset);
}));
}
- choices('style-seg',d=>setStyle(d.s));
+ choices('style-seg',d=>{setStyle(d.s);measure();update()});
choices('thick-seg',d=>vars.setProperty('--bar-thick',d.px+'px'));
choices('color-sw',d=>vars.setProperty('--bar-color',d.c));
setStyle('top');update();