2016-11-23 89 views
0

我有一個問題,在android設備上,ClearInterval命令無法正常工作。如果我在IOS上使用它,它的魅力!完美清除,但在Android上它不會爲我清楚。爲什麼是這樣?我不能誠實地弄清楚它!我跑了一些警報,它正在進入觸發器,並且touchend和超時運行完美,但它的時間間隔不會被清除!Android不會清除時間間隔

我的代碼:

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); 
}); 

回答

1

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

在部分Android裝置當用戶觸摸一個touchstart 事件被激發屏幕,機器人將事件傳遞到web視圖(JavaScript的),以是 處理。如果WebView不能防止默認情況(在200ms內),則Android 將恢復本機滾動並停止將觸摸事件傳遞給WebView。

對此的解決方案主要是爲了防止touchstartDefault和使用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); 
}); 
+0

會給這個去,並會回來的結果!看起來很有希望。所以煩人它如何在iOS上工作,而不是android雖然,仍然不知道這是爲什麼!任何人,將回來的結果。謝謝! – irishwill200

+0

嗨@Annarfych沒有工作! – irishwill200

+0

您是否嘗試過使用完整的調用:window.clearInterval? Idk如果這會有所幫助,但也許會嘗試一下。 – Lacrioque