Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery mobile: clientX and clientY and the taphold event

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!

like image 511
sbaltes Avatar asked Feb 20 '13 13:02

sbaltes


People also ask

What is clientX and clientY?

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.

What does jQuery mobile use to handle page events?

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.


1 Answers

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

like image 158
Gajotres Avatar answered Nov 14 '22 23:11

Gajotres