Swiping in Cordova with Jquery and jgestures

被刻印的时光 ゝ 提交于 2019-12-20 02:05:14

问题


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?


回答1:


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);

Or perhaps you simply need to define the function onDeviceReady BEFORE you call the event listener.



来源:https://stackoverflow.com/questions/15063030/swiping-in-cordova-with-jquery-and-jgestures

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!