如何在javascript中检测touchstart上的两个手指? [英] How do I detect two fingers at touchstart in javascript?

查看:1020
本文介绍了如何在javascript中检测touchstart上的两个手指?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

它只用一根手指触摸。
但是我想用两个手指触摸一些操作...

it is working with one finger touch. but i want some operation with two finger touch too...

推荐答案

触摸事件包含一个属性,称为触及,其中包含所有可用的触摸点。您可以在MDN上阅读有关TouchEvents的更多信息,请访问

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

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

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

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

这篇关于如何在javascript中检测touchstart上的两个手指?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆