PointerEvent: pointerType プロパティ
Baseline Widely available *
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2020.
* Some parts of this feature may have varying levels of support.
pointerType
は PointerEvent
インターフェイスの読み取り専用プロパティで、特定のポインターイベントを引き起こした機器の種類(マウス、ペン、タッチのいずれか)を示します。
値
例
この例は、pointerType
プロパティの値を使用して適切なポインターの種類の処理関数を呼び出す方法を示しています。
js
targetElement.addEventListener(
"pointerdown",
(event) => {
// 適切なポインターの種類のハンドラーを呼び出す
switch (event.pointerType) {
case "mouse":
process_pointer_mouse(event);
break;
case "pen":
process_pointer_pen(event);
break;
case "touch":
process_pointer_touch(event);
break;
default:
console.log(`pointerType ${event.pointerType} には対応していません`);
}
},
false,
);
仕様書
Specification |
---|
Pointer Events # dom-pointerevent-pointertype |
ブラウザーの互換性
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
pointerType | ||||||||||||
Fractional coordinates for mouse . |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
- Partial support
- Partial support
- No support
- No support
- See implementation notes.
- Has more compatibility info.
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.