FireFox browser uses DOMMouseScroll event, others (including IE6) use onmousewheel event;
wheelDelta in FireFox determines the scrolling direction, its value is 120/-120, when it is negative, it means scrolling down, and when it is an integer, scrolling up
Others: detail (Attribute) Judging the direction, the return value is an integer multiple of 3 (3/-3), a positive number means scrolling up, and a negative number scrolling down.
Opera: has both wheelDelta and detail, where the "detail" attribute returns the value and the one in FF. wheelDelta is the same
which is:
1 // jquery 兼容的滚轮事件 2 $(document).on("mousewheel DOMMouseScroll", function (e) { 3 console.log(e); 4 5 var delta = (e.originalEvent.wheelDelta && (e.originalEvent.wheelDelta > 0 ? 1 : -1)) || // chrome & ie 6 (e.originalEvent.detail && (e.originalEvent.detail > 0 ? -1 : 1)); // firefox 7 if (delta > 0) { 8 // 向上滚 9 console.log("wheelup"); 10 } else if(delta < 0 ) { 11 // roll down 12 console.log("wheeldown" ); 13 } 14 });