Android中Jquery手机/手机间隙滑动手势问题

Android中Jquery手机/手机间隙滑动手势问题,android,cordova,jquery-mobile,Android,Cordova,Jquery Mobile,在jquery mobile/phonegap应用程序中,我有以下关于滑动右键事件的代码。代码运行正常,但问题是我必须滑动3-4次才能在android设备上得到响应 <!DOCTYPE html> <html> <head> <title>Slider Stop</title> <meta http-equiv="Content-Type" content="text/html; c

在jquery mobile/phonegap应用程序中,我有以下关于滑动右键事件的代码。代码运行正常,但问题是我必须滑动3-4次才能在android设备上得到响应

<!DOCTYPE html> 
<html> 
    <head> 
        <title>Slider Stop</title> 
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <link rel="stylesheet" href="http://code.jquery.com/mobile/1.1.1/jquery.mobile-1.1.1.min.css" />
        <script type="text/javascript" src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
        <script type="text/javascript" src="http://code.jquery.com/mobile/1.1.1/jquery.mobile-1.1.1.min.js"></script>
        <script>
            $(document).on("swiperight", "#listitem", function() {
                $.mobile.changePage("#page1");
            });
        </script>
    </head> 
    <body>
        <div data-role="page" id="home">
            <div data-role="content">
                <p>
                    <ul data-role="listview" data-inset="true" data-theme="c">
                        <li id="listitem">Swipe Right to view Page 1</li>
                    </ul>
                </p>
            </div>
        </div>
        <div data-role="page" id="page1">
            <div data-role="content">
                <ul data-role="listview" data-inset="true" data-theme="c">
                    <li data-role="list-divider">Navigation</li>
                    <li><a href="#home">Back to the Home Page</a></li>
                </ul>
                <p>
                    Yeah!<br />You Swiped Right to view Page 1
                </p>
            </div>
        </div>
    </body>
</html>

滑块挡块
$(document).on(“swiperight”,“#listitem”,function()){
$.mobile.changePage(“第1页”);
});

  • 向右滑动以查看第1页

    导航
是啊
您向右滑动以查看第1页


您需要确保您的文档和设备都准备好了。我建议:

<!DOCTYPE html> 
<html> 
<head> 
    <title>Slider Stop</title> 
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.1.1/jquery.mobile-1.1.1.min.css" />
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
    <script type="text/javascript" src="http://code.jquery.com/mobile/1.1.1/jquery.mobile-1.1.1.min.js"></script>
    <script>
        function onBodyLoad() {
            document.addEventListener("deviceready", onDeviceReady, false);
        }

        function onDeviceReady() {
            // set your swipe threshold explicitly
            $.event.special.swipe.horizontalDistanceThreshold = 120;
            $(document).on("swiperight", "#listitem", function() {
                $.mobile.changePage("#page1");
            });
        }

    </script>
</head> 
<body onload="onBodyLoad()">
    <div data-role="page" id="home">
      ...

滑块挡块
函数onBodyLoad(){
文件。添加的监听器(“deviceready”,OnDeviceraddy,false);
}
函数ondevicerady(){
//明确设置刷卡阈值
$.event.special.swipe.horizontalDistanceThreshold=120;
$(document).on(“swiperight”,“#listitem”,function()){
$.mobile.changePage(“第1页”);
});
}
...

这是由JQM中已解决但尚未实现的错误引起的

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

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

您还可以考虑升级到jQuery Mobile和jQuery的最新版本。谢谢@ RoviAuthor,第一个解决方案没有工作,但是升级jQuery Mobile和jQuery工作了。