The code as it is will not work since we never update the lastScrollTop, here is the working code...
$(function(config){
var lastScrollTop = 0, // setting initial scrolltop as top of page
direction; // direction of scroll 1)up -1)down 0)static
function detectDirection() {
// current scrollTop can't be cached or in the local global scope
var st = window.pageYOffset;
if (st > lastScrollTop) {
// scrolling down
direction = -1;
} else if (st < lastScrollTop ){
// scrolling up
direction = 1;
} else {
// static
direction = 0;
}
// updated lastscrolltop with new current top
lastScrollTop = st;
// return the direction
return direction;
}`
I used 0 as static/ 1 as scrolling up/ -1 as scrolling down
Hope that helps someone.