有没有办法用Javascript检测强制点击?
有没有办法用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上使用它进
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上运行。如果您想让它同时在两个屏幕上运行,请删除该选项。没有什么比鼠标点击时的力检测更有效的了。