Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I detect two fingers at touchstart in javascript?

Tags:

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.

like image 332
Arvind Rohit Avatar asked Jul 04 '14 05:07

Arvind Rohit


People also ask

How do I use Touchmove event?

The touchmove event occurs when the user moves the finger across the screen. The touchmove event will be triggered once for each movement, and will continue to be triggered until the finger is released. Note: The touchmove event will only work on devices with a touch screen.

Does touch trigger click event?

Because mobile browsers should also work with with web applications that were build for mouse devices, touch devices also fire classic mouse events like mousedown or click . When a user follows a link on a touch device, the following events will be fired in sequence: touchstart.


1 Answers

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.addEventListener('touchstart', function (e) {   if(e.touches.length > 1) {     // ... do what you like here   } }); 

Or with jQuery:

$someElement.on('touchstart', function (e) {   if (e.touches.length > 1) {     // ... do what you like here   } }); 
like image 103
Tudmotu Avatar answered Oct 26 '22 23:10

Tudmotu