Details about the scroll wheel event in JS (multiple Firefox browsers)

Source: Internet
Author: User

Additional event

I tested that IE/opera belongs to the same type. You can use attachevent to add scroll wheel events.CopyCodeThe Code is as follows:/* ie registration event */
If (document. attachevent ){
Document. attachevent ('onmousewheel ', scrollfunc );
}

Firefox uses addeventlistener to add scroll wheel eventsCopy codeThe Code is as follows:/* Firefox registration event */
If (document. addeventlistener ){
Document. addeventlistener ('dommousescroll', scrollfunc, false );
}

Safari and chrome belong to the same type. You can use HTML Dom to add events.
Window. onmousewheel = Document. onmousewheel = scrollfunc; // IE/Opera/chrome
Except Firefox, you can use HTML Dom to add events. Therefore, the following method is used to add events:Copy codeThe Code is as follows:/* register an event */
If (document. addeventlistener ){
Document. addeventlistener ('dommousescroll', scrollfunc, false );
} // W3C
Window. onmousewheel = Document. onmousewheel = scrollfunc; // IE/Opera/chrome

Detail and wheeldelta

compatibility should also be considered when judging the scroll wheel up or down in the browser. Currently, Firefox uses detail in five browsers (ie, opera, Safari, Firefox, and chrome, the other four classes use wheeldelta. The two types only have different values, indicating the same meaning. Detail and wheeldelta take only two values, detail take only ± 3, and wheeldelta take only ± 120, the positive value indicates upward, and the negative value indicates downward. copy Code the code is as follows:

scroll value: (ie/opera)


scroll value: (Firefox)


VaR T1 = Document. getelementbyid ("wheeldelta ");
VaR t2 = Document. getelementbyid ("detail ");
If (E. wheeldelta) {// IE/Opera/chrome
T1.value = E. wheeldelta;
} Else if (E. Detail) {// Firefox
T2.value = E. detail;
}
Scrolltext (direct );
}
/* Register an event */
If (document. addeventlistener ){
Document. addeventlistener ('dommousescroll', scrollfunc, false );
} // W3C
Window. onmousewheel = Document. onmousewheel = scrollfunc; // IE/Opera/Chrome/Safari </SCRIPT>

Xmlns = "http://www.w3.org/1999/xhtml">

Scroll value:(Ie/opera)

Scroll value: (Firefox)

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.