Thursday, 15 August 2013

Detect Scroll Position (Up/Down) using jQuery

Introduction:

Below jQuery code detects whether user is scrolling up or down in the webpage.

Example:


var iScrollPos = 0;

$(window).scroll(function () {
    var iCurScrollPos = $(this).scrollTop();
    if (iCurScrollPos > iScrollPos) {
        //Scrolling Down
    } else {
       //Scrolling Up
    }
    iScrollPos = iCurScrollPos;
});

No comments:

Post a Comment