Movatterモバイル変換


[0]ホーム

URL:


  1. Web
  2. Web APIs
  3. Element
  4. mousewheel

Element: mousewheel event

Deprecated: This feature is no longer recommended. Though some browsers might still support it, it may have already been removed from the relevant web standards, may be in the process of being dropped, or may only be kept for compatibility purposes. Avoid using it, and update existing code if possible; see thecompatibility table at the bottom of this page to guide your decision. Be aware that this feature may cease to work at any time.

Non-standard: This feature is not standardized. We do not recommend using non-standard features in production, as they have limited browser support, and may change or be removed. However, they can be a suitable alternative in specific cases where no standard option exists.

Theobsolete andnon-standardmousewheel event is fired asynchronously at anElement to provide updates while a mouse wheel or similar device is operated. Themousewheel event was never part of any standard, and while it was implemented by several browsers, it was never implemented by Firefox.

Note:Instead of this obsolete event, use the standardwheel event.

Syntax

Use the event name in methods likeaddEventListener(), or set an event handler property.

js
addEventListener("mousewheel", (event) => { })onmousewheel = (event) => { }

Event type

AWheelEvent. Inherits fromMouseEvent,UIEvent andEvent.

Event UIEvent MouseEvent WheelEvent

Event properties

This interface inherits properties from its ancestors,MouseEvent,UIEvent, andEvent.

WheelEvent.deltaXRead only

Returns adouble representing the horizontal scroll amount.

WheelEvent.deltaYRead only

Returns adouble representing the vertical scroll amount.

WheelEvent.deltaZRead only

Returns adouble representing the scroll amount for the z-axis.

WheelEvent.deltaModeRead only

Returns anunsigned long representing the unit of thedelta* values' scroll amount. Permitted values are:

ConstantValueDescription
WheelEvent.DOM_DELTA_PIXEL0x00Thedelta* values are specified in pixels.
WheelEvent.DOM_DELTA_LINE0x01Thedelta* values are specified in lines. Each mouse click scrolls a line of content, where the method used to calculate line height is browser dependent.
WheelEvent.DOM_DELTA_PAGE0x02Thedelta* values are specified in pages. Each mouse click scrolls a page of content.
WheelEvent.wheelDeltaRead onlyDeprecated

Returns an integer (32-bit) representing the distance in pixels.

WheelEvent.wheelDeltaXRead onlyDeprecated

Returns an integer representing the horizontal scroll amount.

WheelEvent.wheelDeltaYRead onlyDeprecated

Returns an integer representing the vertical scroll amount.

The detail property

The value of thedetail property is always zero, except in Opera, which usesdetail similarly to the Firefox-onlyDOMMouseScroll event'sdetail value, which indicates the scroll distance in terms of lines, with negative values indicating the scrolling movement is either toward the bottom or toward the right, and positive values indicating scrolling to the top or left.

Note:On macOS, the scroll distance (and therefore the value ofdetail) is computed based on the accelerated scroll distance.

On Linux,2 or-2 is set per native wheel event.

wheelDelta, wheelDeltaX and wheelDeltaY value

ThewheelDelta attribute value is an abstract value which indicates how far the wheel turned. If the wheel has rotated away from the user, it's positive, otherwise negative. This means that the delta value sign is different from DOM Level 3 Event'swheel. However, the meaning of the amount of these values is not the same between browsers. See following explanation for the detail.

IE and Opera (Presto) only supportwheelDelta attribute and donot support horizontal scroll.

ThewheelDeltaX attribute value indicates thewheelDelta attribute value along the horizontal axis. When a user operates the device for scrolling to right, the value is negative. Otherwise, i.e., if it's to left, the value is positive.

ThewheelDeltaY attribute value indicates thewheelDelta attribute value along the vertical axis. The sign of the value is the same as thewheelDelta attribute value.

Chrome

On Windows, the value is the same as the delta value ofWM_MOUSEWHEEL orWM_MOUSEHWHEEL. And also, the value isn't changed even if the scroll amount of system settings is page scroll, i.e., the value is the same as IE on Windows.

On Linux, the value is120 or-120 per native wheel event. This makes the same behavior as IE and Chrome for Windows.

On Mac, the value is complicated. The value is changed if thedevice that causes the native wheel event supports continuous scroll.

If the device supports continuous scroll (e.g., trackpad of MacBook or mouse wheel which can be turned smoothly), the value is computed from accelerated scroll amount. In this case, the value is the same as Safari.

If the device doesnot support continuous scroll (typically, old mouse wheel which cannot be turned smoothly), the value is computed from non-accelerated scroll amount (120 per notch). In this case, the value is different from Safari.

This difference makes a serious issue for web application developers. That is, web developers cannot know ifmousewheel event is caused by which device.

Safari

The value is always computed from accelerated scroll amount. This is really different from other browsers except Chrome with continuous scroll supported device.

Opera (Presto)

The value is always thedetail attribute value ✕40.

On Windows, since thedetail attribute value is computed from actual scroll amount, the value is different from other browsers except the scroll amount per notch is 3 lines in system settings or a page.

On Linux, the value is80 or-80 per native wheel event. This is different from other browsers.

On Mac, thedetail attribute value is computed from accelerated scroll amount of native event. The value is usually much bigger than Safari's or Chrome's value.

Specifications

Not part of any specification.

Browser compatibility

See also

  • The standardwheel event to listen to instead.

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp