IE 兼容代码不工作
可能的重复:
使 DOM IE 友好
我在这里做错了什么? (它应该是兼容 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;
}
var scrolledtonum = (((t = document.documentElement) || (t = document.body.parentNode)) && typeof t.ScrollTop == 'number' ? t : document.body).ScrollTop + myHeight + 2;
alert(scrolledtonum);
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);
一旦我修复了它,我该怎么做才能使其兼容 IE?
Possible Duplicate:
Making DOM IE Friendly
What I am doing wrong here? (it is supposed to be IE compliant, but it doesn't work at all)
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;
}
var scrolledtonum = (((t = document.documentElement) || (t = document.body.parentNode)) && typeof t.ScrollTop == 'number' ? t : document.body).ScrollTop + myHeight + 2;
alert(scrolledtonum);
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);
What can I do to make it IE compliant once I have fixed it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
以 varscrolledtonum = ( 开头的行中有一个拼写错误
(ScrollTop 中的 S 必须小写)
此外:请确保在触发文档的 onload 事件之前不会调用 getheight() ,否则
document.body.offsetHeight
可能无法返回正确的值。There is a typo in the line starting with
var scrolledtonum = (
(the S in ScrollTop has to be lowercase)
Furthermore: be sure that getheight() will not be called before the document's onload-event has fired, otherwise
document.body.offsetHeight
may not return correct values.