HTML onmousewheel Event Attribute
Description
The onmousewheel HTML event attribute is deprecated, meaning it should no longer be used. It has been replaced by the onwheel attribute, which is more widely supported and provides more accurate information about the mouse wheel event.
The onmousewheel attribute fires when the user rolls the mouse wheel up or down over an element. It can be used to perform any action you want, such as scrolling the element, changing its size, or displaying a different element.
To use the onmousewheel attribute, simply add it to the element you want to listen for the event on. For example, the following code would display an alert box when the user rolls the mouse wheel over the <div> element:
<div onmousewheel="alert('Mouse wheel event!')"></div>
You can also use the onmousewheel attribute to pass a function to be executed when the event fires. For example, the following code would scroll the <div> element up by 100 pixels when the user rolls the mouse wheel down:
<div onmousewheel="window.scrollBy(0, -100)"></div>
However, it is important to note that the onmousewheel attribute is deprecated, so you should use the onwheel attribute instead. The onwheel attribute is more widely supported and provides more accurate information about the mouse wheel event.
Here is an example of how to use the onwheel attribute:
<div onwheel="function(event) {
// Scroll the element up or down by the amount of the wheel delta
window.scrollBy(0, event.deltaY);
}"></div>
This code will scroll the <div> element up by 100 pixels if the user rolls the mouse wheel down, and down by 100 pixels if the user rolls the mouse wheel up.
Syntax
<element onmousewheel="script">
Values
- scriptThe name of the script to use when the event has been triggered.
Example
Browser Support
The following information will show you the current browser support for the HTML onmousewheel event attribute. Hover over a browser icon to see the version that first introduced support for this HTML event attribute.
Desktop





Tablets & Mobile





