Android 不会清除时间间隔

Android wont clear time interval

我有一个问题,在 android 设备上,ClearInterval 命令不起作用。如果我在 IOS 上使用它,它会很有魅力!完全清除,但在 android 上它不会清除我。为什么是这样?老实说,我想不通!我 运行 一些警报,它正在进入 touchstart,touchend 和超时运行完美,但它的时间间隔不会被清除!

我的代码:

var touchticker = null;
var touchtickerint = null;

//TouchStart Volume UP
$("#volumeup").on("touchstart", function() {
    touchticker = setTimeout(function() {
        touchtickerint = setInterval(function() 
        {
            $("#volumeup").click();
        }, 100);
    }, 500);
});

//TouchEnd Clear Timeout
$(document).on("touchend", function() 
{
    clearInterval(touchtickerint);
    clearTimeout(touchticker);
});

来自https://github.com/TNT-RoX/android-swipe-shim

On some Android devices when the user touches the screen a touchstart event is fired, Android passes the event to WebView (javascript) to be handled. If WebView does not preventdefault (within 200ms), Android resumes native scrolling and stops passing touch events to WebView.

这个问题的解决方案主要是在触摸启动时防止默认并使用 javascript 手动滚动。

var touchticker = null,
    touchtickerint = null,
    volumeup = $("#volumeup"),
    isAndroid = /Android/i.test(navigato​r.userAgent);

//TouchStart Volume UP
volumeup.on("touchstart", function(event) {
    if (isAndroid) { event.preventDefault(); volumeup.click(); }
    touchticker = setTimeout(function() {
        clearInterval(touchtickerint);
        touchtickerint = setInterval(function() {
            volumeup.click();
        }, 100);
    }, 500);
});

//TouchEnd Volume UP, Clear Timeout
$(document).on('touchend touchcancel', function() {
    clearInterval(touchtickerint);
    clearTimeout(touchticker);
});