PointerEvent

PointerEvent 接口代表了由 指针 引发的DOM事件的状态,包括接触点的位置,引发事件的设备类型,接触表面受到的压力等。

指针 是输入设备的硬件层抽象(比如鼠标,触摸笔,或触摸屏上的一个触摸点)。指针 能指向一个具体表面(如屏幕)上的一个(或一组)坐标。

指针的 击中检测 指浏览器用来检测 指针事件的目标元素的过程。大多数情况下,这个目标元素是由 指针的位置和元素在文章中的位置和分层共同决定的。

Constructors

PointerEvent() (en-US)
创建一个合成的且不可信的 PointerEvent。

Properties

该接口属性继承自 MouseEvent 和 Event.

PointerEvent.pointerId (en-US) 只读
触发事件的 pointer 的唯一标识符。
PointerEvent.width (en-US) 只读
Pointer 的接触面的 CSS 像素宽度(X轴上的大小)。
PointerEvent.height (en-US) 只读
Pointer 的接触面的 CSS 像素高度(Y轴上的大小)。
PointerEvent.pressure (en-US) 只读
归一化后的 pointer 压力值,范围在 [0,1] 区间。其中 0 和 1 分别代表硬件能够检测的最小和最大压力。
PointerEvent.tangentialPressure (en-US) 只读
归一化后的切向压力值(也称为桶压或cylinder stress),范围在 [-1, 1] 区间,0表示控制设备中立状态时的值。
PointerEvent.tiltX (en-US) 只读
由输入设备(如手写笔)与 Y 轴构成的平面,和 Y-Z 平面之间的夹角(取值在 [-90, 90] 区间)。
PointerEvent.tiltY (en-US) 只读
由输入设备(如手写笔)与 X 轴构成的平面,和 X-Z 平面之间的夹角(取值在 [-90, 90] 区间)。
PointerEvent.twist (en-US) 只读
输入设备(如手写笔)围绕自身主轴顺时针旋转的角度,取值范围是 [0, 359] 度。
PointerEvent.pointerType (en-US) 只读
表示触发事件的设备类型(鼠标,触控笔,触摸板等)。
PointerEvent.isPrimary (en-US) 只读
标识一个 pointer 是否是当前设备类型的主 pointer。

Pointer event types

The PointerEvent interface has several event types. To determine which event fired, look at the event's type property.

Note: It's important to note that in many cases, both pointer and mouse events get sent (in order to let non-pointer-specific code still interact with the user). If you use pointer events, you should call event.preventDefault() to keep the mouse event from being sent as well.
pointerover
This event is fired when a pointing device is moved into an element's hit test boundaries.
pointerenter
This event is fired when when a pointing device is moved into the hit test boundaries of an element or one of its descendants, including as a result of a pointerdown event from a device that does not support hover (see pointerdown). This event type is similar to pointerover, but differs in that it does not bubble.
pointerdown
The event is fired when a pointer becomes active. For mouse, it is fired when the device transitions from no buttons depressed to at least one button depressed. For touch, it is fired when physical contact is made with the digitizer. For pen, it is fired when the stylus makes physical contact with the digitizer.
pointermove
This event is fired when a pointer changes coordinates.
pointerup
This event is fired when a pointer is no longer active.
pointercancel
A browser fires this event if it concludes the pointer will no longer be able to generate events (for example the related device is deactived).
pointerout
This event is fired for several reasons including: pointing device is moved out of the hit test boundaries of an element; firing the pointerup event for a device that does not support hover (see pointerup); after firing the pointercancel event (see pointercancel); when a pen stylus leaves the hover range detectable by the digitizer.
pointerleave
This event is fired when a pointing device is moved out of the hit test boundaries of an element. For pen devices, this event is fired when the stylus leaves the hover range detectable by the digitizer.
gotpointercapture
This event is fired when an element receives pointer capture.
lostpointercapture
This event is fired after pointer capture is released for a pointer.

GlobalEventHandlers

GlobalEventHandlers.onpointerover
A global event handler for the pointerover event.
GlobalEventHandlers.onpointerenter
A global event handler for the pointerenter event.
GlobalEventHandlers.onpointerdown
A global event handler for the pointerdown event.
GlobalEventHandlers.onpointermove
A global event handler for the pointermove event.
GlobalEventHandlers.onpointerup
A global event handler for the pointerup event.
GlobalEventHandlers.onpointercancel
A global event handler for the pointercancel event.
GlobalEventHandlers.onpointerout
A global event handler for the pointerout event.
GlobalEventHandlers.onpointerleave
A global event handler for the pointerleave event.

Example

An Example of each property, event type and global event handler is included in their respective reference page.

Specifications

Specification Status Comment
Pointer Events – Level 2
PointerEvent
Recommendation Non-stable version.
Pointer Events
PointerEvent
Obsolete Initial definition.

Browser compatibility

BCD tables only load in the browser

See also