ajaybc
ajaybc

Reputation: 4059

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 ?

Upvotes: 3

Views: 2861

Answers (1)

Prince Kumar Sharma
Prince Kumar Sharma

Reputation: 12641

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.

Upvotes: 3

Related Questions