How do I detect two fingers at touchstart in javascript?

前端 未结 1 1414
栀梦
栀梦 2021-02-18 17:48

I am using .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.

相关标签:
1条回答
  • 2021-02-18 18:12

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

    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
    });
    
    0 讨论(0)
提交回复
热议问题