Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery animate scrollTop not working in IE 7

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?

like image 538
Alex Avatar asked May 09 '12 15:05

Alex


3 Answers

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

$('body, html').animate({scrollTop : 0}, 0);
like image 113
Fiona - myaccessible.website Avatar answered Nov 14 '22 10:11

Fiona - myaccessible.website


$('body, html').animate({scrollTop : 0}, 0);
like image 45
benastan Avatar answered Nov 14 '22 10:11

benastan


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.

like image 34
YuC Avatar answered Nov 14 '22 11:11

YuC