我的网站上有一个脚本,适用于除Internet Explorer之外的每个浏览器。有人可以解释为什么这不起作用吗?我的滚动处理程序JavaScript在Internet Explorer中不起作用
var header = document.getElementById('header');
var picturebg = document.getElementsByClassName('picturebg')[0];
var arrow = document.getElementsByClassName('toTop-transparent')[0];
var supportPageOffset = window.pageXOffset !== undefined;
window.onscroll = function() {
"use strict";
var y = window.scrollY;
if (y > 7) {
header.className = 'header-colored';
arrow.className = 'toTop';
picturebg.className = 'picturebgns';
} else {
header.className = 'header-transparent';
arrow.className = 'toTop-transparent';
picturebg.className = 'picturebg';
}
};
控制台不给任何错误,它只是不工作。我有另一个运行得很好的jQuery脚本。
我在这里看到了另外一个关于同一事物的问题,但它没有任何帮助。
你用www.caniuse.com检查您正在使用的功能的兼容性如何? – Carcigenicate
那么,这段代码不起作用,因为你没有任何HTML,所以document.getElementById()返回null .... –
如果你已经加载jQuery,为什么不把它移植到jQuery? jQuery的好处之一是其测试方法可以在所有现代浏览器上运行。 – junkfoodjunkie