field notes · 2 min read
Reading progress, measured
A reading progress bar answers one question: how much is left? It fills as you move down the page, and it moves only when you do.
The number behind it is how far the page has scrolled, divided by how far it can scroll. At the top that is 0; at the very bottom it is 1.
Scale the bar with a transform instead of changing its width. A transform never makes the browser lay the page out again, so long pages stay smooth.
On a blog the page is more than the post: a header above it, comments and links below. Follow the article instead, and the bar is full when the last paragraph is on screen.
Where the browser has scroll-driven animations, CSS can do all of it with animation-timeline. Everywhere else, scrollProgress writes the same number into a CSS variable.
Keep it thin and out of the way, and hide it from screen readers: it repeats what the scrollbar already says.
That is the whole trick. Scroll back up and it empties again.