当我尝试检查 this jsbin demo 中的 touchmove
事件时它在 Chrome 和 Opera for Android 中只触发一次,之后立即触发 touchcancel
事件,而不是继续触发 touchmove
事件?
基于 the W3C specs ,以及 touchmove
事件在 Firefox for Android 和 Android 的默认浏览器中的行为,在我看来触摸事件的工作方式应该是 touchmove
当触摸仍在页面上时,事件会不断触发。在trying to test in this 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
)然后拖动屏幕(touchstart
)时发生的情况、touchmove
和 touchcancel
)。同样的specs上面提到,touchcancel 事件应该仅在某些东西干扰时运行,例如浏览器界面(如果我理解正确的话)。
由于我只是用手指在 body 上滑动,根本没有离开 window ,我对此感到非常困惑,所以有人知道为什么会这样吗?
我在 Chrome 32 和 Opera 19 for Android 中得到了这个意想不到的结果。
最佳答案
原来这里的问题只是事件处理程序中没有 event.preventDefault()
,所以原始操作仍在执行,这显然中断了触摸事件。要解决此问题,只需在当前事件处理函数中添加 e.preventDefault()
即可取消当前事件,并使其在 Chrome 和 Opera 中也能正常工作。
关于javascript - Android 浏览器无法正确处理 touchmove 事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21761514/