在最新版的Chrome浏览器中,有两个滚轮事件:
所以这段代码能够良好运行:
但在这种情况下:
wheel
和mousewheel
。所以这段代码能够良好运行:
document.addEventListener('mousewheel', function () {
console.log('mousewheel fires');
}, false);
但在这种情况下:
document.addEventListener('mousewheel', function () {
console.log('mousewheel never fires');
}, false);
document.addEventListener('wheel', function () {
console.log('wheel fires');
}, false);
mousewheel
不起作用。
如果我编写一些第三方脚本(例如jquery插件)并在其中使用mousewheel
,则它无法在使用wheel
事件的网站上工作。
相反,如果我在脚本中使用wheel
事件,则会破坏使用mousewheel
的网站。
在这种情况下该怎么办?(对我的英语表示抱歉)。
更新
感谢Tintu C Raju:
根据MDN,“当指针设备(通常是鼠标)的滚轮按钮旋转时,将触发滚轮事件。此事件替换了已弃用的非标准mousewheel事件。”