How to return X and Y coordinates when using jquery.hammer.js

DFania picture DFania · Jun 30, 2013 · Viewed 11.5k times · Source

I am programming a little page using jquery.hammer.js and I have having problems getting the x and y coordinates of a touch event.

my code is as follows:

var x1, y1;
var element = document.getElementById("myDIV")
$(element).hammer().on("touch", function(e){
x1 = e.clientX
y1 = e.clientY

document.getElementById("resultDIV").innerHTML = x1 + " " + y1
}

but all I get is "undefined undefined" as my result.

i have everything i can think of, any help is much appreciated.

Answer

hudidit picture hudidit · Aug 17, 2014

e.gesture is deprecated now. With the latest version of Hammer.js, you should use

var tapX, tapY;
tapX = e.center.x;
tapY = e.center.y;