javascript 如何在javascript中的touchstart处检测两个手指?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24567441/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 03:03:26  来源:igfitidea点击:

How do I detect two fingers at touchstart in javascript?

javascript

提问by Arvind Rohit

I am using .on("touchstart mousedown",function (e) {pTouchDown(e)});

我正在使用 .on("touchstart mousedown",function (e) {pTouchDown(e)});

Its working with one finger touch, but I want to do some operation with two-finger touch too.

它用一根手指触摸工作,但我也想用两根手指触摸做一些操作。

回答by Tudmotu

The touch events contain a property, called touches, which contains all the touch points available. You can read more about TouchEvents on MDN.

触摸事件包含一个名为 的属性,touches其中包含所有可用的触摸点。你可以在 MDN 上阅读更多关于 TouchEvents 的信息。

In your case, you would need to check the length of the touchesproperty:

在您的情况下,您需要检查touches属性的长度:

$someElement.on('touchstart', function (e) {
    if (e.touches.length > 1)
        // ... do what you like here
});