How does js determine whether the scroll wheel is scroll down or up?

Source: Internet
Author: User
Tags php regular expression

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.