function addScrollEvent(obj,handle){ //obj代表的是将来调用函数时,传递的标签 //先判断是不是火狐 var isFF = navigator.userAgent.indexOf("Firefox"); if(isFF != -1){ obj.addEventListener("DOMMouseScroll",scrollfun,false); }else{ obj.onmousewheel = scrollFun; } //上滚轮还是下滚轮 function scrollFun(event){ var ev = event || window.event; //判断事件;IE和非IE,针对事件不同,IE针对window var down; if(isFF != -1){ down = ev.detail > 0; //火狐,detail>0 表示向下滑 }else{ down = ev.wheelDelta < 0; //非火狐 wheelDelta<0 向下滑; } handle(down); //此处handle是调用父级的函数,down是用了这个子级的参数down //在此处调用,相当于外部引用时候的function(down); } }
时间: 2024-10-19 01:38:29