pointerType 只读特性在 PointerEvent interface indicates the device type (mouse, pen, or touch) that caused a given pointer event.

句法

var pType = pointerEvent.pointerType;
					

返回值

pType
The event's pointer type. The supported values are the following strings:
"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 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
pointerType Chrome 55 Edge 12 Firefox 59
59
Disabled ). To change preferences in Firefox, visit
IE 11
11
部分支持 10
Returns an integer enumeration instead of a string.
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
部分支持 64
movementX and movementY are not fractional, see Chromium bug 802067 .
Edge 部分支持 79
部分支持 79
movementX and movementY are not fractional, see Chromium bug 802067 .
不支持 12 — 79
clientX , clientY , pageX and pageY are fractional.
Firefox No IE 部分支持 Partial
部分支持 Partial
clientX , clientY , pageX and pageY are fractional.
Opera 部分支持 51
部分支持 51
movementX and movementY are not fractional, see Chromium bug 802067 .
Safari No WebView Android 部分支持 64
部分支持 64
movementX and movementY are not fractional, see Chromium bug 802067 .
Chrome Android 部分支持 64
部分支持 64
movementX and movementY are not fractional, see Chromium bug 802067 .
Firefox Android No Opera Android 部分支持 47
部分支持 47
movementX and movementY are not fractional, see Chromium bug 802067 .
Safari iOS No Samsung Internet Android 部分支持 9.0
部分支持 9.0
movementX and movementY are not fractional, see Chromium bug 802067 .

图例

完整支持

完整支持

部分支持

部分支持

不支持

不支持

见实现注意事项。

用户必须明确启用此特征。

用户必须明确启用此特征。

元数据

  • 最后修改: