Menu

Stop Listening to scroll for Progress Bars. CSS Scroll Timelines Are Baseline
📰

Stop Listening to scroll for Progress Bars. CSS Scroll Timelines Are Baseline

DEV Community: css·JKC·11 days ago
#KstFT4kk
#devtocss#devto#dev#scroll#animation
Reading 0:00
15s threshold

TL;DR: animation-timeline: scroll() and view() drive a normal CSS animation with scroll position instead of time. Firefox 159 turned them on by default on October 27, 2026, so scroll-driven animations are now Baseline Newly available.

The listener everyone has written

You want a reading progress bar. A thin line at the top that fills as the reader scrolls. So you write this:

const bar = document . querySelector ( " .progress " );

window . addEventListener ( " scroll " , () => { const max = document . documentElement . scrollHeight - innerHeight ; bar . style . transform = `scaleX( ${ scrollY / max } )` ; }, { passive : true });

Enter fullscreen mode

Exit fullscreen mode

Then someone resizes the window, and you add a resize listener. Then the bar stutters on a busy page, and you add requestAnimationFrame . Then a fade-in effect on cards shows up in the design, and you add an IntersectionObserver with ten thresholds. It works.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.