I'm trying to get the X position with jQuery of a touchstart event, used with the live function?
I.e.
$('#box').live('touchstart', function(e) { var xPos = e.PageX; } );
Now, this does work with 'click' as the event. How on earth (without using the alpha jQuery Mobile) do I get it with a touch event?
Any ideas?
Thanks for any help.
If you're not using jQuery... you need to access one of the event's
TouchList
s to get aTouch
object which haspageX/Y
clientX/Y
etc.Here are links to the relevant docs:
I'm using
e.targetTouches[0].pageX
in my case.Check Safari developer reference on Touch class.
According to this, pageX/Y should be available - maybe you should check spelling? make sure it's
pageX
and notPageX
I use this simple function for JQuery based project
example:
hope this will be usefull for you ;)
Kinda late, but you need to access the original event, not the jQuery massaged one. Also, since these are multi-touch events, other changes need to be made:
If you want other fingers, you can find them in other indices of the touches list.
UPDATE FOR NEWER JQUERY:
I tried some of the other answers here, but originalEvent was also undefined. Upon inspection, found a TouchList classed property (as suggested by another poster) and managed to get to pageX/Y this way: