【转】兼容IE和FireFox的鼠标滚轮事件
滚轮IE和Firefox的代码不一样:
IE是mousewheel事件,Firefox是DOMMouseScroll事件
事件属性,IE是event.wheelDelta,Firefox是event.detail
属性的方向值也不一样,IE向上滚 > 0,Firefox向下滚 > 0
- //滚轮放大或缩小,基于Prototype 1.6
- var scrollfunc = function(event) {
- var direct = 0;
- if (event.wheelDelta) {
- direct = event.wheelDelta > 0 ? 1 : -1;
- } else if (event.detail) {
- direct = event.detail < 0 ? 1 : -1;
- }
- zoom(direct);
- };
- Event.observe(document, 'mousewheel', scrollfunc);
- Event.observe(document, 'DOMMouseScroll', scrollfunc); //firefox