DOMMouseScroll,onmousewheel 鼠标滚动事件js
2017-02-20 23:07
561 查看
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <style type="text/css"> div[class^='div'] { font-family: "微软雅黑"; font-size: 40px; height: 540px; border-bottom: solid 1px paleturquoise; } .div0 { background-color: #ff0; } .div1 { background-color: royalblue; } .div3 { background-color: cornflowerblue; } .div4 { background-color: blueviolet; } </style> </head> <body> <div class="div0">div0</div> <div class="div1">div1</div> <div class="div2">div2</div> <div class="div3">div3</div> <div class="div4">div4</div> </body> <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script> <script type="text/javascript"> //判断是否是火狐浏览器 var IsFirefox = navigator.userAgent.toLocaleLowerCase().indexOf('firefox') > -1 $(function() { //添加鼠标滚动的监听事件 if(IsFirefox) { document.body.addEventListener('DOMMouseScroll', function(event) { console.log(event.detail); //向上滚动为120,向下是-120 }) } else { document.body.onmousewheel = function() { console.log(event.wheelDelta); //向上滚动为120,向下是-120 }; } }) </script> </html>
相关文章推荐
- 关于浏览器兼容的问题以及字符串编码的一个坑,鼠标滚动事件mousewheel和DOMMouseScroll
- js鼠标滚轮事件(mousewheel/DOMMouseScroll)
- js鼠标滚轮事件(mousewheel/DOMMouseScroll)
- JS 鼠标滚轮事件(mousewheel/DOMMouseScroll)
- 鼠标滚动:mousewheel事件在Firefox采用DOMMouseScroll事件的统一处理
- JS滚轮事件(mousewheel/DOMMouseScroll)了解
- JS滚轮事件(mousewheel/DOMMouseScroll)了解
- JS滚轮事件(mousewheel/DOMMouseScroll)了解
- JS滚轮事件(mousewheel/DOMMouseScroll)了解
- 学习 JS滚轮事件(mousewheel/DOMMouseScroll)
- js处理局部scroll事件禁止外部scroll滚动解决办法,jquery.mousewheel.js处理时禁止办法说明
- JS滚轮事件(mousewheel/DOMMouseScroll)了解
- 鼠标滚轮(mousewheel)和DOMMouseScroll事件 (转载)
- 鼠标滑轮事件的差异onmousewheel和DOMMouseScroll
- 鼠标滚轮事件(mousewheel、DOMMouseScroll)
- 扩展 jQuery EasyUI Datagrid 数据行鼠标悬停/离开事件(onMouseOver/onMouseOut)
- js鼠标滚动事件
- js鼠标滑轮滚动事件绑定的简单实例(兼容主流浏览器)
- 扩展 jQuery EasyUI Datagrid 数据行鼠标悬停/离开事件(onMouseOver/onMouseOut)
- 认识js中的鼠标按下放开mousedown,mouseup以及按键事件keydown,keyup