Jquery Mobile 在 Android 4.2.2 中滑动事件不起作用

Jquery Mobile swipe events in Android 4.2.2 not working

本文关键字:事件 不起作用 Jquery Android Mobile      更新时间:2023-09-26

我编写了一个使用JQuery移动向左滑动和向右滑动事件的移动Web应用程序,但这些在运行Android 4.2.2的三星Galaxy S4上不起作用。 在标准网络浏览器或 Chrome 中运行网络应用也存在相同的问题:未检测到滑动事件。

以下是我尝试检测在我测试过的其他设备中运行良好的事件的方式,甚至是 Android 设备(但不是 Android 4.2.2):

$('#showImage').on("swipeleft", function (event) {
if (currentScale != initialScale) return;
if (currentPage < maxPage) {
  ++currentPage;
  img.src = document.getElementById("page" + zeroPad(currentPage, 2) + "url").value;
}
});
$('#showImage').on("swiperight", function (event) {
if (currentScale != initialScale) return;
if (currentPage > 1) {
  --currentPage;
  img.src = document.getElementById("page" + zeroPad(currentPage, 2) + "url").value;
}
});

在代码方面,我可以做些什么来捕获 Android 4.2.2 中的这些事件?

你在这里有两个问题。

首先是由 JQM 中的一个错误引起的,该错误已解决但尚未实现 https://github.com/jquery/jquery-mobile/issues/5534

基本上,滑动事件测量的最小距离必须考虑设备的像素密度。因此,在 JQM 的情况下,以下更改 touch.js 将解决问题:

horizontalDistanceThreshold = window.devicePixelRatio >= 2 ? 15 : 30;
verticalDistanceThreshold = window.devicePixelRatio >= 2 ? 15 : 30;

第二种是奇巧发射触摸取消而不是触摸端。解决方案是将触摸取消委托给触摸端。