鼠标滚轮事件在火狐下的兼容问题
- //兼容火狐的鼠标滚轮事件
- 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方向相反)
- }
- }
- }
来源: https://www.oschina.net/code/snippet_2302627_58729