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

javascript - event.pageXY not working on touchmove - Stack Overflow

programmeradmin3浏览0评论

Today I had the following thing going on: I had an existing mousemove event and added touchmove later on, like this:

$(window).on "mousemove touchmove", (e) ->
  pos_x = e.pageX
  pos_y = e.pageY

Unfortunately both variables were undefined on mobile devices.

Today I had the following thing going on: I had an existing mousemove event and added touchmove later on, like this:

$(window).on "mousemove touchmove", (e) ->
  pos_x = e.pageX
  pos_y = e.pageY

Unfortunately both variables were undefined on mobile devices.

Share Improve this question asked May 27, 2015 at 9:06 makkusumakkusu 8587 silver badges20 bronze badges 1
  • 1 e.originalEvent.touches[0].pageX – Wasim A. Commented Jun 12, 2015 at 10:55
Add a comment  | 

1 Answer 1

Reset to default 25

After a while I fixed it. There's a different event for touches. You can solve it like this:

$(window).on "mousemove touchmove", (e) ->
  touch = undefined
  if e.originalEvent.touches
    touch = e.originalEvent.touches[0]
  pos_x = e.pageX or touch.pageX
  pos_y = e.pageY or touch.pageY

I hope this will help others.

发布评论

评论列表(0)

  1. 暂无评论