detect scroll up and down using javascript
<pre><code>&lt;script type="text/javascript"&gt;
function scrollFunc(e) {
userScroll=true;
    if ( typeof scrollFunc.x == 'undefined' ) {
        scrollFunc.x=window.pageXOffset;
        scrollFunc.y=window.pageYOffset;
    }
    var diffX=scrollFunc.x-window.pageXOffset;
    var diffY=scrollFunc.y-window.pageYOffset;
if(userScroll)
{
if( diffY&lt;0 ) {
         $(".myCar").animate({"top": "+=50px"},1000);// Scroll down
        alert('down');
        //$(".myCar").stop();
    } else if( diffY&gt;0 ) {
        $(".myCar").animate({"top": "-=50px"},1000);

        alert('Up');// Scroll up
    } else {
        // First scroll event
    }
    userScroll=false;
}
else
{

}
    scrollFunc.x=window.pageXOffset;
    scrollFunc.y=window.pageYOffset;
}
window.onscroll=scrollFunc
&lt;/script&gt;
</code></pre>

<p>I'm trying to detect, scrolling up and down, but, it showing alert msg for both, i mean, if i'm scrolling down or up, it is showing both alert msg. Need Help.!!</p>
