Skip to content

Instantly share code, notes, and snippets.

@ealmloff
Created September 14, 2023 22:36
Show Gist options
  • Save ealmloff/7797f6abfb57167cf99c564f6cd256ca to your computer and use it in GitHub Desktop.
Save ealmloff/7797f6abfb57167cf99c564f6cd256ca to your computer and use it in GitHub Desktop.
window.addEventListener('scroll', () => {
let scrollTop = window.scrollY;
let winHeight = window.document.documentElement.scrollHeight - window.document.documentElement.clientHeight;
let new_scroll = Math.min(Math.max(scrollTop, 0) / Math.max(winHeight, 1), 1);
document.body.style.setProperty('--scroll', new_scroll);
}, false);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment