Scrolltop not working
11,193
In your code you have:
document.body.scrollTop(0, 0);
scrollTop is not a method call.
Did you mean window.scrollTo(0,0)
or document.body.scrollTop = 0;
?
Author by
Odinulf
Updated on June 06, 2022Comments
-
Odinulf almost 2 years
Does anyone have any idea why the following script does not reset the place of the page to the top? (The autoscrolling works fine) I am look for the fix to be compatable in IE...
function getheight() { var myWidth = 0, myHeight = 0; if (typeof (window.innerWidth) == 'number') { //Non-IE myWidth = window.innerWidth; myHeight = window.innerHeight; } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) { //IE 6+ in 'standards compliant mode' myWidth = document.documentElement.clientWidth; myHeight = document.documentElement.clientHeight; } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) { //IE 4 compatible myWidth = document.body.clientWidth; myHeight = document.body.clientHeight; } var scrolledtonum = window.pageYOffset + myHeight + 2; var heightofbody = document.body.offsetHeight; if (scrolledtonum >= heightofbody) { document.body.scrollTop(0, 0); } } window.onscroll = getheight; function func() { window.document.body.scrollTop++; } window.document.onmouseover = function () { clearInterval(interval); }; window.document.onmouseout = function () { interval = setInterval(func, 20); }; var interval = setInterval(func, 20);
-
Odinulf almost 13 yearsI used window.scrollTo(0,0) and it works in Chrome. However, it still does not work in IE (Well, at least IE7) Any ideas?
-
epascarello almost 13 yearsAre you sure
scrolledtonum >= heightofbody
is true in IE? -
Odinulf almost 13 yearsNo, that statement is not compatible with IE. How could I replicate it with the same result in a method that is compatible with IE?