我的網站上有一個腳本,適用於除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