滚动条响应鼠标滑轮事件实现上下滚动的js代码

时间:2024-05-18 22:37:26
<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>