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)