复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <style type="text/css"> #box{width: 200px;height: 200px;background-color: red;position: absolute;} </style> <script type="text/javascript"> window.onload=function(){ var oBox=document.getElementById('box');//找到对应的盒子 oBox.onmousewheel=fn;//onmousewheel兼容IE和谷歌,不兼容火狐 if(oBox.addEventListener){//addEventListenner绑定事件,兼容非IE,attachEvent兼容IE oBox.addEventListener('DOMMouseScroll',fn,false);//DOMMouseScroll兼容火狐 } var b=true; function fn(ev){ var iEvent=ev||event; if(iEvent.wheelDelta){//鼠标上滚和下滚事件,wheelDelta兼容IE和谷歌不兼容火狐,上滚为120,下滚为-120 b=iEvent.wheelDelta>0?b=true:b=false; } else{ b=iEvent.detail>0?b=false:b=true;//detail兼容火狐,上滚为-3,下滚为3 } if(b){ oBox.style.height=oBox.offsetHeight+10+'px'; } else{ oBox.style.height=oBox.offsetHeight-10+'px'; } } } </script> </head> <body> <div id="box"> </div> </body> </html>
最后
以上就是迅速八宝粥最近收集整理的关于js的鼠标滚轮事件的全部内容,更多相关js内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复