Javascript Scrolltop不工作

Javascript Scrolltop不工作,javascript,html,css,internet-explorer,Javascript,Html,Css,Internet Explorer,有人知道为什么下面的脚本没有将页面的位置重置为顶部吗?(自动滚动工作正常)我正在寻找在IE中兼容的修复程序 function getheight() { var myWidth = 0, myHeight = 0; if (typeof (window.innerWidth) == 'number') { //Non-IE myWi

有人知道为什么下面的脚本没有将页面的位置重置为顶部吗?(自动滚动工作正常)我正在寻找在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);
在代码中,您有:

document.body.scrollTop(0, 0);
不是方法调用


您的意思是或
document.body.scrollTop=0

我使用window.scrollTo(0,0),它在Chrome中工作。然而,它在IE中仍然不起作用(好吧,至少IE7)有什么想法吗?你确定
scrolledtonum>=身体高度在IE中是真的吗?没有,该语句与IE不兼容。我如何在与IE兼容的方法中复制该语句并获得相同的结果?请检查您的css-我的问题是,我将“溢出:滚动”设置为body中的子级,而不是body/html本身,因此我必须设置child div的动画,而不是body/html的动画(因此,而不是$('body,html')).animate({scrollTop:0},“slow”);我必须执行$('.child元素')。animate({scrollTop:0},“slow”);)