Last active
January 26, 2017 14:40
-
-
Save wwwebman/c382d6d2be866ad0fcab93c16ec24256 to your computer and use it in GitHub Desktop.
How you can simple determine the direction of a jQuery scroll event
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 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