Skip to content

Commit

Permalink
Resolved Scroll indicator bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Sourabh782 committed Aug 10, 2024
1 parent 4f77755 commit 3d96617
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1187,7 +1187,7 @@
<!-- Your custom JavaScript -->
<script src="script.js"></script>
<div class="nav-wrapper">
<div class="progress-bar"></div>
<div class="progress-bar" id="progress-bar"></div>
</div>

<div class="socialmediaicons" style="z-index: 99;" >
Expand Down
9 changes: 6 additions & 3 deletions scrollbar.css
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
.nav-wrapper{
position: sticky;
position: fixed;
top: 0;
background-color: var(--seashell);
z-index: 1;
background-color: transparent;
height: 5px;
width: 100%;
z-index: 1002;
}
.progress-bar{
height: 5px;
width: 0;
background-color: red;
z-index: 1002;
}
25 changes: 19 additions & 6 deletions scrollbar.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
let progressBar = document.querySelector(".progress-bar");
let documentHeight = document.documentElement.scrollHeight - document.documentElement.clientHeight;
// let progressBar = document.querySelector(".progress-bar");
// let documentHeight = document.documentElement.scrollHeight - document.documentElement.clientHeight;

window.onscroll = function(){
let progress = (scrollY / documentHeight) * 100;
progressBar.style.width = progress + "%";
}
// 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 + '%';
}

0 comments on commit 3d96617

Please sign in to comment.