4

当我尝试在这个 jsbin 演示touchmove中检查事件时,它只在 Chrome 和 Opera for Android 中触发一次,然后立即触发一个事件,而不是继续触发事件?touchcanceltouchmove

根据W3C 规范以及 Firefox for Android 和 Android 的默认浏览器中的事件行为,在touchmove我看来,触摸事件的工作方式应该是touchmove在触摸仍然在页。不过,在尝试在此 jsbin 中进行测试后,我收到以下日志消息:

touchstart event; starting on (140,197) on the screen, or (381,536) on the page.
touchend event; starting on (undefined,undefined) on the screen, or (undefined,undefined) on the page.
touchstart event; starting on (181,137) on the screen, or (492,372) on the page.
touchmove event; starting on (182,153) on the screen, or (495,416) on the page.
touchcancel event; starting on (undefined,undefined) on the screen, or (undefined,undefined) on the page.

这就是我第一次点击屏幕(通过touchstart和显示touchend)然后拖动屏幕(touchstarttouchmove)时发生的情况touchcancel。按照上面提到的相同规范,touchcancel 事件应该在有干扰时运行,例如浏览器界面(如果我理解正确的话)。

由于我只是在身体上滑动手指,根本没有离开窗户,我对此感到非常困惑,所以有人知道为什么会发生这种情况吗?

我在Chrome 32Opera 19 for Android 中得到了这个意想不到的结果。

4

1 回答 1

7

事实证明这里的问题只是事件处理程序中没有一个event.preventDefault()事实,所以原始动作仍然执行,这显然中断了触摸事件。要解决此问题,只需添加e.preventDefault()当前事件处理函数以取消当前事件,并使其在 Chrome 和 Opera 中也能按预期工作。

工作演示

于 2014-02-13T19:10:19.373 回答