onwheel incident
onwheel Event
Instance
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <style> #myDIV { border: 1px solid black; } </style> </head> <body> <div id="myDIV">该实例演示了如何使用 addEventListener() 方法向 DIV 元素添加 "wheel" 事件。在这个区域上下滚动鼠标滚轮!</div> <p>当你在 div 元素中滚动鼠标滚轮时,脚本函数会设置 div 的字体大小为 35 像素。</p> <p><strong>注意:</strong> Safari 浏览器不支持 wheel 事件</p> <script> document.getElementById("myDIV").addEventListener("wheel", myFunction); function myFunction() { document.getElementById("myDIV").style.fontSize = "35px"; } </script> </body> </html>
Run Instance»
Click the "Run Instance" button to view Online Example
#Definition and Usage
The onwheel event is triggered when the mouse wheel scrolls up and down on the element.
The onwheel event can also be triggered when scrolling on the touchpad or zooming in or out of the area (such as the touchpad on a laptop).
Browser support
Event | |||||
---|---|---|---|---|---|
#onwheel | 31.09.0 | 17.0 | Not supported | 18.0
Note: In the IE browser, the wheel event can only be supported through the addEventListener() method. There is no onwheel attribute in DOM objects.
SyntaxIn HTML:
<
JavaScript:element onwheel="myScript"> Try it
object.onwheel=function(){myScript};Try it
object.addEventListener("wheel", myScript); try it
Note: Internet Explorer 8 and earlier IE versions do not support the addEventListener() method.
Technical detailsYes | |
Yes | |
WheelEvent | |
All HTML elements |