Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get touch coordinates in iOS Safari

I am using the below code to get the touch coordinates in iOS Safari

$('#touchable').bind('touchstart', function(e){

        alert(e.touches[0].pageX);
        alert(e.touches[0].pageY);
}

But when I test it I am unable to get the coordinates. Is this code the right way to get the touch coordinates ?

like image 614
ajaybc Avatar asked Nov 16 '25 14:11

ajaybc


1 Answers

Prefer the following link :

Detect Safari Touch

and try this code

document.addEventListener('touchmove', function(e) {
    e.preventDefault();
    var touch = e.touches[0];
    alert(touch.pageX + " - " + touch.pageY);
}, false);

to add touchEvent.

like image 89
Prince Kumar Sharma Avatar answered Nov 19 '25 05:11

Prince Kumar Sharma



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!