10

The following works in Chrome / FF etc...

$('body').animate({scrollTop : 0}, 0);

However, in IE 7, it doesn't do anything.
Is there an alternative?

Alex
  • 37,502
  • 51
  • 204
  • 332

4 Answers4

21

EDIT As pointed out by many, it is better to use:

$('body, html').animate({scrollTop : 0}, 0);
Fiona - myaccessible.website
  • 14,481
  • 16
  • 82
  • 117
17
$('body, html').animate({scrollTop : 0}, 0);
benastan
  • 2,268
  • 15
  • 14
4

in IE8, i use $(document).scrollTop() to get the scrollTop property, $('body').scrollTop() or $('html').scrollTop() will always return 0.

Maybe you can use

$(document).animate({scrollTop: 0}, 0);
$('html,body').animate({scrollTop: 0}, 0);

to make it works on all browser.

hellosmithy
  • 279
  • 1
  • 9
YuC
  • 1,787
  • 3
  • 19
  • 22
2

Set:

# FF、IE8        
document.documentElement.scrollTop = 100;

# chrome
document.body.scrollTop = 100;

Get:

scrollTop = document.documentElement.scrollTop + document.body.scrollTop;
Suyi
  • 41
  • 4