website/static/js/scrollProgressBar.js

13 lines
450 B
JavaScript
Raw Normal View History

2023-06-13 20:13:00 +02:00
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;
};