0

I want to have a swipe function in my first html page of the mobile application that I am implementing.

I use Phonegap 2.9 and Eclipse. For this function, I used from this files the Page_scrolling.html and the JavaScripts it calls.


My head in .html file that I want to have the swipe function:

<head>
<meta name="viewport" content="width=device-width,initial-scale=1">
<meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">

<title>Guide-Me For-All</title>

<link href='http://fonts.googleapis.com/css?family=Patrick+Hand|Permanent+Marker|Exo|Nunito|Limelight|Ubuntu|Montserrat|Audiowide|Architects+Daughter' rel='stylesheet' type='text/css'>

<!-- import stylesheets -->
<link rel="stylesheet" type="text/css" href="../../css/home/home.css">
<link rel="stylesheet" type="text/css" href="../../css/home/home-eng-fonts.css">

<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.4/jquery.mobile-1.4.4.min.css" />
<link rel="stylesheet" href="../../jQuery-Mobile-Bootstrap-Theme-master/themes/Bootstrap.css">

<!-- <link href="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.2.2/css/bootstrap-combined.min.css" rel="stylesheet">
     <link href="http://twitter.github.com/bootstrap/assets/js/google-code-prettify/prettify.css" rel="stylesheet" /> -->
 <link href="css/main.css" type="text/css" rel="stylesheet" />

<!-- import js --> 
<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.4.4/jquery.mobile-1.4.4.min.js"></script>

<script type="text/javascript" charset="utf-8" src="../../cordova.js"></script>

<script type="text/javascript" charset="utf-8" src="../../jss/connect.js"></script>

<script type="text/javascript" charset="utf-8" src="../../jss/home/change_page.js"></script>

<script type="text/javascript" src="https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js"></script>
<script type="text/javascript" src="../../plugins/jquery.touchSwipe.min.js"></script>
<script type="text/javascript" src="../../plugins/js/main.js"></script>

<script src="../../plugins/swipe.js"></script>

According to the link, I needed the last .css link and the last four .js links. The forth JavaScript is the one that is inside the Page_scrolling.html in the tutorial I put above. The only file that I changed, is the last JavaScript:


My Swipe.js contains :

$(function() {      
  $("#trust_us").swipe( { swipeLeft:swipe2, swipeRight:swipe2} );
  $("#how_it_works").swipe( { swipeLeft:swipe2, swipeRight:swipe2} );
  $("#owners").swipe( { swipeLeft:swipe2, swipeRight:swipe2} );
  $("#sign_up_in").swipe( { swipeLeft:swipe2, swipeRight:swipe2} );
  //Swipe handlers.
  function swipe1(event, direction, distance, duration, fingerCount) {
    $(this).text( "You have swiped " + direction +' with ' + fingerCount +' fingers' );
  }

  function swipe2(event, phase, direction, distance) {
    $(this).text( phase +" you have swiped " + distance + "px in direction:" + direction );
  }
});

//{ swipeStatus:swipe2, allowPageScroll:"horizontal"}

My body file is divided in the divs I want to swipe:

 <body> 
    <div id="logo">
        <img id="lg" src="../../imgs/logo.png" alt="Logo">    
    </div>


    <div id="trust_us">
        <div id="trust_us_h2">
            <h3>Why you should trust us :</h3>
        </div>
                            
        <ul>
            <li><p>All the info about the shops, are being validated with their owners.</p></li>
            <li><p>You can send your thoughts or complaints to the shops' owners, so that they will do improvements to it. *</p></li>
        </ul>

        <div id="notice">*Only for occasions when there was a contact between administrator - shop's owner!</div>   
    </div> <!--trust us-->

    <div id="how_it_works">
        <div id="how_it_works_h2">
            <h3>How it works :</h3>
        </div>
                                
        <div id="first">
            <h5>First:</h5>
        </div>
                                                        
        <div id="Sign_Up" class="float-left">
            <img  src="../../imgs/1sign-up.png" alt="Sign-Up">
            <p>  1. Register</p>
        </div>
                                                    
        <div id="Rate" class="float-right">
            <img  src="../../imgs/5rate.png" alt="Rate">    
            <p>5. Rate it according to your experience</p>
        </div>  
                                                    
    </div> <!--how it works-->


    <div id="owners">
        <div id="owners_h2">
            <h3>For the owners of a shop :</h3>
        </div>
                                                
        <ol>
            <li><p>Register</p></li>
            <li><p>After that, you can take interesting reports and useful statistics about your shop. *</p></li>
            <li><p>Now, you can do improvements to your shop according to what the customers need so you can get even more of them.</p></li>
        </ol>

        <div id="notice">*Contact the admin of the app for more information.</div>
    </div> <!--owners-->

    <div id="sign_up_in">
        <h2>...REGISTER NOW OR SIGN IN...</h2>
        <a href="#" data-role="button" data-theme="f" data-icon="heart" onclick="change_page();">Sign-Up Now!</a>
    </div>

    
    <div id="last_line">
        <br>
    </div>
    
    <div id="footer">
        <p>Copyright (c) 2014 Guide-Me For-All. Design by Marialena S.</p>
    </div>
 </body>

What Is happening right now, Is when I swipe to the left or to the right a div, it disappears and in it's place it appears a message. And all the divs are in a vertical row. There are all viewable from the start when you scroll the page. What I want now, is when I swipe to the right the first div for example, to display the second div. In the same way I want to do the swipe to left function to display the previous div. That's all. I tried many other options but this looks the most simple.

Community
  • 1
  • 1
  • Swipe pages or Scrolling down the page? if its for scrolling have a look at this question i answered --- http://stackoverflow.com/questions/25968141/jquery-mobile-listviews-lazy-loading/25968972#25968972 – Tasos Sep 29 '14 at 18:04
  • The specific example does both swipe and scrolling.... Scrolling is working as I checked now (I will update my css), but the swipe does't work. The one page is down of another. –  Sep 29 '14 at 18:17
  • you don't really need Iscroll-swipe for UP DOWN swipes. there is a function for JQM to do that. -- http://stackoverflow.com/questions/17131815/how-to-swipe-top-down-jquery-mobile -- you just the need to animate how many pixels you want to scroll down or up after the swipe. – Tasos Sep 29 '14 at 19:25
  • and how about my `.html` file? what do I have to write there? I mean in my example, i divide to `
    –  Sep 29 '14 at 19:37
  • Yes exactly. give your pages or elements id's and then create a function eg ($( '#page1" ).on("swipeup", function(){ scroll to next page or elenment });) -- check here for an example how to use iscroll to scroll to another element or check SO on how to do that-- http://stackoverflow.com/questions/21448992/scroll-to-element-in-iscroll -- becareful though because you are mixing iscroll with a swipe up so they may get confused between the 2 events ie scrolling and swipeing – Tasos Sep 29 '14 at 21:11
  • In the second link you sent me, I managed to run the [code](https://github.com/mattbryson/TouchSwipe-Jquery-Plugin/tree/master/demos) I needed that was in a comment( a link). It detects the swipe movement. I used only the `Page_scrolling.html` from those files and the `JavaScripts` it calls . In the JavaScript, the important code is this: `$("#trust_us").swipe( swipeLeft:swipe2, swipeRight:swipe2} );` as you can check in the example. But, it does only call a function that prints a message on the div's place after I swipe a div. I only want to change the divs. And, I don't want iScroll at last. –  Sep 29 '14 at 23:07

1 Answers1

0

I couldn't find the solution to my problem but I found this very nice tutorial and it's really simple to to do the swipe function.

But if anyone finds my mistakes to the above code, please post the answer so that I can learn how to do the swipe function with this method too.