Can't get coordinates of touchevents in Javascript on Android devices

拥有回忆 提交于 2019-11-30 01:28:34

FINAL EDIT: Ok I got it working, if anyone finds this and has a similar problem you need to access the touch array within the event, and if just using a single touch (rather than multi touch) take the first item out of the array, as below, or you may need to offset it if that isn't accurate:

var touch = event.touches[0];
var x = touch.pageX;
var y = touch.pageY;
// or taking offset into consideration
var x_2 = touch.pageX - canvas.offsetLeft;
var y_2 = touch.pageY - canvas.offsetTop;

Didn't work for me (in iScroll 5 context). Used changedTouches[0] instead, as proposed in mouse click event.pagex is NaN in mobile chrome browser (v30.0.1599.92).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!