Event.pageX / Y not working on touchmove

Today I had the following: I had an existing mousemove event and added touchmove later, for example:

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

Unfortunately, both variables were undefined on mobile devices.

+6
source share
1 answer

After a while I fixed it. There's another touch event. You can solve it as follows:

 $(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 

Hope this helps others.

+11
source

Source: https://habr.com/ru/post/987992/


All Articles