Last active
May 28, 2024 18:25
-
-
Save BroFox86/6d0017553fee190fe5d40b0df24249ce to your computer and use it in GitHub Desktop.
[Detect scroll direction] #jsTrick
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
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