I was trying to use pointer events (e.g. pointerdown
) instead of combining touch (e.g. touchstart
) and mouse (e.g. mousedown
) events to figure out the input event coordinates.
var bodyElement = document.body;
bodyElement.addEventListener("touchstart", function(e) {console.log("touch: " + e.changedTouches[0].clientX + " " + e.changedTouches[0].clientY);});
bodyElement.addEventListener("pointerdown", function(e) {console.log("point: " + e.clientX + " " + e.clientY);});
All works fine until the viewport gets zoomed (e.g. android chrome zooms the webpage, device toolbar zoom factor in chrome's dev tools is other than 100%, ...). The pointer events then start reporting completely wrong values.
You can observe the error in following screenshots:
1) viewport scaled to 100%, 300px*300px div clicked to bottom right corder:
2) viewport scaled to 150%, 300px*300px div clicked to bottom right corner:
Do you guys know how to get the correct coordinates from pointer events?
Edit:
Added jsfiddle: jsfiddle