Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

event.pageX/Y not working on touchmove

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.

like image 220
MyXoToD Avatar asked May 27 '15 09:05

MyXoToD


1 Answers

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.

like image 158
MyXoToD Avatar answered Nov 16 '22 15:11

MyXoToD