一、鼠标滚轮事件
1.1.IE
1.1.1.滚轮事件;onmousewheel
1.1.2.添加事件;
window.attachEvent('onmousewheel', function() { handle.call(window); });
1.2.火狐
1.2.1.滚轮事件;onwheel
1.2.2.添加事件;
window.addEventListener('wheel', handle, false);
1.3.其他浏览器
1.3.1.滚轮事件;onwheel
1.3.2.滚轮事件;onwheel
window.addEventListener('mousewheel', handle, false);
二、滚轮事件兼容处理程序
2.1.代码
function myMouseWheel(handle) { if (window.attachEvent) { window.attachEvent('onmousewheel', function() { handle.call(window); }); } else if (window.addEventListener) { if (window.onmousewheel === null) { window.addEventListener('mousewheel', handle, false); } else if (window.hasOwnProperty('wheel')) { window.addEventListener('wheel', handle, false); } } } function test(e) { var event = e || window.event; console.log(event); } myMouseWheel(test);
博主联系方式:
- 微信:34419369
- QQ: 34419369
- 公众号:前方录
- 有什么不懂的地方欢迎联系我,帮到你是我会很开心