This article mainly gives you a detailed introduction to the mouse scroll event in javascript, which is illustrated in great detail. if you need it, you can refer to it. All modern browsers support the scroll wheel and trigger time when you scroll the scroll wheel. Browsers usually use the scroll wheel to scroll or scale the document, but you can disable the mousewheel event to prevent these default operations. Some interoperability issues affect scroll events, but you can still write cross-platform code. All browsers except Firefox support the "mousewheel" event, but Firefox uses "DOMMouseScroll". the draft level 3 DOM event specification suggests replacing "mousewheel" with the event name "wheel ".
document.body.onmousewheel = function(event){ event = event || window.event; console.dir(event);}
Firefox does not support mousewheel
document.body.addEventListener("DOMMouseScroll",function(event){ console.dir(event);})
The following scroll wheel is output in the console of chrome and IE9.
The following is the console output for scroll down Firefox
From the output above, we can use a non-standard DOMMouseScroll event to replace mousewheel, and replace wheelDetal with the detail attribute of the event object. However, the scaling ratio and positive and negative symbols of the detail property value are different from those of the wheelDetal value. The value of the detail value is multiplied by-40 and the value of the wheelDetal value is equal.
In browsers other than FireFox, the scroll up and down is related to the following wheelDelta.
According to the test, in my win7 system, whether IE7, IE10, Opera12, or safari5.1, each time I scroll downevent.wheelDelta
All values-120
.
For the FireFox browser (also available in operabrowser), the attribute of judging the mouse scroll direction isevent.detail
, Scroll down3
.
It should be noted that the positive and negative values of the FireFox browser are opposite to those of other browsers. The FireFox browser scroll down to a positive value, while other browsers scroll down to a negative value.
Var isFirefox = (navigator. userAgent. indexOf ("Firefox ")! =-1); if (isFirefox) {element. addEventListener ("DOMMouseScroll", wheelHandler, false);} element. onmousewheel = wheelHandler; // element. onwheel = wheelHandler; // DOM3-level wheel events, which are not supported after IE9 tests, but are supported by both Google and Firefox. in Google, there is a wheelDelta with the detailfunction wheelHandler (event) in Firefox) {event = event | window. event; var delta = event. wheelDelta | detail *-30 ;}
The above is all the content of this article. I hope you will like it.