jQuery animate scrollTop not working in IE 7
10,939
Solution 1
EDIT As pointed out by many, it is better to use:
$('body, html').animate({scrollTop : 0}, 0);
Solution 2
$('body, html').animate({scrollTop : 0}, 0);
Solution 3
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.
Solution 4
Set:
# FF、IE8
document.documentElement.scrollTop = 100;
# chrome
document.body.scrollTop = 100;
Get:
scrollTop = document.documentElement.scrollTop + document.body.scrollTop;
Author by
Alex
I'm a .net developer from Camberley, Surrey. Strong interest in web applications - emphasis on back end APIs. Recently working in serverless applications. Enjoy speaking at tech events where possible.
Updated on July 06, 2022Comments
-
Alex over 1 year
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? -
Simon East about 11 yearsI don't think this works in all browsers.
'body, html'
is a better selector (see other answer). -
Richard about 11 yearsThis doesnt work well in all browsers. Rather use the other answer.