0

jquery mobile/phonegap アプリの右スワイプ イベントの次のコードがあります。

<!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>
4

2 に答える 2

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">
      ...
于 2013-01-04T15:51:54.263 に答える
0

これは、解決済みだがまだ実装されていない JQM のバグが原因ですhttps://github.com/jquery/jquery-mobile/issues/5534

基本的に、スワイプ イベントによって測定される最小距離は、デバイスのピクセル密度を考慮する必要があります。したがって、JQM の場合、touch.js を次のように変更すると問題が解決します。

horizontalDistanceThreshold = window.devicePixelRatio >= 2 ? 15 : 30;
verticalDistanceThreshold = window.devicePixelRatio >= 2 ? 15 : 30; 
于 2014-05-29T09:27:29.000 に答える