javascript - Android 浏览器无法正确处理 touchmove 事件

标签 javascript android touch touchmove

当我尝试检查 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.

这是我第一次点击屏幕(通过 touchstarttouchend)然后拖动屏幕(touchstart)时发生的情况、touchmovetouchcancel)。同样的specs上面提到,touchcancel 事件应该在某些东西干扰时运行,例如浏览器界面(如果我理解正确的话)。

由于我只是用手指在 body 上滑动,根本没有离开 window ,我对此感到非常困惑,所以有人知道为什么会这样吗?

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

最佳答案

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

Working demo .

关于javascript - Android 浏览器无法正确处理 touchmove 事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21761514/

相关文章:

javascript - 使用带有 requireJS 的 Node 包客户端?

javascript - 查找 tr 中的复选框是否被选中

javascript - Jquery 和 Bootstrap 应该放在 HTML 文件的什么位置?

javascript - KineticJS 对图像应用多个滤镜,我还看到了一个色调滤镜

java - 具有图像叠加中心和滚动行为的工具栏

java - 找不到模块 '<unknown>' 的 JDK 'appcompatV7'

javascript - 在 PC 浏览器上模拟触摸事件

CSS3 下拉菜单悬停不起作用

java - 在Java中分别显示阿拉伯/波斯字母/字符?

相当于 'mouseleave' 的 javascript,用于触摸交互