有什么方法可以使用 Javascript 检测强制点击?我知道有一些方法可以检测常规点击和右键点击,但是强制点击呢?
问问题
1525 次
2 回答
5
我发现了一个名为Pressure.js的 JS 库,它使处理 Force/3D Touch 变得更简单。它适用于具有 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 上运行。如果您希望它在两者上都运行简单,请删除该选项。
于 2016-01-24T05:52:03.477 回答
3
监听webkitmouseforcewillbegin
和webkitmouseforcedown
事件。webkitForce
您可以从传递给事件处理程序的对象中的属性中获取力级别。
当然,这只适用于支持 Force Touch 的 Mac 上的 Safari。
于 2015-11-03T19:01:43.473 回答