pointerType
只读特性在
PointerEvent
interface indicates the device type (mouse, pen, or touch) that caused a given pointer event.
var pType = pointerEvent.pointerType;
pType
"mouse"
The event was generated by a mouse device.
"pen"
The event was generated by a pen or stylus device.
"touch"
The event was generated by a touch, such as a finger.
If the device type cannot be detected by the browser, the value can be an empty string (
""
). If the browser supports pointer device types other than those listed above, the value should be
vendor-prefixed
to avoid conflicting names for different types of devices.
This example illustrates using the value of the
pointerType
property to call the appropriate pointer type processing function.
targetElement.addEventListener('pointerdown', function(event) {
// Call the appropriate pointer type handler
switch (event.pointerType) {
case 'mouse':
process_pointer_mouse(event);
break;
case 'pen':
process_pointer_pen(event);
break;
case 'touch':
process_pointer_touch(event);
break;
默认:
console.log(`pointerType ${event.pointerType} is not suported`);
}
}, false);
| 规范 | 状态 | 注释 |
|---|---|---|
|
指针事件
The definition of 'pointerType' in that specification. |
过时 | 初始定义。 |
|
指针事件 – 2 级
The definition of 'pointerType' in that specification. |
推荐 | 非稳定版本。 |
|
CSSOM (CSS 对象模型) 视图模块
在该规范中的 MouseEvent 定义。 |
工作草案 |
重新定义
MouseEvent
from
long
to
double
. This means that a
PointerEvent
whose
pointerType
is mouse will be a
double
.
|
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
更新 GitHub 上的兼容性数据| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
pointerType
|
Chrome 55 | Edge 12 |
Firefox
59
|
IE
11
|
Opera 42 | Safari 13 | WebView Android 55 | Chrome Android 55 | Firefox Android 41 | Opera Android 42 | Safari iOS 13 | Samsung Internet Android 6.0 |
Fractional coordinates for
mouse
.
|
Chrome
部分支持
64
|
Edge
部分支持
79
|
Firefox No |
IE
部分支持
Partial
|
Opera
部分支持
51
|
Safari No |
WebView Android
部分支持
64
|
Chrome Android
部分支持
64
|
Firefox Android No |
Opera Android
部分支持
47
|
Safari iOS No |
Samsung Internet Android
部分支持
9.0
|
完整支持
部分支持
不支持
见实现注意事项。
用户必须明确启用此特征。
PointerEvent
Element.ongotpointercapture
Element.onlostpointercapture
Element.releasePointerCapture()
Element.setPointerCapture()
GlobalEventHandlers.onpointercancel
GlobalEventHandlers.onpointerdown
GlobalEventHandlers.onpointerenter
GlobalEventHandlers.onpointerleave
GlobalEventHandlers.onpointermove
GlobalEventHandlers.onpointerout
GlobalEventHandlers.onpointerover
GlobalEventHandlers.onpointerup
Navigator.maxTouchPoints