;Jquery: animate page down 100px from current screen position

android.nick picture android.nick · Feb 3, 2011 · Viewed 78.2k times · Source

I need to animate a scroll from the current screen position, down a set number of pixels.

    $('html,body').animate({
        scrollTop: $(window).position().top += 100
    });

or?

    $('html,body').animate({
        scrollTop: '+=100px'
    });

Answer

David Tang picture David Tang · Feb 3, 2011

Just change:

scrollTop: $('body').position().top += 100

To this:

scrollTop: $(window).scrollTop() + 100

See demo: http://jsfiddle.net/fpxuC/