MDN’s new design is in Beta! A sneak peek: https://blog.mozilla.org/opendesign/mdns-new-design-beta/

PointerEvent

这篇翻译不完整。请帮忙从英语翻译这篇文章

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

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

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

Constructors

PointerEvent()
Creates a synthetic and untrusted PointerEvent.

Properties

This interface inherits properties from MouseEvent and Event.

PointerEvent.pointerId 只读
A unique identifier for the pointer causing the event.
PointerEvent.width 只读
The width (magnitude on the X axis), in CSS pixels, of the contact geometry of the pointer.
PointerEvent.height 只读
The height (magnitude on the Y axis), in CSS pixels, of the contact geometry of the pointer.
PointerEvent.pressure 只读
The normalized pressure of the pointer input in the range 0 to 1, where 0 and 1 represent the minimum and maximum pressure the hardware is capable of detecting, respectively.
PointerEvent.tangentialPressure 只读
The normalized tangential pressure of the pointer input (also known as barrel pressure or cylinder stress) in the range -1 to 1, where 0 is the neutral position of the control.
PointerEvent.tiltX 只读
The plane angle (in degrees, in the range of -90 to 90) between the Y-Z plane and the plane containing both the transducer (e.g. pen stylus) axis and the Y axis.
PointerEvent.tiltY 只读
The plane angle (in degrees, in the range of -90 to 90) between the X-Z plane and the plane containing both the transducer (e.g. pen stylus) axis and the X axis.
PointerEvent.twist 只读
The clockwise rotation of the transducer (e.g. pen stylus) around its major axis in degrees, with a value in the range 0 to 359.
PointerEvent.pointerType 只读
Indicates the device type that caused the event (mouse, pen, touch, etc.)
PointerEvent.isPrimary 只读
Indicates if the pointer represents the primary pointer of this pointer type.

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
Working Draft Non-stable version.
Pointer Events
PointerEvent
Recommendation Initial definition.

Browser compatibility

Feature Chrome Edge Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support 55.0 (Yes) 未实现 [1] 10ms
11
42 未实现
touch-action property (Yes) ? 未实现 [2] 11 (Yes) 未实现
tangentialPressure and twist (Yes) (Yes) 未实现[1][3] (Yes) (Yes) 未实现
Feature Android Android Webview Edge Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile Chrome for Android
Basic support 未实现 55.0 (Yes) 未实现 [1] 10 42 未实现 55.0
touch-action property 未实现 (Yes) ? 未实现 [2] (Yes) (Yes) 未实现 (Yes)
tangentialPressure and twist 未实现 (Yes) ? 未实现[1][3] (Yes) (Yes) 未实现 (Yes)

[1] This feature is currently hidden behind a flag; to enable it and experiment, set the dom.w3c_pointer_events.enabled preference to true in about:config.

[2] Starting in Firefox 29, touch-action is implemented in Firefox, but is hidden behind the layout.css.touch_action.enabled preference. Starting in Firefox Nighly 50, it is enabled by default when running in nightly builds only; no decision has been made on when it will make its way along toward release. You still need to separately enable the dom.w3c_pointer_events.enabled preference, however.

[3] tangentialPressure and twist were implemented in Firefox 54.

See also

<embed height="0" id="xunlei_com_thunder_helper_plugin_d462f475-c18e-46be-bd10-327458d045bd" type="application/thunder_download_plugin" width="0"/>

文档标签和贡献者

 此页面的贡献者: ucev
 最后编辑者: ucev,