The mouse wheel is judged to scroll up or down. Different browsers have different identification methods. Currently, popular browsers include IE, Opera, Safari, Firefox, Chrome, the implementation of Firefox is different from that of other browsers. Now, let's use a specific example to analyze this problem!
The sample code is as follows:
<Label for = "wheelDelta"> scroll value: </label> (IE/Opera) <input type = "text" id = "wheelDelta"/> <label for = "detail"> scroll value: (Firefox) </label> <input type = "text" id = "detail"/> <script type = "text/javascript">/* register an event */if (document. addEventListener) {document. addEventListener ('domainscroll', scrollFunc, false);} // W3Cwindow. onmousewheel = document. onmousewheel = scrollFunc; // IE/Opera/Chromevar scrollFunc = function (e) {e = e | window. event; var t1 = document. getElementById ("wheelDelta"); var t2 = document. getElementById ("detail"); if (e. wheelDelta) {// for IE/Opera/Chrome t1.value = e. wheelDelta;} else if (e. detail) {// If the browser is Firefox t2.value = e. detail ;}}</script>
By running the above code, we can see that:
In Firefox, detail is used, while other browsers use wheelDelta. Although the two are different in values, the actual meaning is the same. Only two values are available for detail and wheelDelta, the value of detail is ± 3, and the value of wheelDelta is only ± 120. The positive value indicates upward, and the negative value indicates downward.
In a non-firefox browser, scroll up returns 120, scroll down returns-120
In firefox, the value returned by scroll up is-3, and 3 is returned by scroll down.
The Code is as follows. e. wheelDelta determines whether it is a non-firefox browser, and e. detail judges it as a firefox browser.
if(e.wheelDelta){//IE/Opera/Chromet1.value=e.wheelDelta;}else if(e.detail){//Firefoxt2.value=e.detail;}
Articles you may be interested in
- How does JS determine whether to scroll up or down
- Javascript determines whether the mouse is left or right-click-compatible with ie, firefox, chrome, and other major browsers
- Js determines whether a value exists in a js Array
- Js determines whether the variable is a number
- Php determines whether the string is full of English, pure Chinese, and a combination of Chinese and English
- Js restrictions: Only English letters and numbers can be entered. Chinese characters and other special characters cannot be entered.
- Do you want to start a business, or do you want to become a sohofamily?
- Javascript, php Regular Expression verification for mixed numbers and letters (6-15 digits)