Getting Ipad Code Reference Coordinates

I would like to get touch event coordinates on ipad in javascript. How can I do it?

+6
source share
4 answers

I believe this should do the trick:

var x = event.targetTouches[0].pageX, y = event.targetTouches[0].pageY; 


Update:
Here is an example:

 <!doctype html> <html lang="en" class="no-js"> <head> <meta charset="utf-8"> <title>Touch event test</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script> </head> <body> <script> $(function() { var $log = $("#log"); function updateLog(x, y) { $log.html('X: '+x+'; Y: '+y); } document.addEventListener('touchstart', function(e) { updateLog(e.changedTouches[0].pageX, e.changedTouches[0].pageY); }, false); document.addEventListener('touchmove', function(e) { e.preventDefault(); updateLog(e.targetTouches[0].pageX, e.targetTouches[0].pageY); }, false); }); </script> <div id="log"></div> </body> </html> 
+6
source

Try using:

 x = event.originalEvent.pageX; y = event.originalEvent.pageY; 
+3
source

This is an old question, but there is no answer, and the solution in my case with the iPad was lower:

 var x = event.originalEvent.touches[0].clientX; var y = event.originalEvent.touches[0].clientY; 
0
source

Try this js script .. The program works in all major browsers and all touch devices. In this code, I provide how to find the coordinates of a touchstart.

http://jsfiddle.net/vecny/

-1
source

Source: https://habr.com/ru/post/889702/


All Articles