Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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'
    });
like image 343
android.nick Avatar asked Feb 03 '11 06:02

android.nick


3 Answers

Just change:

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

To this:

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

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

like image 200
David Tang Avatar answered Nov 06 '22 08:11

David Tang


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

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

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

scrollTop: $(window).scrollTop() + 100
like image 42
Gaurang Avatar answered Nov 06 '22 06:11

Gaurang


Check out the jQuery.ScrollTo plugin. You can do something like: $(...).scrollTo( '+=100px', 800 );

Check out the sample for everything this plugin can do: http://demos.flesler.com/jquery/scrollTo/

like image 1
ajma Avatar answered Nov 06 '22 07:11

ajma