When the user rolls the mouse wheel over a <div> element, change its font-size:
document.getElementById("myDIV").addEventListener("wheel", myFunction);
function myFunction() {
this.style.fontSize = "35px";
}
Try it Yourself »
The onwheel
event occurs when the mouse wheel is rolled over an element.
The onwheel
event also occurs when the user scrolls using a touchpad.
In JavaScript, using the addEventListener() method:
object.addEventListener("wheel",
myScript);
Try it Yourself »
Bubbles: | Yes |
---|---|
Cancelable: | Yes |
Event type: | WheelEvent |
HTML tags: | All HTML elements |
DOM Version: | Level 3 Events |
onwheel
is a DOM Level 3 (2004) feature.
It is fully supported in all modern browsers:
Chrome | Edge | Firefox | Safari | Opera | IE |
Yes | Yes | Yes | Yes | Yes | 11 |
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!