I'm using the taphold event in my project and need the coordinates of the point where the user tapped. Unfortunately, event.clientX and event.clientY are undefined (cp. my example here). Is there a possibility to get these coordinates similar to the onclick-event?
Thanks in advance!
The clientX property returns the horizontal coordinate (according to the client area) of the mouse pointer when a mouse event was triggered. The client area is the current window. Tip: To get the vertical coordinate (according to the client area) of the mouse pointer, use the clientY property.
However, in jQuery Mobile, Ajax is used to load the contents of each page into the DOM as you navigate, and the DOM ready handler only executes for the first page. To execute code whenever a new page is loaded and created, you can bind to the pageinit event.
You will need to cheat a bit, I made a working example for you: http://jsfiddle.net/Gajotres/STLWn/
$(document).on('vmousedown', function(event){
holdCords.holdX = event.pageX;
holdCords.holdY = event.pageY;
});
$(document).on('taphold', function(e){
alert('X: ' + holdCords.holdX + ' Y: ' + holdCords.holdY );
});
var holdCords = {
holdX : 0,
holdY : 0
}
Tested on desktop Firefox, Android 4.1.1 Chrome and iPad 6.0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With