Javascript 让domie变得友好
如何使此脚本友好?唯一不友好的部分是变量Javascript 让domie变得友好,javascript,internet-explorer,dom,Javascript,Internet Explorer,Dom,如何使此脚本友好?唯一不友好的部分是变量scrolledtonum和heightofbody function getheight() { var myWidth = 0, myHeight = 0; if (typeof (window.innerWidth) == 'number') { //Non-IE myWidth = window.innerWidth;
scrolledtonum
和heightofbody
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;
}
}
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);
scrollY的mozilla MDN文档包含处理pageYOffset:兼容性问题的示例代码 它说: 要实现跨浏览器兼容性,请使用
window.pageYOffset
而不是window.scrollY
,使用除外
(((t = document.documentElement) || (t = document.body.parentNode)) && typeof t.ScrollTop == 'number' ? t : document.body).ScrollTop
当
window.pageYOffset
(和window.scrollY
)未定义时。@Mike Samuel未处于怪癖模式。您真的有IE4用户吗?如果没有,就去掉IE4支持代码。你永远不知道。。。可能没有。我添加了代码:(在这里)这里有什么我做错的吗?您可能想将ScrollTop更改为ScrollTop-它应该区分大小写。我也很想知道这一点。这是从MDN页面逐字复制的,我想知道是否一些非常旧的浏览器将其作为ScrollTop
?