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.…