Skip to content

Instantly share code, notes, and snippets.

@daltonnyx
Created June 18, 2017 08:32
Show Gist options
  • Save daltonnyx/619bfad2ba91148506b3b68bd0dcf072 to your computer and use it in GitHub Desktop.
Save daltonnyx/619bfad2ba91148506b3b68bd0dcf072 to your computer and use it in GitHub Desktop.
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