Home > Web Front-end > JS Tutorial > How to use jQueryMobile to achieve sliding page turning effect_jquery

How to use jQueryMobile to achieve sliding page turning effect_jquery

WBOY
Release: 2016-05-16 16:15:55
Original
1519 people have browsed it

The example in this article describes how to use jQueryMobile to achieve the sliding page turning effect. Share it with everyone for your reference. The specific analysis is as follows:

Swipe gestures are very popular on mobile devices and are very common in swiping to turn pages on mobile devices

Although this function can be implemented in jQueryMobile, I personally agree with the views in the previous article [Analysis of the difficulty of dragging actions in jQuery mobile browsers], because this is in a mobile browser Browsing is not an independent APP of Android, so do not frequently use mobile device gestures other than clicking to avoid conflict with the gestures of the mobile browser and the mobile system itself.

So, how to use jQueryMobile to achieve the effect of sliding page turning?

1. Basic goals

Realize the sliding gesture page turning function in the jQueryMobile frame page in the mobile browser, as shown below:

And records the number of pages on the current page, which will automatically increase and decrease as the user slides.

2. Production process

Regarding how to arrange the interface of JqueryMobile, I will not go into details. For details, please read the previous article [Helloworld and page switching methods of jQueryMobile]

The following code comments mainly describe how to implement the above page by processing the sliding gestures jQuery Mobile Swipeleft and jQuery Mobile Swiperight encapsulated by JqueryMobile, W3C "jQuery Mobile Touch Events" The description of this is problematic, and the experimental code is not consistent with the code given:

Copy code The code is as follows:
 
 
 
 
a 
 
 
 
 
 
 
 
 
 
 
 
 
 
   

Title

 
 
 
 
 
 
 
     
 
       

你好1

 
     
 
       
       
       
       
     
 
        /4 
     
 
 
 
 
 
 
     
 
     
     
           
  • a
  •  
           
  • b
  •  
           
  • c
  •  
         
 
   
 
     
 
  
  



<script> <br> /* In the jquery part, first define a variable that records how many pages have been turned */ <br> var divnum=1; <br> /* Equivalent to .innerhtml=""; jquery needs to set the value of a node like this */ <br> $("#divnumber").text(divnum) <br> /* Enable touch on #mypage */ <br> $(document).on("pageinit","#mypage",function(){ <br> /* If you slide the non-blank part of div1 to the left, then div1 will be hidden, div2 will be displayed, and the page counter will be 1, and the inline text of divnumber will be updated */ <br>            $("#div1").on("swipeleft",function(){ <br>                $("#div1").hide("fast"); <br>                 $("#div2").show("fast"); <br>               divnum=divnum 1; <br>                  $("#divnumber").text(divnum) <br>          }); <br> /* If you slide the non-blank part of div2 to the right, then div1 will be displayed, div2 will be hidden, and the page counter will be -1, and the inline text of divnumber will be updated */ <br>              $("#div2").on("swiperight",function(){                                                          $("#div1").show("fast"); <br>                $("#div2").hide("fast"); <br>             divnum=divnum-1; <br>                  $("#divnumber").text(divnum) <br>          }); <br> /* If you slide the non-blank part of div2 to the left, then div2 will be hidden, div3 will be displayed, and the page counter will be 1, and the inline text of divnumber will be updated, and so on */ <br>           $("#div2").on("swipeleft",function(){ <br>                $("#div2").hide("fast"); <br>                $("#div3").show("fast"); <br>               divnum=divnum 1; <br>                  $("#divnumber").text(divnum) <br>          }); <br>            $("#div3").on("swiperight",function(){ <br>                 $("#div2").show("fast"); <br>                 $("#div3").hide("fast"); <br>             divnum=divnum-1; <br>                  $("#divnumber").text(divnum) <br>          }); <br>            $("#div3").on("swipeleft",function(){ <br>                 $("#div3").hide("fast"); <br>                $("#div4").show("fast"); <br>               divnum=divnum 1; <br>                  $("#divnumber").text(divnum) <br>          }); <br>              $("#div4").on("swiperight",function(){                                                        $("#div3").show("fast"); <br>                $("#div4").hide("fast"); <br>             divnum=divnum-1; <br>                  $("#divnumber").text(divnum) <br>                                                           }); <br></script>

Please note that div1 does not have a swipe right gesture because this is the first page, and div4 does not have a swipe left gesture because it is the last page.

I hope this article will be helpful to everyone’s jQueryMobile program design.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template