Touch.force - Web APIs 编辑

Experimental

This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

The Touch.force read-only property returns the amount of pressure the user is applying to the touch surface for a Touch point.

Syntax

touchItem.force;

Return value

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.

Example

This example illustrates using the Touch interface's Touch.force property. This property is a relative value of pressure applied, in the range 0.0 to 1.0, where 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 iterates 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);

Specifications

SpecificationStatusComment
Touch Events – Level 2DraftInitial definition.

Browser compatibility

BCD tables only load in the browser

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:122 次

字数:3478

最后编辑:6年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文