获取scrollTop:
document.documentElement.scrollTop || document.body.scrollTop
鼠标滚轮事件:
onscroll
事件;
悬浮导航例子:
//导航悬浮
var navT = 0;
window.onload = function () {
var navBox = document.getElementById("navBox");
var navT = navBox.offsetTop;
window.onscroll = function () {
var t = document.documentElement.scrollTop || document.body.scrollTop;
if (t > navT) {
navBox.style.position = "fixed";
navBox.style.top = "0";
}
else {
navBox.style.position = "absolute";
navBox.style.top = "725px";
}
}
}