-
Notifications
You must be signed in to change notification settings - Fork 769
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2844 from Sourabh782/scroll
Resolved Scroll indicator bug
- Loading branch information
Showing
3 changed files
with
26 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 + '%'; | ||
} |