在Android 4.x的touchmove后Touchend不触发?Android、Touchend、touchmove

2023-09-07 16:18:54 作者:从别后忆相逢

我写了一些code用JavaScript就像这样:

I am writing some code with javascript just like this:

    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 /萨法航空和Android 2.x.x这code做工精细。在Android 4.x版(我试过4.0.4&安培; 4.1),touchmove后touchend不点火。如果我点击屏幕,不要动我的手指,touchend将被解雇。

This code work fine on IOS/safair and android 2.x.x . On android 4.x(I tried 4.0.4 & 4.1) , touchend not firing after touchmove. If I tap the screen, don't move my finger, touchend will be fired.

如何解决这一问题?

这是镀铬的一个bug,细节在这里:http://$c$c.google.com/p/chromium/issues/detail?id=152913

This is a bug of chrome, the detail is here: http://code.google.com/p/chromium/issues/detail?id=152913

推荐答案

我相信如果你叫即preventDefault()在touchstart或touchmove它将停止该事件被吸收了它击中你的ontouchend处理程序之前。我没有一个设备现在在这里想试试,但:)

I believe if you call e.preventDefault() in touchstart or touchmove it will stop the event being soaked up before it hits your ontouchend handler. I dont have a device here to try it on right now though :)