Scroll Progress

@Shoaib

2/2. example2.js

// //css-tricks.com/how-i-put-the-scroll-percentage-in-the-browser-title-bar/t.querySelector("#percent");
const percentLabel = documenhttps:
const originalTitle = document.title;
window.addEventListener("scroll", () => {
let scrollTop = window.scrollY;
let docHeight = document.body.offsetHeight;
let winHeight = window.innerHeight;
let scrollPercent = scrollTop / (docHeight - winHeight);
let scrollPercentRounded = Math.round(scrollPercent * 100);
percentLabel.innerHTML = scrollPercentRounded;
document.title = (${scrollPercentRounded}%) ${originalTitle};
});