PointerEvent
PointerEvent 接口代表了由 指针 引发的 DOM 事件的状态,包括接触点的位置,引发事件的设备类型,接触表面受到的压力等。
指针 是输入设备的硬件层抽象(比如鼠标,触摸笔,或触摸屏上的一个触摸点)。指针 能指向一个具体表面(如屏幕)上的一个(或一组)坐标。
指针的 击中检测 指浏览器用来检测 指针事件的目标元素的过程。大多数情况下,这个目标元素是由 指针的位置和元素在文章中的位置和分层共同决定的。
Constructors
PointerEvent()
-
创建一个合成的且不可信的 PointerEvent。
Properties
该接口属性继承自 MouseEvent
和 Event
.
PointerEvent.pointerId
只读-
触发事件的 pointer 的唯一标识符。
PointerEvent.width
只读-
Pointer 的接触面的 CSS 像素宽度(X 轴上的大小)。
PointerEvent.height
只读-
Pointer 的接触面的 CSS 像素高度(Y 轴上的大小)。
PointerEvent.pressure
只读-
归一化后的 pointer 压力值,范围在 [0,1] 区间。其中 0 和 1 分别代表硬件能够检测的最小和最大压力。
PointerEvent.tangentialPressure
只读-
归一化后的切向压力值(也称为桶压或cylinder stress),范围在 [-1, 1] 区间,0 表示控制设备中立状态时的值。
PointerEvent.tiltX
只读-
由输入设备(如手写笔)与 Y 轴构成的平面,和 Y-Z 平面之间的夹角(取值在 [-90, 90] 区间)。
PointerEvent.tiltY
只读-
由输入设备(如手写笔)与 X 轴构成的平面,和 X-Z 平面之间的夹角(取值在 [-90, 90] 区间)。
PointerEvent.twist
只读-
输入设备(如手写笔)围绕自身主轴顺时针旋转的角度,取值范围是 [0, 359] 度。
PointerEvent.pointerType
只读-
表示触发事件的设备类型(鼠标,触控笔,触摸板等)。
PointerEvent.isPrimary
只读-
标识一个 pointer 是否是当前设备类型的主 pointer。
Pointer event types
The PointerEvent
interface has several event types. To determine which event fired, look at the event's type
property.
备注:
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 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 (seepointerdown
). This event type is similar topointerover
, 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.
pointerrawupdate
实验性-
This event is fired when any of a pointer's properties change.
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 deactivated).
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 (seepointerup
); after firing thepointercancel
event (seepointercancel
); 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.
示例
An Example of each property, event type and global event handler is included in their respective reference page.
规范
Specification |
---|
Pointer Events # pointerevent-interface |
浏览器兼容性
BCD tables only load in the browser