[英]Any way to detect Force Click with Javascript?
Is there any way to detect a Force Click with Javascript? 有什么方法可以使用Java技术检测强制点击? I know there are ways to detect regular and right clicks, but what about Force Clicks?
我知道有多种方法可以检测常规点击和右键点击,但是强制点击呢?
I've found a JS library called Pressure.js that makes handling Force/3D Touch simpler. 我找到了一个名为Pressure.js的JS库,该库使处理Force / 3D Touch更加简单。 It works for both iOS with 3D touch and OSX with force touch.
它适用于具有3D触摸的iOS和具有强制触摸的OSX。 If you are using it for just force touch on Mac, you could use it like this:
如果您仅在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'});
The {only: 'force'}
options at the end make sure it only runs for force touch on Mac and not also on iOS. 最后的
{only: 'force'}
选项可确保它仅在Mac上为强制触摸而运行,而在iOS上不运行。 If you want it to run on both simple remove that option. 如果您希望它同时运行,则删除该选项。
Listen for the webkitmouseforcewillbegin
and webkitmouseforcedown
events. 侦听
webkitmouseforcewillbegin
和webkitmouseforcedown
事件。 You can get the force level from the webkitForce
property in the object passed into the event handler. 您可以从传递给事件处理程序的对象中的
webkitForce
属性获取强制级别。
Of course, this only works on Safari on Macs with Force Touch support. 当然,这仅适用于具有Force Touch支持的Mac上的Safari。
Source: WebKit DOM Programming Documentation 来源: WebKit DOM编程文档
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.