1var lastScrollTop = 0;
2
3// element should be replaced with the actual target element on which you have applied scroll, use window in case of no target element.
4element.addEventListener("scroll", function(){ // or window.addEventListener("scroll"....
5 var st = window.pageYOffset || document.documentElement.scrollTop; // Credits: "https://github.com/qeremy/so/blob/master/so.dom.js#L426"
6 if (st > lastScrollTop){
7 // downscroll code
8 } else {
9 // upscroll code
10 }
11 lastScrollTop = st <= 0 ? 0 : st; // For Mobile or negative scrolling
12}, false);
13