Skip to content

Instantly share code, notes, and snippets.

@BroFox86
Last active May 28, 2024 18:25
Show Gist options
  • Save BroFox86/6d0017553fee190fe5d40b0df24249ce to your computer and use it in GitHub Desktop.
Save BroFox86/6d0017553fee190fe5d40b0df24249ce to your computer and use it in GitHub Desktop.
[Detect scroll direction] #jsTrick
let lastScrollY = scrollY || 0;
window.addEventListener("scroll", () => {
if (scrollY > lastScrollY) {
console.log("down scroll");
} else if (scrollY < lastScrollY) {
console.log("up scroll");
}
lastScrollY = scrollY;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment