function addMouseWheel(obj,fn,preventDefault){ //添加绑定 if(window.navigator.userAgent.toLowerCase().indexOf("firefox") != -1){ obj.addEventListener("DOMMouseScroll",fnWheel,false); } else { obj.onmousewheel = fnWheel; } function fnWheel(ev){ var oEvent = ev || event; var bDown = true;//下 if(oEvent.wheelDelta){//ie chrome console.log(oEvent.wheelDelta) bDown = oEvent.wheelDelta > 0 ? false:true; } else {//ff console.log(oEvent.detail) bDown = oEvent.detail > 0 ? true:false; } (typeof fn == "function") && fn(bDown); if(preventDefault){ oEvent.preventDefault && oEvent.preventDefault(); return false; } } }
时间: 2024-10-11 09:00:32