Home > Web Front-end > JS Tutorial > Detailed explanation of mouse wheel events in js (firefox multi-browser)_javascript skills

Detailed explanation of mouse wheel events in js (firefox multi-browser)_javascript skills

WBOY
Release: 2016-05-16 18:35:29
Original
1033 people have browsed it

Attached events

After my testing, IE/Opera are of the same type, and you can use attachEvent to add wheel events.

Copy code The code is as follows:

/*IE registration event*/
if( document.attachEvent){
document.attachEvent('onmousewheel',scrollFunc);
}

Firefox uses addEventListener to add scroll wheel events
Copy code The code is as follows:

/*Firefox registration event*/
if(document.addEventListener){
document.addEventListener( 'DOMMouseScroll',scrollFunc,false);
}

Safari and Chrome are of the same type, and events can be added using HTML DOM
window.onmousewheel=document.onmousewheel=scrollFunc;/ /IE/Opera/Chrome
Except Firefox, all others can use HTML DOM to add events, so add events using the following method
Copy code The code is as follows:

/*Register event*/
if(document.addEventListener){
document.addEventListener('DOMMouseScroll',scrollFunc,false);
}//W3C
window.onmousewheel=document.onmousewheel=scrollFunc;//IE/Opera/Chrome

detail and wheelDelta

Judge whether the scroll wheel is up or down Compatibility must also be considered in browsers. Among the five major browsers (IE, Opera, Safari, Firefox, Chrome), Firefox uses detail, and the other four use wheelDelta; the two are only inconsistent in value, which means the meaning is the same, detail and wheelDelta only take two values ​​each, detail only takes ±3, and wheelDelta only takes ±120, where positive numbers represent upwards and negative numbers represent downwards.
Copy code The code is as follows:

(IE/Opera)






Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template