Skip to content

Instantly share code, notes, and snippets.

@mattkenefick
Created December 3, 2023 19:15
Show Gist options
  • Save mattkenefick/3f1ead9b87bf9f5db95ebed6f8dee68f to your computer and use it in GitHub Desktop.
Save mattkenefick/3f1ead9b87bf9f5db95ebed6f8dee68f to your computer and use it in GitHub Desktop.
Get normalized value of scroll amount of window
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