首页 > 代码库 > 鼠标滚轮事件

鼠标滚轮事件

FireFox以外的浏览器,包括ie6,使用onmousewheel;

FireFox使用DOMMouseScroll

 1 function mousewheel (e) {
 2   var e = e || window.event;
 3   e.delta = e.wheelDelta ? e.wheelDelta / 120 : - (e.delta || 0) / 3;
 4 if (e.delta === -1) {
 5 console.log("向下滚");
 6 } else if (e.delta === 1) {
 7 console.log("向上滚");
 8 }
 9   e.stopPropagation();
10 e.preventDefault();
11 }
12 window.addEventListener(‘DOMMouseScroll‘, mousewheel);
13 window.addEventListener(‘mousewheel‘, mousewheel);

 

鼠标滚轮事件