javaScript實現滾動條事件
阿新 • • 發佈:2019-01-07
//滾動事件
function myScroll() {
var i = document.body.scrollTop;
var top = document.getElementById("top");
var left = document.getElementById("left");
var f1 = document.getElementById("f1");
var f2 = document.getElementById("f2" );
var f3 = document.getElementById("f3");
var f4 = document.getElementById("f4");
var f5 = document.getElementById("f5");
var f6 = document.getElementById("f6");
//控制頂部
if(i >= 1000) {
top.style.display = "block" ;
top.innerHTML = i;
} else {
top.style.display = "none";
}
//控制左側
if(i >= 2000) {
left.style.display = "block";
} else {
left.style.display = "none" ;
}
//顯示樓層
if(i >= 2000 && i <= 2500) {
f1.className = "a";
f2.className = "";
f3.className = "";
f4.className = "";
f5.className = "";
f6.className = "";
} else if(i > 2500 && i <= 3000) {
f1.className = "";
f2.className = "a";
f3.className = "";
f4.className = "";
f5.className = "";
f6.className = "";
} else if(i > 3000 && i <= 3500) {
f1.className = "";
f2.className = "";
f3.className = "a";
f4.className = "";
f5.className = "";
f6.className = "";
} else if(i > 3500 && i <= 4000) {
f1.className = "";
f2.className = "";
f3.className = "";
f4.className = "a";
f5.className = "";
f6.className = "";
} else if(i > 4000 && i <= 4500) {
f1.className = "";
f2.className = "";
f3.className = "";
f4.className = "";
f5.className = "a";
f6.className = "";
} else if(i > 4500 && i <= 5000) {
f1.className = "";
f2.className = "";
f3.className = "";
f4.className = "";
f5.className = "";
f6.className = "a";
}
}