Created
October 24, 2017 07:39
-
-
Save adeyahya/58f6d1d844a1e5916ad264d53e93c593 to your computer and use it in GitHub Desktop.
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
(function() { | |
let lastScrollTop = 0; | |
let scrollUpEvent = new Event("scrollUp"); | |
let scrollDownEvent = new Event("scrollDown"); | |
document.addEventListener("scroll", function(){ // or window.addEventListener("scroll".... | |
let scrollTop = window.pageYOffset || document.documentElement.scrollTop; | |
if (scrollTop > lastScrollTop){ | |
document.dispatchEvent(scrollDownEvent); | |
} else { | |
document.dispatchEvent(scrollUpEvent); | |
} | |
lastScrollTop = scrollTop; | |
}, false); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment