js:鼠标滚轮事件

参考 http://www.cnblogs.com/walkingp/archive/2010/02/03/1662872.html

 

1.注册事件

//Firefox
if(document.addEventListener)
{
    document.addEventListener("DOMMouseScroll",scrollFunc,false);
}
// safari chrome IE Opera
window.onmousewheel = document.onmousewheel = scrollFunc;

2.节流,防止滚轮一次,触发两次事件

var timer = null;
function scrollFunc(){
    clearTimeout(timer);
    timer = setTimeout(function(){},100)
}

 

posted on 2017-02-22 16:20  飞翔吧菜鸟23  阅读(79)  评论(0编辑  收藏  举报