isPrimary 只读特性在 PointerEvent interface indicates whether or not the pointer device that created the event is the primary pointer. It returns true if the pointer that caused the event to be fired is the primary device and returns false 否则。

In a multi-pointer scenario (such as a touch screen that supports more than one touch point), this property is used to identify a master pointer among the set of active pointers for each pointer type. Only a primary pointer will produce compatibility mouse events . Authors who desire only single-pointer interaction can achieve that by ignoring non-primary pointers.

A pointer is considered primary if the pointer represents a mouse device. A pointer representing pen input is considered the primary pen input if its pointerdown event was dispatched when no other active pointers representing pen input existed. A pointer representing touch input is considered the primary touch input if its pointerdown event was dispatched when no other active pointers representing touch input existed.

When two or more pointer device types are being used concurrently, multiple pointers (one for each pointerType ) are considered primary. For example, a touch contact and a mouse cursor moved simultaneously will produce pointers that are both considered primary. If there are multiple primary pointers, these pointers will all produce compatibility mouse events (见 Pointer_events for more information about pointer, mouse and touch interaction).

句法

var isPrimary = pointerEvent.isPrimary;
					

返回值

isPrimary
返回 true if the pointer for this event is the primary pointer and returns false 否则。

范例

This example illustrates using the value of isPrimary to call the appropriate processing function.

target.addEventListener('pointerdown', function(event) {
   if (event.isPrimary)
     process_primary_pointer(event);
   else
     process_secondary_pointer(event);
 }, false);
					

规范

规范 状态 注释
指针事件 – 2 级
The definition of 'isPrimary' in that specification.
推荐 非稳定版本。
指针事件
The definition of 'isPrimary' in that specification.
过时 初始定义。

浏览器兼容性

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
isPrimary Chrome 55 Edge 12 Firefox 59
59
Disabled ). To change preferences in Firefox, visit
IE 10 Opera 42 Safari 13 WebView Android 55 Chrome Android 55 Firefox Android 41 Opera Android 42 Safari iOS 13 Samsung Internet Android 6.0

图例

完整支持

完整支持

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

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

元数据

  • 最后修改: