Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ScrollTop not working in IE

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);
like image 550
Odinulf Avatar asked Jul 18 '11 17:07

Odinulf


People also ask

Is scrollTop deprecated?

scrollTop is deprecated in strict mode.

Can I use document documentElement scrollTop?

Scrolling: scrollTo, scrollBy, scrollIntoView Regular elements can be scrolled by changing scrollTop/scrollLeft . We can do the same for the page using document. documentElement.

Can scrollTop be negative?

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.

What is $( window scrollTop ()?

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.


1 Answers

Try:

document.documentElement.scrollTop = x // where x is some integer
like image 186
Trevor Avatar answered Oct 21 '22 06:10

Trevor