width 只读特性在 PointerEvent interface represents the width of the pointer's contact geometry along the x-axis, measured in CSS pixels. Depending on the source of the pointer device (such as a finger), for a given pointer, each event may produce a different value.

If the input hardware cannot report the contact geometry to the browser, the width defaults to 1 .

句法

var contactWidth = pointerEvent.width;
					

返回值

contactWidth

The width of the event's contact area (in CSS pixels).

范例

This example illustrates using the PointerEvent 接口的 width and height properties to calculate the contact area.

target.addEventListener("pointerdown", function(ev) {
   // Calculate the contact area
   var area = ev.width * ev.height;
 }, false);
					

规范

规范 状态 注释
指针事件 – 2 级
The definition of 'width' in that specification.
推荐 非稳定版本。
指针事件
The definition of 'width' 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
width Chrome 55 Edge 12 Firefox 59
59
Disabled ). To change preferences in Firefox, visit
IE 11
11
部分支持 10
Returns values in screen pixels instead of CSS document pixels.
Opera 42 Safari 13 WebView Android 55 Chrome Android 55 Firefox Android 41 Opera Android 42 Safari iOS 13 Samsung Internet Android 6.0

图例

完整支持

完整支持

见实现注意事项。

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

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

元数据

  • 最后修改: