我正在用 Javascript 编写一些代码,如下所示:
var el = document.getElementById('some-div');
el.ontouchstart = function(e){
el.innerHTML = "touch start";
};
el.ontouchend = function(e){
el.innerHTML = "touch end";
};
el.ontouchmove = function(e){
el.innerHTML = "touch moved";
};
此代码在 iOS/Safari 和 Android 2.x.x 上运行良好。在 Android 4.x 上(我尝试过 4.0.4 和 4.1),touchend 在 touchmove 后不会触发。如果我点击屏幕,不要移动手指,touchend 将被触发。
如何解决这个问题?
这是Chrome的一个bug,详细信息在这里:http://code.google.com/p/chromium/issues/detail?id=152913 http://code.google.com/p/chromium/issues/detail?id=152913
我相信,如果您在 touchstart 或 touchmove 中调用 e.preventDefault() ,它将在事件到达 ontouchend 处理程序之前停止吸收该事件。不过我现在没有设备可以尝试:)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)