使用jquerymobile和phonegap for android的刷卡功能不起作用

使用jquerymobile和phonegap for android的刷卡功能不起作用,jquery,jquery-mobile,cordova,swipe,Jquery,Jquery Mobile,Cordova,Swipe,我是phonegap新手。我正在eclipse中使用phonegap for android创建应用程序。我在xml文件夹中添加了phone gap.jar和插件。我还添加了jquery库和phonegap1.1.0 js。我试图实现滑动功能,将一个页面导航到另一个页面,但它不起作用。有人能告诉我如何解决这个问题吗 我正在活动中调用inex.html 这是我的index.html <html> <head> <title>sample

我是phonegap新手。我正在eclipse中使用phonegap for android创建应用程序。我在xml文件夹中添加了phone gap.jar和插件。我还添加了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>
谢谢你的帮助

你可以试试这个

$("#listitem").on("swiperight", function() { 
    $.mobile.changePage("file:///android_asset/www/samplecheck.html"); 
});
你可以试试这个

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

我正在使用jquerymobile1.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  
        });
     });
});

我正在使用jquerymobile1.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  
        });
     });
});

我也遇到了同样的问题,除了安卓系统外,所有的刷卡事件都正常工作。为了解决这个问题,我必须为刷卡事件设置阈值。您可以在调用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.
这个答案对我帮助很大:

以及文件:


希望这有帮助

我遇到了同样的问题,除了安卓系统,所有的刷卡事件都正常工作。为了解决这个问题,我必须为刷卡事件设置阈值。您可以在调用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.
这个答案对我帮助很大:

以及文件:


希望这有帮助

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

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> 
功能(事件){
var数据=event.originalEvent.touchs?
event.originalEvent.touchs[0]:事件;
返回{
时间:(新建日期()).getTime(),
coords:[data.pageX,data.pageY],
来源:$(event.target)
};
}
)
当刷卡停止时(
功能(事件){
var数据=event.originalEvent.touchs?
event.originalEvent.touchs[0]:事件;
返回{
时间:(新建日期()).getTime(),
coords:[data.pageX,data.pageY]
};
}
)
此方法接收启动和停止对象,并处理刷卡事件的逻辑和触发。
(
功能(启动、停止){
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.verticaldistance阈值){
start.origin.trigger(“滑动”)
.trigger(start.coords[0]>stop.coords[0]?“swipleft”:“swiperight”);
}
}
)
HTMl代码(
$(函数(){
//将swipeHandler回调函数绑定到div.box上的swipe事件
美元(“div.box”)。在(“swipe”,swipeHandler)上;
//回调函数引用事件目标并向其添加“swipe”类
函数swipeHandler(事件){
$(event.target).addClass(“滑动”);
}
});

尝试类似的代码,看看是否有帮助

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> 
功能(事件){
var数据=event.originalEvent.touchs?
event.originalEvent.touchs[0]:事件;
返回{
时间:(新建日期()).getTime(),
coords:[data.pageX,data.pageY],
来源:$(event.target)
};
}
)
当刷卡停止时(
功能(事件){
var数据=event.originalEvent.touchs?
event.originalEvent.touchs[0]:事件;
返回{
时间:(新建日期()).getTime(),
coords:[data.pageX,data.pageY]
};
}
)
此方法接收启动和停止对象,并处理刷卡事件的逻辑和触发。
(
功能(启动、停止){
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.verticaldistance阈值){
start.origin.trigger(“滑动”)
.trigger(start.coords[0]>stop.coords[0]?“swipleft”:“swiperight”);
}
}
)
HTMl代码(
$(函数(){
//将swipeHandler回调函数绑定到div.box上的swipe事件
美元(“div.box”)。在(“swipe”,swipeHandler)上;
//回调函数引用事件目标并向其添加“swipe”类
函数swipeHandler(事件){
$(event.target).addClass(“滑动”);
}
});

Try$(“#listitem”).live('swiperight',function(){@paulBeusterien我使用的上述代码仍然不起作用您可以尝试更新到最新的PhoneGap 1.3.0和jQuery 1.0(如果您更新Eclipse鼓掌插件,也可以使用)。我也没有让swiperight/left在我的android上工作。您尝试过其他滑动方法吗(不记得atm的名字了)?试试$(“#listitem”).live('swiperight',function(){@paulBeusterien我使用的上面的代码仍然不起作用。你可以尝试更新到最新的PhoneGap 1.3.0和jQuery 1.0(如果你更新了EclipsePaude插件,也可以使用)我也没有让SwiperRight/left在我的android上工作。你试过另一种刷卡方法吗(不记得atm的名字)?