JavaScript/wheel:修订间差异
来自康健生活
| (未显示同一用户的10个中间版本) | |||
| 第3行: | 第3行: | ||
=== 组成 === | === 组成 === | ||
鼠标的滚轮事件主要有两种: | 鼠标的滚轮事件主要有两种: | ||
* | * mousewheel (firefox 不支持,非标准弃用) | ||
* DOMMouseScroll ( | * DOMMouseScroll (只有 firefox 支持,非标准弃用) | ||
== mousewheel == | |||
触摸板的双指操作行为触发 mousewheel 事件。 | |||
=== 双指 === | |||
{| class="wikitable" | |||
|+ 双指操作行为 | |||
|- | |||
| 上滑动 || 下滑动 || 左滑动 || 右滑动 || 放大 || 缩小 | |||
|} | |||
==== 快速滑动 ==== | |||
{| class="wikitable" | |||
|- | |||
! !! 方向 !! 值域 | |||
|- | |||
| deltaX || 示例 || 示例 | |||
|- | |||
| deltaY || 示例 || 示例 | |||
|- | |||
| deltaZ || 示例 || 示例 | |||
|} | |||
==== 缓慢滑动 ==== | |||
{| class="wikitable" | |||
|- | |||
! !! 方向 !! 值域 | |||
|- | |||
| deltaX || 示例 || [-3, 3] | |||
|- | |||
| deltaY || 示例 || [-3, 3] | |||
|- | |||
| deltaZ || 示例 || 示例 | |||
|} | |||
==== 放大/缩小 ==== | |||
这里对比一个<code>放大/缩小</code>和<code>向上/向下/向左/向右</code>的动作。 | |||
{{hcdiff|head= wheel |output=<syntaxhighlight lang="bash" highlight="11"> | |||
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</syntaxhighlight>|output2=<syntaxhighlight lang="bash" highlight="11"> | |||
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 | |||
</syntaxhighlight>}} | |||
双指<code>放大/缩小</code>,只有 <code>ctrlKey</code> 值为 <code>true</code>,并且几乎只有 <code>deltaY</code> 发生变化,放大时 <math>deltaY < 0</math>,缩小时 <math>deltaY > 0</math>。 | |||
===== 实现 ===== | |||
=== 监听 wheel 结束 === | |||
== 属性 == | == 属性 == | ||
* deltaX | * deltaX | ||
| 第16行: | 第152行: | ||
* 使用触摸板触发事件,由于系统的平滑处理,会触发多次事件。 | * 使用触摸板触发事件,由于系统的平滑处理,会触发多次事件。 | ||
* IE 下无法使用触摸板触发该事件。{{Qm|有待验证}} | * IE 下无法使用触摸板触发该事件。{{Qm|有待验证}} | ||
== 滚动事件参考 == | |||
<pre> | |||
事件 浏览器 | |||
wheel Chrome(31+), FF(17+), IE(9+) | |||
mousewheel Chrome, IE(6+), Opera, Safari | |||
MozMousePixelScroll FF(3.5 only!) (2010-2013) | |||
DOMMouseScroll FF(0.9.7+) since 2003 | |||
</pre> | |||
== error == | == error == | ||
2022年6月20日 (一) 03:30的最新版本
引言
滚动事件
组成
鼠标的滚轮事件主要有两种:
- 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 发生变化,放大时 ,缩小时 。
实现
监听 wheel 结束
属性
- deltaX
- deltaY
- wheelDelta
- deltaMode
- detail
触摸板
触摸板逻辑包括双指在触摸板上持续滑动、双指滑动后松开任其自由滑动一段距离两种状态。
问题
- 使用触摸板触发事件,由于系统的平滑处理,会触发多次事件。
- IE 下无法使用触摸板触发该事件。?(有待验证)
滚动事件参考
事件 浏览器 wheel Chrome(31+), FF(17+), IE(9+) mousewheel Chrome, IE(6+), Opera, Safari MozMousePixelScroll FF(3.5 only!) (2010-2013) DOMMouseScroll FF(0.9.7+) since 2003
error
参考
No categories