【问题标题】:How to measure the force of pressure on the Web?如何测量 Web 上的压力?
【发布时间】:2015-06-30 17:51:01
【问题描述】:

最近,Apple 推出了一款新的触控板,它支持“Force Touch”功能。它类似于用于绘画的 Wacom 数位板,因为通过特殊的软件,您可以测量按压的力(重量)。
那么,是否有可能使用像 javascript 这样的网络技术来获取这些值?浏览器是否提供任何有关压力的 API 和信息?

附言我发现这个问题与我的问题有关,但与网络无关:Android, IOS force pressing on the screen

【问题讨论】:

    标签: javascript web touch tablet


    【解决方案1】:

    您正在寻找PointerEventpressure 属性。 This isn't widely supported across browsers yet,因为它不是最终规范,但在撰写本文时 IE11 has some support

    【讨论】:

    • 有史以来最好的答案!非常感谢 :) 它有效,经过测试。
    【解决方案2】:

    对于 iOS (iPhone 6s) 和 Mac(带有 Force Touch 的新 MabBook Pro),您可以使用Pressure.js。它是一个 JavaScript 库,可让您在 Web 上简单地使用强制触摸。下面是一个基本用法的例子:

    Pressure.set('#element', {
      change: function(force, event){
        // this is called every time there is a change in pressure
      },
      unsupported: function(){
        // this is called if device or browser does not support Force or 3D touch
      }
    });
    

    【讨论】:

    • 谢谢!看起来现在我们有了 MouseEvent.webkitForce 等等。
    • @MaximMazurok 完全正确。但是使用它会变得复杂,因为您必须反复循环事件以获得更新的力,以及检测它是否受支持等其他问题。 Pressure.js 负责所有这些,默认情况下也支持 Mac Force Touch。所以它适用于 iPhone 6s 和新 Mac 以及新的 Mac 触控板
    猜你喜欢
    • 1970-01-01
    • 2014-10-02
    • 2011-01-17
    • 2012-07-22
    • 2010-09-18
    • 2012-02-03
    • 1970-01-01
    • 1970-01-01
    • 2011-06-07
    相关资源
    最近更新 更多