From this question on - How can I determine the direction of a jQuery scroll event?, I wrote this code.
var lastS=$(window).scrollTop();
function whatHappened()
{
var currentS=$(window).scrollTop();
console.log(lastS,currentS);
if(currentS>lastS)
{
lastS = currentS;
return "Scroll down";
}
else
{
lastS = currentS;
return "Scroll up";
}
}
$(window).on("mousewheel",function(){
console.log(whatHappened());
});
This seems to work fine but there is a small problem. If I scroll down more than two times and then scroll up it first shows scroll down then scroll up. Similar happens in vice-versa. What's wrong? Please help. Thanks in advance.
JS Fiddle: http://jsfiddle.net/3843e/