我有一个问题,在安卓设备上,ClearInterval命令不能工作。如果我在IOS上使用它,它会很有魅力!非常清晰,但在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);
});发布于 2016-11-23 18:52:20
来自https://github.com/TNT-RoX/android-swipe-shim
在一些安卓设备上,当用户触摸屏幕时触发一个touchstart事件,Android将事件传递给WebView (javascript)来处理。如果WebView不预防默认情况(在200 to内),Android将恢复本机滚动,并停止将触摸事件传递给WebView。
解决这一问题的方法主要是在touchstart上使用preventDefault并使用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);
});https://stackoverflow.com/questions/40770036
复制相似问题