onwheel Event
Definition and Usage
The onwheel event occurs when the mouse wheel scrolls up or down over an element.
The onwheel event also occurs when the user scrolls or zooms in or out of an element using a touchpad.
Example
Change the font size of the <div> element when the user scrolls the mouse wheel over it:
document.getElementById("myDIV").addEventListener("wheel", myFunction); function myFunction() { this.style.fontSize = "35px"; }
Syntax
In HTML:
<element onwheel="myScript">
In JavaScript:
object.onwheel = function(){myScript};
In JavaScript, use the addEventListener() method:
object.addEventListener("wheel", myScript);
Note:Internet Explorer 8 or earlier versions do not support addEventListener() Method.
Technical Details
Bubbling: | Supported |
---|---|
Cancelable: | Supported |
Event type: | WheelEvent |
Supported HTML tags: | All HTML elements |
DOM Version: | Level 3 Events |
Browser Support
The numbers in the table indicate the first browser version that fully supports this event.
event | Chrome | IE | Firefox | Safari | Opera |
---|---|---|---|---|---|
onwheel | 31.0 | 9.0 | 17.0 | Not Supported | 18.0 |
Note:In IE, wheel events are only supported through the addEventListener() method. There is no onwheel property on the DOM object.