阻止浏览器滚动条滚动

function handler(e){ //这里必须加参数e,否则firefox不兼容
   
e = e ? e : window.event;
   if(document.addEventListener){
       e.preventDefault();
   }else{
       e.returnValue = false;
   }
}
var mousewheelevt=(/Firefox/i.test(navigator.userAgent))?"DOMMouseScroll": "mousewheel"//FF doesn't recognize mousewheel as of FF3.x
if(document.attachEvent){//if IE (and Opera depending on user setting)
   
document.attachEvent("on"+mousewheelevt, handler);
}else if(document.addEventListener){ //WC3 browsers
   
document.addEventListener(mousewheelevt, handler, false);
}



你可能感兴趣的:(阻止浏览器滚动条滚动)