今天我发生了以下事情:我有一个现有的 mousemove
事件并稍后添加了 touchmove
,如下所示:
$(window).on "mousemove touchmove", (e) ->
pos_x = e.pageX
pos_y = e.pageY
不幸的是,这两个变量在移动设备上都未定义
。
最佳答案
过了一会儿,我修好了。触摸有不同的事件。你可以这样解决:
$(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
我希望这对其他人有帮助。
关于javascript - event.pageX/Y 不适用于 touchmove,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30477868/