Skip to content

Create a dynamic Reading Progress Bar with HTML, CSS, and JavaScript to visually track reading progress on web pages.

Notifications You must be signed in to change notification settings

Shahriyar-Hosen/progress-bar-page-topside-animation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

84 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Reading Progress Bar Animation
with
HTML CSS JavaScript

JavaScript

// progressBar main div
const progressBar = document.querySelector("#progress-bar");
//Whichever div will work based
const mainBlogSection = document.querySelector("main");

const animateProgressBar = () => {
  let scrollDistance = -mainBlogSection.getBoundingClientRect().top;
  let progressWidth =
    (scrollDistance /
      (mainBlogSection.getBoundingClientRect().height -
        document.documentElement.clientHeight)) *
    100;
  let value = Math.floor(progressWidth);
  progressBar.style.width = value + "%";

  if (value < 0) {
    progressBar.style.width = "0%";
  }
};

window.addEventListener("scroll", animateProgressBar);

Video Preview

Reading.Progress.Bar.Animation.with.HTML.CSS.JavaScript.mp4

About

Create a dynamic Reading Progress Bar with HTML, CSS, and JavaScript to visually track reading progress on web pages.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages