简体   繁体   English

Android 4.2.2中的Jquery Mobile滑动事件无法正常工作

[英]Jquery Mobile swipe events in Android 4.2.2 not working

I have written a mobile web application that uses the JQuery mobile swipeleft and swiperight events but these are not working on a Samsung Galaxy S4 running Android 4.2.2. 我编写了一个使用JQuery移动swipeleft和swiperight事件的移动Web应用程序,但这些不适用于运行Android 4.2.2的三星Galaxy S4。 Running the web application in either the standard web browser or in Chrome has the same issue: the swipe events are not detected. 在标准Web浏览器或Chrome中运行Web应用程序具有相同的问题:未检测到滑动事件。

The following is how I am trying to detect the events which works fine in other devices I have tested it on, even Android devices (but not Android 4.2.2): 以下是我试图检测在我测试过的其他设备上工作正常的事件,甚至是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;
}
});

Is there anything I can do, code-wise, to capture these events in Android 4.2.2? 在Android 4.2.2中有什么我可以做的,代码方式来捕获这些事件吗?

You are having two problems here. 你在这里有两个问题。

First is caused by a bug in JQM that has been resolved but is not yet implemented https://github.com/jquery/jquery-mobile/issues/5534 首先是由JQM中已经解决但尚未实现的错误引起的https://github.com/jquery/jquery-mobile/issues/5534

Basically the min distance measured by the swipe event must take into account the pixel density of the device. 基本上,滑动事件测量的最小距离必须考虑设备的像素密度。 So in JQM's case, the following change to touch.js will solve the issue: 所以在JQM的情况下,touch.js的以下更改将解决问题:

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

The second is todo with kitkat firing a touchcancel instead of a touchend. 第二个是todo与kitkat发射touchcancel而不是touchend。 The solution is to delegate touchcancel to touchend. 解决方案是将touchcancel委托给touchend。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM