I am trying to implement a drag/move action on an SVG element using Javascript. I am using event handlers such as this:
function handleMouseDown(evt) {
currentX = evt.offsetX;
currentY = evt.offsetY;
dX = currentX - Number($(evt.srcElement).attr("x"));
dY = currentY - Number($(evt.srcElement).attr("y"));
isDragging = true;
$info.html("mousedown at " + currentX + ", " + currentY); //feedback for debugging
}
Note that I already have code to point either mousedown or touchstart to handleMouseDown, depending on whether it is a touch device or not.
On my desktop, the code works fine on IE9, Google and Safari. However on an iPad, on touchstart, the feedback shows "mousedown at undefined, undefined." If I replace .offsetX and .offsetY with .pageX and .pageY, then I get actual coordinates. So it seems Safari Mobile does not handle .offsetX and .offsetY, but it does handle .pageX and .pageY.
I know that I can calculate .offsetX from pageX using the source elements position.left property, but I would like to avoid this if possible. SO MY QUESTION IS: is there something wrong in my code or approach, or is .offsetX not handled in Safari Mobile.
Any help greatly appreciated!