我有一个问题,在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);
});
答案 0 :(得分:1)
来自https://github.com/TNT-RoX/android-swipe-shim:
在某些Android设备上,当用户触摸屏幕时触摸开始 事件被触发,Android将事件传递给WebView(javascript)即可 处理。如果WebView没有阻止默认(200ms内),Android 恢复本机滚动并停止将触摸事件传递给WebView。
解决这个问题的方法主要是防止touchstart上的默认设置并使用javascript手动滚动。
var touchticker = null,
touchtickerint = null,
volumeup = $("#volumeup"),
isAndroid = /Android/i.test(navigator.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);
});