Skip to content

Instantly share code, notes, and snippets.

@adeyahya
Created October 24, 2017 07:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adeyahya/58f6d1d844a1e5916ad264d53e93c593 to your computer and use it in GitHub Desktop.
Save adeyahya/58f6d1d844a1e5916ad264d53e93c593 to your computer and use it in GitHub Desktop.
(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