Scroll bar response to the mouse pulley event to achieve up and down scrolling js code

  • 2020-03-30 03:28:08
  • OfStack

Implement the 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) 
{ 
//Scroll up event
alert(e.wheelDeta +" upward "); 

}else 
{ 
//Scroll up event
alert(e.wheelDeta +" upward "); 
} 
}else if(e.detail){ 
//Firefox 
if(e.detail==-3) { 
//Scroll up events <Br>
alert(e.detail +" upward "); 
}else { 
//Scroll down events <Br>
alert(e.detail +" down  "); 
} 
} 
}; 
if(document.addEventListener){ 
//adding the event listerner for Mozilla 
document.addEventListener("DOMMouseScroll" ,scrollFunc, false); 
} 
//IE/Opera/Chrome 
window.onmousewheel=document.onmousewheel=scrollFunc;
</script>

Related articles: