Android浏览器:touchcancel被解雇althought touchmove有preventDefault浏览器、touchcancel、Android、preventDefault

2023-09-05 01:29:26 作者:Accompagne-moi fou 陪我疯

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

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