最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Android browser touch event location - Stack Overflow

programmeradmin2浏览0评论

On Safari, you can get the location of where the user touched the screen from event.pageX and event.pageY. However, on my Android browser, event.pageX and event.pageY are always 0. Is there any way to get the location of a touch event in the browser on Android?

On Safari, you can get the location of where the user touched the screen from event.pageX and event.pageY. However, on my Android browser, event.pageX and event.pageY are always 0. Is there any way to get the location of a touch event in the browser on Android?

Share Improve this question asked Dec 3, 2011 at 23:07 VinceVince 5899 silver badges16 bronze badges 1
  • Could you elaborate a bit on what you're trying to acplish? Are you also interested in native options? E.g. like with any view, you can hook up a OnTouchListener to WebView and request the touch coordinates. Obviously, this will not work when zoomed in though. If you're after specific page elements, getHitTestResult() might also be worth looking at. – MH. Commented Dec 4, 2011 at 2:45
Add a ment  | 

1 Answer 1

Reset to default 8

This is from memory, since I don't own an Android device anymore, but I think it's right. At the very least, it should get you started in the right direction. Good luck.

var elem = document.getElementById('elem');
elem.addEventListener('touchend', function(e){
    var pageX = e.changedTouches[0].pageX,
        pageY = e.changedTouches[0].pageY;
}, false);
发布评论

评论列表(0)

  1. 暂无评论