Created
December 3, 2023 19:15
-
-
Save mattkenefick/3f1ead9b87bf9f5db95ebed6f8dee68f to your computer and use it in GitHub Desktop.
Get normalized value of scroll amount of window
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
document.addEventListener('scroll', (e) => { | |
const documentHeight = document.documentElement.scrollHeight; | |
const windowHeight = window.innerHeight; | |
const scrollDistance = window.scrollY; | |
const ratio = scrollDistance / (documentHeight - windowHeight); | |
console.log(ratio); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment