js监听鼠标滚动
//加载顺序问题,不可改变位置
var scrollFunc = function(e){
e = e || window.event;
if (e.wheelDelta) {
if (e.wheelDelta > 0) {
scrollUp();
}
if (e.wheelDelta < 0) {
scrollDown();
}
}else if (e.detail) { //Firefox 滑轮事件
if (e.detail > 0) {
scrollUp();
}
if (e.detail < 0) {
scrollDown();
}
}
}
//给页面绑定滑轮滚动事件
if (document.addEventListener) {//firefox
document.addEventListener('DOMMouseScroll', scrollFunc, false);
}
//滚动滑轮触发scrollFunc方法 //ie 谷歌
window.onmousewheel = document.onmousewheel = scrollFunc;
function scrollUp(){
alert("滑轮向上滚动");
}
function scrollDown(){
alert("滑轮向下滚动");
}