禁用在Android浏览器中触发touchcancel [英] Disable the firing of touchcancel in Android Browser
问题描述
我正在制作一个使用JavaScript触摸事件的移动网站。在iOS Safari和Chrome for Android中,一切正常,但Android浏览器(版本4.1.2)给我带来了麻烦。
I am making a mobile website that uses JavaScript touch events. Things work fine in iOS Safari and Chrome for Android, but the stock Android Browser (version 4.1.2) is giving me trouble.
在触摸过程中, touchstart
和 touchmove
按预期调用事件。但是, touchmove
处理程序执行的操作之一似乎会触发过早的 touchcancel
事件。 (我不确定这是否重要,但触发 touchcancel
的操作是修改SVG对象的 viewBox
属性。)如果我注释掉这个动作,触摸过程会正常进行(即完成 touchmove
到 touchend
)。
During a touch process, the touchstart
and touchmove
events are called as expected. However, one of the actions performed by the touchmove
handler seems to trigger a premature touchcancel
event. (I'm not sure whether this is significant, but the action that triggers the touchcancel
is the modification of an SVG object's viewBox
attribute.) If I comment out this action, the touch process proceeds normally (i.e., completion of touchmove
through to touchend
).
我的所有触摸处理程序都调用 preventDefault()
函数,所以问题不在这个bug中描述的那个: https://code.google.com/p/android/问题/细节?id = 19827 。
All of my touch handlers call the preventDefault()
function, so the issue isn't the one that's described in this bug: https://code.google.com/p/android/issues/detail?id=19827.
我读过很多浏览器之间的不一致关于何时 touchcancel
叫做。 Android浏览器是唯一一个对我来说有问题的浏览器。
I've read that there is a lot of inconsistency among browsers as to when touchcancel
is called. The stock Android browser is the only one that is problematic for me.
有解决方法吗?例如,有没有我可以完全禁用 touchcancel
事件?我的另一个想法是让 touchcancel
处理程序以编程方式触发另一个 touchstart
/ touchmove
事件,但我没有那么远。任何想法都将不胜感激。
Is there a workaround out there? For example, is there away I can completely disable the touchcancel
event? Another idea I had was to have the touchcancel
handler programmatically trigger another touchstart
/touchmove
event, but I didn't get very far with that. Any ideas would be appreciated.
推荐答案
如果您正在使用hammer.js,您可以禁用指针事件(这会导致像这个),通过添加:
删除window.PointerEvent;
在index.html中加载hammer.js之前,它将忽略这些事件。
你也可以设置SUPPORT_POINTER_EVENTS = false; (v2.0.8的第384行)做同样的事情。
理想情况下,开发人员会增加关闭它的能力,但开源难度也是如此......
If you are useing hammer.js, you can disable pointer-events (which cause problems like this), by adding:
delete window.PointerEvent;
in your index.html PRIOR to loading hammer.js, and it will ignore those events.
You can also set SUPPORT_POINTER_EVENTS = false; (line 384 of v2.0.8) to do the same thing.
Ideally the devs would add the ability to turn this off, but so goes the open source dilemma...
这篇关于禁用在Android浏览器中触发touchcancel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!