Anyone have any ideas why scrollTop isn't working in IE?
It works in Chrome fine, and I don't know about firefox. (The idea of this script is to have an autoscrolling page that resets once it hits the bottom of the page)
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);
scrollTop is deprecated in strict mode.
Scrolling: scrollTo, scrollBy, scrollIntoView Regular elements can be scrolled by changing scrollTop/scrollLeft . We can do the same for the page using document. documentElement.
scrollTop doesn't respond to negative values; instead, it sets itself back to 0 . If set to a value greater than the maximum available for the element, scrollTop settles itself to the maximum value.
The scrollTop() method sets or returns the vertical scrollbar position for the selected elements. Tip: When the scrollbar is on the top, the position is 0. When used to return the position: This method returns the vertical position of the scrollbar for the FIRST matched element.
Try:
document.documentElement.scrollTop = x // where x is some integer
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With