forked from anuragverma108/SwapReads
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscrollbar.js
More file actions
20 lines (13 loc) · 686 Bytes
/
scrollbar.js
File metadata and controls
20 lines (13 loc) · 686 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// let progressBar = document.querySelector(".progress-bar");
// let documentHeight = document.documentElement.scrollHeight - document.documentElement.clientHeight;
// window.onscroll = function(){
// let progress = Math.floor((scrollY / documentHeight) * 100);
// progressBar.style.width = progress + "%";
// }
window.addEventListener('scroll', moveScrollIndicator);
const scrollIndicatorElt = document.getElementById('progress-bar');
const maxHeight = window.document.body.scrollHeight - window.innerHeight;
function moveScrollIndicator(e) {
const percentage = Math.floor(((window.scrollY) / maxHeight) * 100);
scrollIndicatorElt.style.width = percentage + '%';
}