LATEST >>

Welcome Here And Thanks For Visiting. Like Us On Facebook...

EXEIdeas – Let's Your Mind Rock » HTML-CSS-PHP-JavaScript / JavaScript Codes » Add A Simple Page Scroll Reader Indicator With Pure Vanilla JavaScript

Add A Simple Page Scroll Reader Indicator With Pure Vanilla JavaScript

Add-A-Simple-Page-Scroll-Reader-Indicator-With-Pure-Vanilla-JavaScript
Reading progress indicators are generally used in long-form articles. They provide a visual clue for readers indicating how far they are from the end of an article. In this tutorial we’ll be creating a reading progress indicator that looks and functions like the following:

Adding a progress bar to the top of the page is a simple way of showing the user how far down the page they have read. There is a scroll bar on the right hand side of the page on my current device, but that isn’t always present on all devices. It is possible to hide the scroll bar on Macs and mobile devices so that they are only shown as the page is being scrolled.

There are many code snippets available online or on many other blogs and websites, but everyone cannot optimize your blog or website, so you need some optimized code snippets. So now checkout out the code snippet for your blog and website that will give you all features for your desired code. Now grab the ready-to-use code and paste it where you want.

Table of Contents

Features:

  1. Light Weight.
  2. Pure JavaScript.
  3. Cross Browser.
  4. No JQuery Files.
  5. Fully Customizable.
  6. Responsive.

How To Add A Simple Page Scroll Reader Indicator With Pure Vanilla JavaScript?

There are a few easy and understandable steps to achieve your desired functionality that we are gonna share below. Follow each step perfectly.

CSS:

<style type="text/css">
#progress-bar {
position: fixed;
top: 0;
left: 0;
width: 0;
height: 20px;
z-index: 99;
background-color: #b22222;
transition: width 1s;
}
</style>

HTML:

<div id="progress-bar"></div>

JavaScript:

<script type="text/javascript">
const progressBar = document.getElementById("progress-bar");
const setProgressBar = () => {
let scrollDist = document.documentElement.scrollTop || document.body.scrollTop;
let progressWidth = (scrollDist / (document.body.scrollHeight - document.documentElement.clientHeight)) * 100;
progressBar.style.width = progressWidth + "%";
};
if (progressBar) {
window.addEventListener("scroll", setProgressBar); 
}
</script>

Customization:

No need to customize it. Just copy-paste. Rest edit the code as per comments and need.

Troubleshooting the Errors:

Do it with concentration and patience. Check your all steps again and all codes or scripts. If you find any error you can contact us anytime via comment or better via email, We are always here to help you.

Final Words:

That’s all we have. We hope that you liked this article. If you have any problem with this code in your template then feel free to contact us with a full explanation of your problem. We will reply to you as time allows us If you have any doubts or problems please comment below. We are happy to help you! If you liked this article, Don’t forget to share this with your friends so they can also take benefit from it and leave.

Recommended For You:
Get All Resources Like href And src From A WebPage Using PHP

You Like It, Please Share This Recipe With Your Friends Using...

Be the first to write a comment.

Leave a Reply

Your email address will not be published. Required fields are marked *