这是
实验性技术
检查
浏览器兼容性表格
要小心谨慎在生产中使用这之前。
Touch.force
read-only property returns the amount of pressure the user is applying to the touch surface for a
触摸
point.
touchItem.force;
A
float
that represents the amount of pressure the user is applying to the touch surface. This is a value between
0.0
(no pressure) and
1.0
(the maximum amount of pressure the hardware can recognize). A value of
0.0
is returned if no value is known (for example the touch device does not support this property). In environments where force is known, the absolute pressure represented by the force attribute, and the sensitivity in levels of pressure, may vary.
This example illustrates using the
触摸
接口的
Touch.force
property. This property is a relative value of pressure applied, in the range
0.0
to
1.0
,其中
0.0
is no pressure, and
1.0
is the highest level of pressure the touch device is capable of sensing.
In following code snippet, the
touchstart
event handler iterrates through the
targetTouches
list and logs the
force
value of each touch point but the code could invoke different processing depending on the value.
someElement.addEventListener('touchstart', function(e) {
// Iterate through the list of touch points and log each touch
// point's force.
for (var i=0; i < e.targetTouches.length; i++) {
// Add code to "switch" based on the force value. For example
// minimum pressure vs. maximum pressure could result in
// different handling of the user's input.
console.log("targetTouches[" + i + "].force = " + e.targetTouches[i].force);
}
}, false);
| 规范 | 状态 | 注释 |
|---|---|---|
| Touch Events – Level 2 | 草案 | 初始定义。 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
force
|
Chrome Yes | Edge ≤79 | Firefox Yes | IE No | Opera Yes | Safari No | WebView Android Yes | Chrome Android Yes | Firefox Android Yes | Opera Android Yes | Safari iOS Yes | Samsung Internet Android Yes |
完整支持
不支持
实验。期望将来行为有所改变。