简体   繁体   English

有什么方法可以使用JavaScript检测“强制点击”吗?

[英]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. 侦听webkitmouseforcewillbeginwebkitmouseforcedown事件。 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.

相关问题 JavaScript / jQuery-是否可以检测点击类型? - JavaScript / jQuery - Any way to detect click type? 任何方法来检测ctrl +在osx浏览器中单击javascript? 没有jQuery - any way to detect ctrl + click in javascript for osx browsers? no jQuery PowerShell JavaScript按钮单击是否有任何“强制命令”? - PowerShell JavaScript Button Click is there any Force Command? 有没有办法'模拟'右键单击save-as命令或强制在浏览器中使用JavaScript下载文件? - Is there any way to 'simulate' right-click save-as command or force download of file in the browser with JavaScript? 有没有办法检测 React JS 中的中间点击? - Is there any way to detect middle click in React JS? 有没有办法检测用户在javascript弹出窗口中的点击? - Is there any way to detect user clicks in the javascript popup? 有什么方法可以检测javascript中字母的最低点吗? - Is there any way to detect lowest point of a letter in javascript? 有什么方法可以强制在 javascript 循环中重新绘制 DOM 元素? - Is there any way to force repaint of DOM element inside javascript loop? 有没有办法在基于webkit的浏览器中强制使用Javascript垃圾收集器? - Is there any way to force the Javascript Garbage Collector in webkit based browsers? 强制点击javascript页面 - Force a Click on a javascript page
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM