Android的浏览器不能正确处理touchmove事件 [英] Android browsers not handling touchmove events correctly

查看:238
本文介绍了Android的浏览器不能正确处理touchmove事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试在视察 <在 touchmove 事件STRONG>此jsbin演示 它仅适用于Chrome和Opera触发一次为Android,紧接着的是,它触发的,而不是一个 touchcancel 事件,继续触发 touchmove 事件?

When I try to inspect the touchmove event in this jsbin demo it only triggers once in Chrome and Opera for Android, and immediately after that, it triggers a touchcancel event, instead of continuing to trigger touchmove events?

根据双方 的W3C规范 ,并在这两个Android版Firefox和Android默认浏览器的 touchmove 事件的行为,在我看来,该触摸事件都应该工作的方式是该 touchmove 事件触发保留而触摸仍然在页面上。 试图在这一jsbin 测试虽然,我得到了以下日志消息:

Based on both the W3C specs, and the behaviour of the touchmove event in both Firefox for Android and Android's default browser, it seems to me that the way the touch events are supposed to work is that the touchmove event keeps triggering while the touch is still on the page. After trying to test in this jsbin though, I got the following log messages:

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 )。由同一规格的上面提到的,touchcancel事件应该去的只有的运行时的东西干扰,如浏览器界面(如果我理解正确的)。

This is what happened when I first tapped the screen (shown via a touchstart and touchend), and then dragged the screen (touchstart, touchmove and touchcancel). Going by the same specs mentioned above, the touchcancel event should only run when something interferes , such as the browser interface (if I understand that correctly).

由于我只是滑动我的手指在身,不留窗户可言,我真的这个疑惑,所以会有人知道为什么会这样?

Since I was simply sliding my finger over the body, without leaving the window at all, I am really puzzled by this, so would anybody know why this is happening?

我得到这个意外的结果的铬32 歌剧院19 为Android。

I am getting this unexpected result in Chrome 32 and Opera 19 for Android.

推荐答案

原来这里的问题只是事实的事件处理程序没有一个事件。preventDefault()在里面,所以原来的动作仍然执行,这显然打断了触摸事件。为了解决这个问题,只需添加即preventDefault()在当前的事件处理函数取消当前事件,并使其按预期在Chrome和Opera太

Turns out the problem here was simply the fact the event handler didn't have an event.preventDefault() in it, so the original action still executed, which apparently interrupted the touch event. To fix this, simply add e.preventDefault() in the current event handler function to cancel the current event, and make it work as expected in Chrome and Opera too.

工作演示

这篇关于Android的浏览器不能正确处理touchmove事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆