问题描述
关于使用jQuery/jQuery mobile进行刷卡操作,Stackoverflow中有很多主题.但是,它们似乎都没有按照我想要的方式工作.以下是我的phonegap应用程序的索引页面的结构.按照此主题的建议,我尝试了jgestures插件.
There are lots of topics in Stackoverflow when it comes to swiping using jQuery/jQuery mobile. However, none of them seem to work in the manner I want. The following is the structure of my index page of my phonegap app. As this topic recommended, I tried jgestures plugin.
<html>
<head>
<title>App</title>
<script type="text/javascript" src="lib/cordova-2.2.0.js"></script>
<script type="text/javascript" src="lib/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="lib/jgestures.js"></script>
</head>
<body>
<div id="home">
<div id="headersec">
<!-- some elements like images here-->
</div>
<div id="screen1">
<!-- three 80x80 images go here -->
</div>
<div id="screen2">
<!-- three other 80x80 images go here-->
</div>
</div>
</body>
</html>
在我的设备就绪事件中我要做的就是这个
All I want to do in my deviceready event is this
document.addEventListener("deviceready",onDeviceReady,false);
function onDeviceReady() {
$('#screen1').bind('swipeleft',showNext); //show next hides screen1, shows screen2
$('#screen2').bind('swiperight',showPrev);//show prev hides screen2, shows screen1
}
但是,这不适用于我尝试过的任何示例代码.任何人都可以告诉我我在做什么错吗?
But this does not work with any of the sample code I've tried.. Can anyone tell what am I doing wrong?
推荐答案
Looks like this question had a similar issue. The solution was do something like this:
document.addEventListener("deviceready", function(){
$('#screen1').bind('swipeleft',showNext); //show next hides screen1, shows screen2
$('#screen2').bind('swiperight',showPrev);//show prev hides screen2, shows screen1
},false);
或者也许您只需要在调用事件侦听器之前定义函数onDeviceReady
.
Or perhaps you simply need to define the function onDeviceReady
BEFORE you call the event listener.
这篇关于用Jquery和jgestures在Cordova中刷卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!