30

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'
    });
Kundan roy
  • 3,082
  • 3
  • 18
  • 22
android.nick
  • 11,069
  • 23
  • 77
  • 112
  • then use that point as a selector from where you want to down the window position not html,body – Vivek Feb 03 '11 at 07:00

3 Answers3

55

Just change:

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

To this:

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

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

David Tang
  • 92,262
  • 30
  • 167
  • 149
  • i am not able to replicate this example, could you pleas provide an example in which i could start the animation with a click event – Anurag-Sharma Oct 24 '14 at 14:55
2
$('html,body').animate({
        scrollTop: $(window).position().top += 100
    })

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

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

scrollTop: $(window).scrollTop() + 100
Gaurang
  • 1,928
  • 18
  • 12
1

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/

ajma
  • 12,106
  • 12
  • 71
  • 90