7

今天我发生了以下事情:我有一个现有的mousemove事件,touchmove后来又添加了,像这样:

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

不幸的是,这两个变量都undefined在移动设备上。

4

1 回答 1

21

过了一会儿,我修好了。触摸有不同的事件。你可以像这样解决它:

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

我希望这对其他人有帮助。

于 2015-05-27T09:06:46.360 回答