Skip to content

Instantly share code, notes, and snippets.

@wwwebman
Last active January 26, 2017 14:40
Show Gist options
  • Save wwwebman/c382d6d2be866ad0fcab93c16ec24256 to your computer and use it in GitHub Desktop.
Save wwwebman/c382d6d2be866ad0fcab93c16ec24256 to your computer and use it in GitHub Desktop.
How you can simple determine the direction of a jQuery scroll event
var scrollDirectionPrevValue = 0;
// Function return:
// true - scroll bottom
// false - scroll top
function scrollDirectionToBottom(scrollTop){
var directionToBottom = false;
if( scrollDirectionPrevValue < scrollTop ) directionToBottom = true;
scrollDirectionPrevValue = scrollTop;
return directionToBottom;
}
// Addhandler to scroll Events width our func
$(window).on("scroll", function(){
var scrollTop = $(window).scrollTop();
console.log( scrollDirectionToBottom(scrollTop) );
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment