Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

onwheel event

onwheel event

Event Object Reference Event Object

Example

Execute JavaScript when the user right-clicks the mouse on the element:

Execute JavaScript when the mouse wheel is scrolled over the element:

document

.

getElementById

(

"

myDIV

"

)

.

addEventListener

(

"

wheel

"

,

myFunction

)

;

function

myFunction

(

)

{

document

.

getElementById

(

"

myDIV

"

)

.

style

.

color

=

"

red

"

;

}

Try it »


Definition and Usage

The onwheel event is triggered when the mouse wheel is scrolled up or down over the element.

The onwheel event can also be triggered when scrolling or zooming a region on a touchpad (such as the touchpad on a laptop).


Browser support

Events
onwheel 31.0 9.0 17.0 6.0 18.0

Note: In the IE browser, the wheel event is only supported through the addEventListener() method. There is no onwheel attribute in the DOM object.


Syntax

In HTML:

<

element

onwheel="

myScript

">

Try it

In JavaScript:

object

.onwheel=function(){

myScript

};

Try it

In JavaScript, use the addEventListener() method:

object

.addEventListener("wheel",

myScript

);

Try it

Note: Internet Explorer 8 and earlier IE versions do not support addEventListener() method.


Technical Details

Does it support bubbling: Yes
Is it cancelable: Yes
Event type: WheelEvent
Supported HTML tags: All HTML elements

Event Object Reference Event Object