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.
- 1 e.originalEvent.touches[0].pageX – Wasim A. Commented Jun 12, 2015 at 10:55
1 Answer
Reset to default 25After 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.