Created
June 18, 2017 08:32
-
-
Save daltonnyx/619bfad2ba91148506b3b68bd0dcf072 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
var lastScrollTop = 0; | |
// element should be replaced with the actual target element on which you have applied scroll, use window in case of no target element. | |
element.addEventListener("scroll", function(){ // or window.addEventListener("scroll".... | |
var st = window.pageYOffset || document.documentElement.scrollTop; // Credits: "https://github.com/qeremy/so/blob/master/so.dom.js#L426" | |
if (st > lastScrollTop){ | |
// downscroll code | |
} else { | |
// upscroll code | |
} | |
lastScrollTop = st; | |
}, false); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment