How to Build a Reading Progress Bar with CSS and JavaScript

You may have noticed blogs which display a “reading progress indicator” (or progress bar) to let readers know how far through the content they’ve read, and how much content remains.
These indicators usually sit at the top of the page, and as you scrol…


This content originally appeared on Envato Tuts+ Tutorials and was authored by Adi Purdila

You may have noticed blogs which display a “reading progress indicator” (or progress bar) to let readers know how far through the content they’ve read, and how much content remains.

These indicators usually sit at the top of the page, and as you scroll down they get wider and wider until they fill the whole width. Progress bars like these are actually quite easy to implement with JavaScript; in this tutorial that’s exactly what we’re going to do!

Reading Progress Indicator

What We’ll Cover in this Tutorial

We’re going to use a JavaScript event listener to detect when the page is being scrolled. We’ll then calculate how far down the page the viewport window is. Once we have that percentage value, we’ll update a CSS variable (custom property) which styles the progress bar to display it at a certain width.

The following timestamps mark useful sections of the tutorial which you may want to revisit later on.

Our Progress Bar Demo

This is the reading progress bar you’ll create by following this tutorial:

 

Premium JavaScript Scripts and Plugins 

Explore the thousands of JavaScript plugins and templates on CodeCanyon. Purchase these high-quality JavaScript files and improve your website experience for you and your visitors. 

javascript plugins on CodeCanyon.

You’ve Built a Reading Progress Bar!

If you followed along you should now have a great little addition to your website, built with a bit of JavaScript and some CSS. And now you know what’s possible using the style.setProperty() method why not see what else you can change?

jQuery Progress Indicator

If you enjoyed this tutorial and want to build something similar, but you prefer to use jQuery, Jonathan Cutrell created exactly what you need–take a look!


This content originally appeared on Envato Tuts+ Tutorials and was authored by Adi Purdila


Print Share Comment Cite Upload Translate Updates
APA

Adi Purdila | Sciencx (2021-03-29T14:48:13+00:00) How to Build a Reading Progress Bar with CSS and JavaScript. Retrieved from https://www.scien.cx/2021/03/29/how-to-build-a-reading-progress-bar-with-css-and-javascript/

MLA
" » How to Build a Reading Progress Bar with CSS and JavaScript." Adi Purdila | Sciencx - Monday March 29, 2021, https://www.scien.cx/2021/03/29/how-to-build-a-reading-progress-bar-with-css-and-javascript/
HARVARD
Adi Purdila | Sciencx Monday March 29, 2021 » How to Build a Reading Progress Bar with CSS and JavaScript., viewed ,<https://www.scien.cx/2021/03/29/how-to-build-a-reading-progress-bar-with-css-and-javascript/>
VANCOUVER
Adi Purdila | Sciencx - » How to Build a Reading Progress Bar with CSS and JavaScript. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/03/29/how-to-build-a-reading-progress-bar-with-css-and-javascript/
CHICAGO
" » How to Build a Reading Progress Bar with CSS and JavaScript." Adi Purdila | Sciencx - Accessed . https://www.scien.cx/2021/03/29/how-to-build-a-reading-progress-bar-with-css-and-javascript/
IEEE
" » How to Build a Reading Progress Bar with CSS and JavaScript." Adi Purdila | Sciencx [Online]. Available: https://www.scien.cx/2021/03/29/how-to-build-a-reading-progress-bar-with-css-and-javascript/. [Accessed: ]
rf:citation
» How to Build a Reading Progress Bar with CSS and JavaScript | Adi Purdila | Sciencx | https://www.scien.cx/2021/03/29/how-to-build-a-reading-progress-bar-with-css-and-javascript/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.