JavaScript/wheel
来自康健生活
引言
滚动事件
组成
鼠标的滚轮事件主要有两种:
- mousewheel (firefox 不支持,非标准弃用)
- DOMMouseScroll (只有 firefox 支持,非标准弃用)
mousewheel
触摸板的双指操作行为触发 mousewheel 事件。
双指
| 上滑动 | 下滑动 | 左滑动 | 右滑动 | 放大 | 缩小 |
快速滑动
| 方向 | 值域 | |
|---|---|---|
| deltaX | 示例 | 示例 |
| deltaY | 示例 | 示例 |
| deltaZ | 示例 | 示例 |
缓慢滑动
| 方向 | 值域 | |
|---|---|---|
| deltaX | 示例 | [-3, 3] |
| deltaY | 示例 | [-3, 3] |
| deltaZ | 示例 | 示例 |
放大/缩小
这里对比一个放大/缩小和向上/向下/向左/向右的动作。
wheel
isTrusted: true
altKey: false
bubbles: true
button: 0
buttons: 0
cancelBubble: false
cancelable: true
clientX: 491
clientY: 339
composed: true
ctrlKey: true
currentTarget: null
defaultPrevented: true
deltaMode: 0
deltaX: -0
deltaY: 5.265862464904785
deltaZ: 0
detail: 0
eventPhase: 0
fromElement: null
layerX: 491
layerY: 339
metaKey: false
movementX: 0
movementY: 0
offsetX: 492
offsetY: 340
pageX: 491
pageY: 339
path: (9) [main#boardDocumentDrag.board-document-drag, div.board-document, div.container, div, div#app, body#syno-nsc-ext-gen3.ext-webkit.ext-chrome.ext-mac, html.ext-strict, document, Window]
relatedTarget: null
returnValue: false
screenX: 491
screenY: 418
shiftKey: false
sourceCapabilities: null
srcElement: main#boardDocumentDrag.board-document-drag
target: main#boardDocumentDrag.board-document-drag
timeStamp: 64205.89999999106
toElement: main#boardDocumentDrag.board-document-drag
type: "wheel"
view: Window {window: Window, self: Window, document: document, name: '', location: Location, …}
wheelDelta: -240
wheelDeltaX: 0
wheelDeltaY: -240
which: 0
x: 491
y: 339
[[Prototype]]: WheelEvent
isTrusted: true
altKey: false
bubbles: true
button: 0
buttons: 0
cancelBubble: false
cancelable: true
clientX: 648
clientY: 331
composed: true
ctrlKey: false
currentTarget: null
defaultPrevented: true
deltaMode: 0
deltaX: -6
deltaY: -0
deltaZ: 0
detail: 0
eventPhase: 0
fromElement: null
layerX: 648
layerY: 331
metaKey: false
movementX: 0
movementY: 0
offsetX: 648
offsetY: 331
pageX: 648
pageY: 331
path: (9) [main#boardDocumentDrag.board-document-drag, div.board-document, div.container, div, div#app, body#syno-nsc-ext-gen3.ext-webkit.ext-chrome.ext-mac, html.ext-strict, document, Window]
relatedTarget: null
returnValue: false
screenX: 648
screenY: 410
shiftKey: false
sourceCapabilities: null
srcElement: main#boardDocumentDrag.board-document-drag
target: main#boardDocumentDrag.board-document-drag
timeStamp: 87451.29999999702
toElement: main#boardDocumentDrag.board-document-drag
type: "wheel"
view: Window {window: Window, self: Window, document: document, name: '', location: Location, …}
wheelDelta: 18
wheelDeltaX: 18
wheelDeltaY: 0
which: 0
x: 648
y: 331
[[Prototype]]: WheelEvent
双指放大/缩小,只有 ctrlKey 值为 true,并且几乎只有 deltaY 发生变化,放大时 ,缩小时 。
实现
属性
- deltaX
- deltaY
- wheelDelta
- deltaMode
- detail
触摸板
触摸板逻辑包括双指在触摸板上持续滑动、双指滑动后松开任其自由滑动一段距离两种状态。
问题
- 使用触摸板触发事件,由于系统的平滑处理,会触发多次事件。
- IE 下无法使用触摸板触发该事件。?(有待验证)
error
参考
No categories