Функция прокрутки не работает с использованием jquerymobile и phonegap для Android

Я новичок в phonegap. Я создаю приложение в eclipse, используя phonegap для Android. Я добавил телефон gap.jar и плагин в папку xml. Я также добавил библиотеку jquery и phonegap1.1.0 js. Я пытаюсь реализовать функцию прокрутки для перехода с одной страницы на другую, но она не работает. Кто-нибудь может сказать, как решить проблему?

Я вызываю inex.html в своей деятельности, это мой index.html

<html>
    <head>
        <title>sample check</title>
        <link rel="stylesheet" href="www/jquery.mobile/jquery.mobile-1.0rc2.min.css" type="text/css" charset="utf-8" />

        <script type="text/javascript" src="js/fnswipe.js"></script>
        <script type="text/javascript" src="www/jquery.mobile/jquery-1.6.4.min"></script>
        <script type="text/javascript" src="www/jquery.mobile/jquery.mobile-1.0rc2.min.js"></script>
        <script type="text/javascript" charset="utf-8" src="phonegap-1.1.0.js"></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 smple check page</li> 
                    </ul> 
                </p> 
            </div> 
        </div> 
    </body>
</html>

Это мой файл js включен

$("#listitem").swiperight(function() { 
    $.mobile.changePage("file:///android_asset/www/samplecheck.html"); 
}); 

Спасибо за вашу помощь


person kumar    schedule 25.01.2012    source источник
comment
Попробуйте $(#listitem).live('swiperight', function() {   -  person Paul Beusterien    schedule 25.01.2012
comment
@paulBeusterien, я использую приведенный выше код, но он все еще не работает   -  person kumar    schedule 27.01.2012
comment
Вы можете попробовать обновиться до последней версии PhoneGap 1.3.0 и jQuery 1.0 (также доступно, если вы обновите свой плагин Eclipse AppLaud)   -  person Paul Beusterien    schedule 27.01.2012
comment
У меня тоже не работало свайп вправо/влево на моем андроиде. Вы пробовали другой метод смахивания (не помню название банкомата)?   -  person Johan    schedule 01.03.2012


Ответы (4)


У меня была такая же проблема, все события смахивания работали, кроме Android. Чтобы решить эту проблему, мне пришлось установить пороговые значения для событий Swipe. Вы можете установить их непосредственно перед вызовом событий смахивания в файле JS. Для достижения наилучших результатов я установил:

$.event.special.swipe.scrollSupressionThreshold = 10; // More than this horizontal displacement, and we will suppress scrolling.
$.event.special.swipe.horizontalDistanceThreshold = 30; // Swipe horizontal displacement must be more than this.
$.event.special.swipe.durationThreshold = 500;  // More time than this, and it isn't a swipe.
$.event.special.swipe.verticalDistanceThreshold = 75; // Swipe vertical displacement must be less than this.

Этот ответ мне очень помог: swipeleft/swiperight срабатывает во время вертикальной прокрутки в мобильном jquery

А также документацию: События -> Touch Events -> Swipe

Надеюсь это поможет!!

person William Delong    schedule 04.10.2013

Попробуйте код, похожий на этот, и посмотрите, поможет ли он каким-либо образом.

function( event ) {
  var data = event.originalEvent.touches ?
      event.originalEvent.touches[ 0 ] : event;
  return {
      time: ( new Date() ).getTime(),
      coords: [ data.pageX, data.pageY ],
      origin: $( event.target )
    };
}
)

And the when the swipe stops (

function( event ) {
  var data = event.originalEvent.touches ?
      event.originalEvent.touches[ 0 ] : event;
  return {
      time: ( new Date() ).getTime(),
      coords: [ data.pageX, data.pageY ]
    };
}
)

This method receives the start and stop objects and handles the logic for and triggering for the swipe events.

(

function( start, stop ) {
  if ( stop.time - start.time < $.event.special.swipe.durationThreshold &&
    Math.abs( start.coords[ 0 ] - stop.coords[ 0 ] ) > $.event.special.swipe.horizontalDistanceThreshold &&
    Math.abs( start.coords[ 1 ] - stop.coords[ 1 ] ) < $.event.special.swipe.verticalDistanceThreshold ) {

    start.origin.trigger( "swipe" )
      .trigger( start.coords[0] > stop.coords[ 0 ] ? "swipeleft" : "swiperight" );
  }
}
)

HTMl code (

<script>
$(function(){
  // Bind the swipeHandler callback function to the swipe event on div.box
  $( "div.box" ).on( "swipe", swipeHandler );

  // Callback function references the event target and adds the 'swipe' class to it
  function swipeHandler( event ){
    $( event.target ).addClass( "swipe" );
  }
});
</script> 
person Community    schedule 05.02.2014

ты можешь попробовать это

$("#listitem").on("swiperight", function() { 
    $.mobile.changePage("file:///android_asset/www/samplecheck.html"); 
});
person user2270213    schedule 11.04.2013

Я использую jquery mobile 1.2.0 для пролистывания страницы. Эта функция не зависит от phonegap или cordova. Это мой рабочий код. Надеюсь, что это поможет вам:

$(document).bind("pageinit", function(event) {
    $('#page').unbind("swipeleft");
    $("#next").unbind("swiperight");

     $("#page").bind("swipeleft",function(event) {
        $.mobile.changePage('next.html',  {
            transition : "slide"
        });
     });

     $("#next").bind("swiperight",function(event) {
        $.mobile.changePage('index.html', {
            transition : "slide",
            reverse : true  
        });
     });
});
person Pradip Kharbuja    schedule 04.06.2013