今天趁着工作闲暇的时间,写了一个简单的兼容各浏览器的鼠标滚轮方法:
代码:
function mouseWheel(){ if(document.addEventListener){ document.body.addEventListener('mousewheel',function(e){ Detail(e); e.stopPropagation(); e.preventDefalut(); }); document.body.addEventListener('DOMMouseScroll',function(e){ Detail(e); e.stopPropagation(); e.preventDefault(); }) }else{ document.body.attachEvent('onmousewheel',function(event){ Detail(event); event.cancelBubble=true; event.returnValue=false; }) } function Detail(e){ ((-e.detail || e.wheelDelta)>0)?alert('top'):alert('down'); } }