added scroll progress bar in single page template

This commit is contained in:
gurusabarish
2023-02-12 00:41:29 +05:30
parent edde3e1123
commit 2e8daeaa0d
4 changed files with 43 additions and 0 deletions
+12
View File
@@ -0,0 +1,12 @@
function getScrollPercent() {
const totalHeight = document.body.scrollHeight - window.innerHeight;
const scrolled = window.scrollY;
return (scrolled / totalHeight) * 100;
}
const scrollProgressBar = document.getElementById("scroll-progress-bar");
document.onscroll = function () {
var scrollPercent = Math.round(getScrollPercent());
scrollProgressBar.style.width = scrollPercent + "%";
scrollProgressBar.ariaValueNow = scrollPercent;
};