Attached events
After my testing, IE/Opera are of the same type, and you can use attachEvent to add wheel events.
/*IE registration event*/
if( document.attachEvent){
document.attachEvent('onmousewheel',scrollFunc);
}
Firefox uses addEventListener to add scroll wheel events
/*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
/*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.
Statement: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