Document: wheel event

The wheel event fires when the user rotates a wheel button on a pointing device (typically a mouse).

Bubbles Yes
Cancelable Yes
Interface WheelEvent
Event handler property GlobalEventHandlers.onwheel

This event replaces the non-standard deprecated mousewheel event.

Note: Don't confuse the wheel event with the scroll event. The default action of a wheel event is implementation-specific, and doesn't necessarily dispatch a scroll event. Even when it does, the delta* values in the wheel event don't necessarily reflect the content's scrolling direction. Therefore, do not rely on the wheel event's delta* properties to get the scrolling direction. Instead, detect value changes of scrollLeft and scrollTop in the scroll event.

Examples

Scaling an element via the wheel

This example shows how to scale an element using the mouse (or other pointing device) wheel.

<div>Scale me with your mouse wheel.</div>
body {
  min-height: 100vh;
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

div {
  width: 105px;
  height: 105px;
  background: #cdf;
  padding: 5px;
}
function zoom(event) {
  event.preventDefault();

  if (event.deltaY < 0) {
    // Zoom in
    scale *= event.deltaY * -2;
  }
  else {
    // Zoom out
    scale /= event.deltaY * 2;
  }

  // Restrict scale
  scale = Math.min(Math.max(.125, scale), 4);

  // Apply scale transform
  el.style.transform = `scale(${scale})`;
}

let scale = 1;
const el = document.querySelector('div');
document.onwheel = zoom;

addEventListener equivalent

The event handler can also be set up using the addEventListener() method:

document.addEventListener('wheel', zoom);

Specifications

Specification Status Comment
UI Events
The definition of 'wheel' in that specification.
Working Draft

Browser compatibility

DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
wheel eventChrome Full support 61Edge Full support 12Firefox Full support YesIE Full support YesOpera Full support 48Safari Full support 6.1WebView Android Full support 61Chrome Android Full support 61Firefox Android Full support YesOpera Android Full support 45Safari iOS No support NoSamsung Internet Android Full support 8.0

Legend

Full support
Full support
No support
No support

See also