Android浏览器:touchcancel被解雇althought touchmove有preventDefault [英] Android browser: touchcancel being fired althought touchmove has preventDefault

查看:244
本文介绍了Android浏览器:touchcancel被解雇althought touchmove有preventDefault的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图建立一个网页,检测来自用户的触摸和拖动和对象沿画布。

I'm trying to build a Webpage that senses the touch from the user and drags and object along the canvas.

所以我在做这样的事情:

So I'm doing something like this:

var touchStart = function(e) {
    e.preventDefault();
    // Do stuff
}
var touchMove = function(e) {
    e.preventDefault();
    console.log("Touch move");
    // Move objs
}
var touchEnd = function(e) {
    e.preventDefault();
    console.log("Touch start!");
    // clean up stuff
}
var touchCancel = function(e) {
    e.preventDefault();

    // Oh NO touch cancel!
    console.log("Touch cancel!");

}
bindElemOrig.addEventListener('touchstart', touchStart, false);
bindElemOrig.addEventListener('touchmove', touchStart, false);
bindElemOrig.addEventListener('touchend', touchStart, false);
bindElemOrig.addEventListener('touchcancel', touchStart, false);

它正常工作,直到某一点。

It works fine until some point.

现在的问题是,一旦我加载了太多的OBJ文件,这在我看来,在 touchmove 时间过长回应,和 touchcancel 被触发。现在的问题是,一旦 touchcancel 被触发我没有收到任何*的 touchmove 的*发生的事件,我无法感知运动了。

The problem is that as soon as I load too many objs, it seems to me that the touchmove takes too long to respond, and touchcancel gets triggered. The problem is that as soon as touchcancel get triggered I don't receive any more *touchmove*s events, and I cannot sense the movement anymore.

有没有人遇到这个问题?我知道在Android上的错误,你必须调用的 preventDefault touchend事件在IOS的WebKit不费一枪?),但在这种情况下,它似乎是不工作的,因为记忆负担。

Did anyone face this problem? I know about the bug in Android where you must call preventDefault (touchend event in ios webkit not firing?) but on this case it seems that it is not working because of the memory burden.

感谢您!

推荐答案

像这样

var touchMove = function(e) {
    e.preventDefault();
    setTimeout(function(){
        console.log("Touch move");
    // Move objs

    })
}

使用setTimeout的包裹你的逻辑在touchmove可以解决这个问题。

use setTimeout to wrap you logic in touchmove can solve this problem

这篇关于Android浏览器:touchcancel被解雇althought touchmove有preventDefault的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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