Home >Web Front-end >JS Tutorial >The scroll bar responds to the mouse wheel event to implement js code for scrolling up and down_javascript skills

The scroll bar responds to the mouse wheel event to implement js code for scrolling up and down_javascript skills

WBOY
WBOYOriginal
2016-05-16 16:42:451136browse

Implement mouse scroll wheel event:

<script type="text/javascript"> 
var scrollFunc=function(e){ 
e=e || window.event; 
if(e.wheelDelta){//IE/Opera/Chrome 
if(e.wheelDelta==120) 
{ 
//向上滚动事件 
alert(e.wheelDeta +"向上"); 

}else 
{ 
//向上滚动事件 
alert(e.wheelDeta +"向上"); 
} 
}else if(e.detail){ 
//Firefox 
if(e.detail==-3) { 
//向上滚动事件<br> 
alert(e.detail +"向上"); 
}else { 
//向下滚动事件<br> 
alert(e.detail +"向下 "); 
} 
} 
}; 
if(document.addEventListener){ 
//adding the event listerner for Mozilla 
document.addEventListener("DOMMouseScroll" ,scrollFunc, false); 
} 
//IE/Opera/Chrome 
window.onmousewheel=document.onmousewheel=scrollFunc;
</script>
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