使用jquerymobile和phonegap for android的滑动function不起作用

我是手机上的新手。我正在使用phonegap为android在eclipse中创建应用程序。我在xml文件夹中添加了手机gap.jar和插件。我还添加了jquery库和phonegap1.1.0 js。 我试图实现滑动function,将一个页面导航到另一个页面,但它无法正常工作。可以告诉我们如何解决问题吗?

我在我的活动中使用inex.html调用这是我的index.html

  sample check        

  • Swipe Right to smple check page

这是我的js文件包含在内

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

谢谢你的帮助

我遇到了同样的问题,除了Android之外,所有刷卡事件都有效。 要解决此问题,我必须为滑动事件设置阈值。 您可以在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. 

这个答案对我帮助很大: 在jquery mobile中垂直滚动时触发了swipeleft / swiperight

以及文档: 事件 – >触摸事件 – >滑动

希望这可以帮助!!

尝试类似于此的代码,看看它是否有任何帮助。

 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 (  

你可以试试这个

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

我正在使用jquery mobile 1.2.0来刷页面。 此function不依赖于phonegapcordova 。 这是我的工作代码。 希望对你有帮助:

 $(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 }); }); });