Android WebView TouchMove错误

时间:2019-06-06 22:01:27

标签: android webview touch-event

我正在开发一个Android WebView App,由于某种原因,“ touchmove”事件拒绝触发。它可以在桌面浏览器上正常工作。我该如何解决?也不在android模拟器上工作。

document.body.addEventListener("touchstart", function (e) {
    console.log("touchstart", e);
    e.preventDefault();
    e.stopPropagation();
});
document.body.addEventListener("touchmove", function (e) {
    console.log("touchmove", e); // <--- refuses to fire
    e.preventDefault();
    e.stopPropagation();
});
document.body.addEventListener("touchend", function (e) {
    console.log("touchend", e);
    e.preventDefault();
    e.stopPropagation();
});

1 个答案:

答案 0 :(得分:3)

您可能需要采取以下解决方法:

var onTouchEnd = function(){
  console.log("touch end");
}
document.addEventListener("touchstart", onTouchEnd);
document.addEventListener("touchmove", onTouchEnd);
document.addEventListener("touchend", onTouchEnd);

尝试这样操作它

var onTouchEnd = function(){
  console.log("touch end");
  var touch = event.changeTouches[0];
  console.log("touch", touch);
}
document.addEventListener("touchstart", onTouchEnd);
document.addEventListener("touchmove", onTouchEnd);
document.addEventListener("touchend", onTouchEnd);