onwheel
特性为
GlobalEventHandlers
混合
EventHandler
处理
wheel
事件。
wheel
event fires when the user rotates the mouse (or other pointing device) wheel.
注意:
Don't confuse
onwheel
with
onscroll
:
onwheel
handles general wheel rotation, while
onscroll
handles scrolling of an object's content.
target.onwheel = functionRef;
functionRef
is a function name or a
函数表达式
. The function receives a
WheelEvent
object as its sole argument.
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: 80px;
height: 80px;
background: #cdf;
padding: 5px;
transition: transform .3s;
}
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;
| 规范 | 状态 | 注释 |
|---|---|---|
|
HTML 实时标准
The definition of 'onwheel' in that specification. |
实时标准 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
onwheel
|
Chrome 61 | Edge 12 | Firefox Yes | IE Yes | Opera 48 | Safari Yes | WebView Android 61 | Chrome Android 61 | Firefox Android Yes | Opera Android 45 | Safari iOS Yes | Samsung Internet Android 8.0 |
完整支持
GlobalEventHandlers
onabort
onanimationcancel
onanimationend
onanimationiteration
onauxclick
onblur
oncancel
oncanplay
oncanplaythrough
onchange
onclick
onclose
oncontextmenu
oncuechange
ondblclick
ondurationchange
onended
onerror
onfocus
onformdata
ongotpointercapture
oninput
oninvalid
onkeydown
onkeypress
onkeyup
onload
onloadeddata
onloadedmetadata
onloadend
onloadstart
onlostpointercapture
onmousedown
onmouseenter
onmouseleave
onmousemove
onmouseout
onmouseover
onmouseup
onpause
onplay
onplaying
onpointercancel
onpointerdown
onpointerenter
onpointerleave
onpointermove
onpointerout
onpointerover
onpointerup
onreset
onresize
onscroll
onselect
onselectionchange
onselectstart
onsubmit
ontouchcancel
ontouchstart
ontransitioncancel
ontransitionend
onwheel
AbortController
AbortSignal
AbstractRange
Attr
ByteString
CDATASection
CSSPrimitiveValue
CSSValue
CSSValueList
CharacterData
ChildNode
注释
CustomEvent
DOMConfiguration
DOMError
DOMErrorHandler
DOMException
DOMImplementation
DOMImplementationList
DOMImplementationRegistry
DOMImplementationSource
DOMLocator
DOMObject
DOMParser
DOMPoint
DOMPointInit
DOMPointReadOnly
DOMRect
DOMString
DOMTimeStamp
DOMTokenList
DOMUserData
Document
DocumentFragment
DocumentType
元素
ElementTraversal
Entity
EntityReference
事件
EventTarget
HTMLCollection
MutationObserver
节点
NodeFilter
NodeIterator
NodeList
NonDocumentTypeChildNode
ProcessingInstruction
PromiseResolver
范围
StaticRange
文本
TextDecoder
TextEncoder
TimeRanges
TreeWalker
TypeInfo
USVString
UserDataHandler
XMLDocument