我正在尝试捕获鼠标事件。这是我正在尝试的代码:
if(window.addEventListener) { document.addEventListener('DOMMouseScroll', zoom_handler, false); }
else { document.onmousewheel = zoom_handler; }
alert("test"); //I see this alert so I assume the code above it is run
//...
function zoom_handler(event) {
var delta = 0;
if (!event) event = window.event;
// normalize the delta
if (event.wheelDelta) {
// IE and Opera
delta = event.wheelDelta / 60;
} else if (event.detail) {
// W3C
delta = -event.detail / 2;
}
alert("Delta: " + delta);
}
除了问题是当我尝试在页面上上下滚动时我什么也看不到,所以我想我没有正确捕获事件。作为参考,我一直在尝试遵循本教程:http: //viralpatel.net/blogs/2009/08/javascript-mouse-scroll-event-down-example.html
谢谢你的帮助。