当前位置 : 主页 > 网络编程 > JavaScript >

火狐下鼠标滚轮事件

来源:互联网 收集:自由互联 发布时间:2021-07-03
鼠标滚轮事件在火狐下的兼容问题 1. [代码] [JavaScript]代码 //兼容火狐的鼠标滚轮事件 document.getElementById("t1").addEventListener("DOMMouseScroll",function(e){ scrollFunc(e,$(".table_1"),$("#pageNum"),$("#total
鼠标滚轮事件在火狐下的兼容问题

1. [代码][JavaScript]代码    

    //兼容火狐的鼠标滚轮事件
    document.getElementById("t1").addEventListener("DOMMouseScroll",function(e){
        scrollFunc(e,$(".table_1"),$("#pageNum"),$("#total"));
    },false);

     document.getElementById("t2").addEventListener("DOMMouseScroll",function(e){
        scrollFunc(e,$(".table_2"),$("#pageNum_phone"),$("#total_phone"));
    },false);

    document.getElementById("t3").addEventListener("DOMMouseScroll",function(e){
        scrollFunc(e,$(".table_3"),$("#pageNum_bus"),$("#total_bus"));
    },false);


    //chroom和ie下的鼠标滚轮事件
    $('.table_1 table').on("mousewheel", function() {
        scrollFunc(e,$(this),$("#pageNum"),$("#total"));
    });

    $('.table_2 table').on("mousewheel",function(){
        scrollFunc(e,$(this),$("#pageNum_phone"),$("#total_phone"));
    })

    $('.table_3 table').on("mousewheel",function(){
        scrollFunc(e,$(this),$("#pageNum_bus"),$("#total_bus"));
    })
}


function scrollFunc(e,that,pageNum,totalPage){
     var e = e || window.event;
     if (e.wheelDelta) {      
        if (e.wheelDelta > 0) {
           up(that,pageNum,totalPage);//chroom和ie下,鼠标滚轮向上滚
        }
        if (e.wheelDelta < 0) { 
           down(that,pageNum,totalPage);//chroom和ie下,鼠标滚轮向下滚
       }
    } 
    else if (e.detail) {  
        if (e.detail> 0) { 
            down(that,pageNum,totalPage);//火狐下,鼠标滚轮向下滚(与chroom和ie方向相反)
        }
        if (e.detail< 0) { 
            up(that,pageNum,totalPage);//火狐,鼠标滚轮向上滚(与chroom和ie方向相反)
        }
    }
}
网友评论