Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
有没有办法用Javascript检测强制点击?_Javascript_Macos_Browser_Click_Pressure.js - Fatal编程技术网

有没有办法用Javascript检测强制点击?

有没有办法用Javascript检测强制点击?,javascript,macos,browser,click,pressure.js,Javascript,Macos,Browser,Click,Pressure.js,有没有办法用Javascript检测强制点击?我知道有很多方法可以检测常规和右键单击,但是强制单击呢?请收听webkitmouseforcewillbegin和webkitmouseforcedown事件。您可以从传递到事件处理程序的对象中的webkitForce属性获取强制级别 当然,这只适用于Mac上支持Force Touch的Safari 资料来源:我发现了一个名为JS的库,它可以简化处理力/3D触摸。它适用于具有3D触控功能的iOS和具有强制触控功能的OSX。如果您只是在Mac上使用它进

有没有办法用Javascript检测强制点击?我知道有很多方法可以检测常规和右键单击,但是强制单击呢?

请收听
webkitmouseforcewillbegin
webkitmouseforcedown
事件。您可以从传递到事件处理程序的对象中的
webkitForce
属性获取强制级别

当然,这只适用于Mac上支持Force Touch的Safari


资料来源:

我发现了一个名为JS的库,它可以简化处理力/3D触摸。它适用于具有3D触控功能的iOS和具有强制触控功能的OSX。如果您只是在Mac上使用它进行强制触摸,您可以这样使用它:

Pressure.set('#element', {
  start: function(event){
    // this is called on force start
  },
  end: function(){
    // this is called on force end
  },
  startDeepPress: function(event){
    // this is called on "force click" / "deep press", aka once the force is greater than 0.5
  },
  endDeepPress: function(){
    // this is called when the "force click" / "deep press" end
  },
  change: function(force, event){
    // this is called every time there is a change in pressure
  },
  unsupported: function(){
    // this is called once there is a touch on the element and the device or browser does not support Force or 3D touch
  }
}, {only: 'force'});

最后的
{only:'force'}
选项确保它只在Mac上运行,而不在iOS上运行。如果您想让它同时在两个屏幕上运行,请删除该选项。

没有什么比鼠标点击时的力检测更有效的了。