Small white Learn jQuery mobile "building cross-platform App:jquery Mobile mobile app" serial Four (scene toggle)

Source: Internet
Author: User

As a really useful application, there should be at least two pages in the first place, and more interaction can be achieved by switching the page. For example, mobile phone Renren, the first to enter the login page, login will be new, and then open the left side of the panel, you can see albums, Whispers, applications and other content.

In jquery Mobile, the page switch is done by link, which is exactly the same as HTML. The difference is that JQuery mobile provides 10 different switching effects to enable developers to create good interactivity. Let's look at an example:

"Example 4-4 the scene switch in JQuery mobile"

  1. <! DOCTYPE>
  2. <HTML xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <Meta http-equiv= "content-type" content= "text/html; Charset=utf-8 " />
  5. <Meta name= "viewport" content="width=device-width,initial-scale=2">
  6. <title> Toggle between pages </title>
  7. <link rel= "stylesheet" href="jquery.mobile-1.0.min.css" />
  8. <script src="Jquery-1.7.1.min.js"></script>
  9. <script src="Jquery.mobile-1.1.1.min.js"></script>
  10. <!--<script type= "Text/javascript" src= "Cordova.js" ></script>-->
  11. </head>
  12. <body>
  13. <div data-role="page">
  14. <!-using the default switching mode, the effect is fade-->
  15. <a href="demo.html" data-role= "button"> Toggle between pages </a>
  16. <!--data-transition= "fade" definition Toggle mode fade
  17. <a data-role= "button" href="demo.html" data-transition="Fade" data-direction= "Reverse">fade</a>
  18. <!--data-transition= "pop" definition switching mode spread --
  19. <a data-role= "button" href="demo.html" data-transition="Pop" data-direction= "Reverse">pop</a>
  20. <!--data-transition= "Flip" to define the toggle mode --
  21. <a data-role= "button" href="demo.html" data-transition="Flip" data-direction= "Reverse">flip</a>
  22. <!--data-transition= "turn" to define the toggle mode rollover Overlay --
  23. <a data-role= "button" href="demo.html" data-transition="Turn" data-direction= "Reverse">turn</a>
  24. <!--data-transition= "Flow" defines the switching mode diffusion overlay --
  25. <a data-role= "button" href="demo.html" data-transition="Flow" data-direction= "Reverse">flow</a>
  26. <!--data-transition= "Slidefade" defines the toggle mode slide Fade --
  27. <a data-role= "button" href="demo.html" data-transition="Slidefade" > Slidefade</a>
  28. <!--data-transition= "slide" defines the toggle mode swipe --
  29. <a data-role= "button" href="demo.html" data-transition="Slide" data-direction= "Reverse">slide</a>
  30. <!--data-transition= "Slidedown" defines the toggle mode swipe down --
  31. <a data-role= "button" href="demo.html" data-transition="Slidedown" > Slidedown</a>
  32. <!--data-transition= "slideup" definition toggle swipe up -
  33. <a data-role= "button" href="demo.html" data-transition="Slideup" >slideup </a>
  34. <!--data-transition= "None" Definition Toggle Mode "None" -
  35. <a data-role= "button" href="demo.html" data-transition="None" data-direction= "Reverse">none</a>
  36. </div>
  37. </body>
  38. </html>

In addition, another page is required demo.html:

  1. <! DOCTYPE>
  2. <HTML xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <Meta http-equiv= "content-type" content= "text/html; Charset=utf-8 " />
  5. <Meta name= "viewport" content="width=device-width,initial-scale=2">
  6. <title> Untitled document </title>
  7. <link rel= "stylesheet" href="jquery.mobile-1.0.min.css" />
  8. <script src="Jquery-1.7.1.min.js"></script>
  9. <script src="Jquery.mobile-1.1.1.min.js"></script>
  10. <!--<script type= "Text/javascript" src= "Cordova.js" ></script>-->
  11. </head>
  12. <body>
  13. <div data-role="page">
  14. <H1> Come in my bowl. </H1>
  15. </div>
  16. </body>
  17. </html>

Run the effect 4-4, shown in Figure 4-5.

Fig. 4-4 Fig. 4-5

The 14th to 24th line in the example above actually does the same thing, that is, the switch from the index.html page to the demo.html page is implemented. Here is a brief description of the 10 switching effects in particular:

<a href= "demo.html" data-role= "button" > Switch between pages </a>

You can see clearly that the demo.html page has a fade animation effect.

<a data-role= "button" href= "demo.html" data-transition= "Fade" data-direction= "reverse" >fade</a>

After running, the effect is the same as not adding the Data-transition property, that is, in jquery Mobile, the transition will be added to the fade fade animation effect by default.

<a data-role= "button" href= "demo.html" data-transition= "Pop" data-direction= "reverse" >pop</a>

The demo page gradually becomes larger in the center of the original page and eventually covers the entire page.

<a data-role= "button" href= "demo.html" data-transition= "Flip" data-direction= "Reverse" >flip</a>

The demo page initially appears as a vertical bar in the center of the original page, expanding to the ends and enlarging to the normal page scale until the entire page is covered.

<a data-role= "button" href= "demo.html" data-transition= "turn" data-direction= "reverse" >turn</a>

The demo page is initially flipped vertically with a vertical bar in the center of the original page and then zoomed in to cover the entire page.

<a data-role= "button" href= "demo.html" data-transition= "Flow" data-direction= "reverse" >flow</a>

The demo page gradually becomes larger in the center of the original page and gradually covers the entire page, while the original page is gradually reduced until it is completely triansitions2 covered.

<a data-role= "button" href= "demo.html" data-transition= "Slidefade" data-direction= "reverse" >slidefade</a >

The demo page appears on the right side of the original page, moves to the center, and fade in the process.

<a data-role= "button" href= "demo.html" data-transition= "slide" data-direction= "reverse" >slide</a>

The demo page appears on the right side of the original page and moves to the center.

<a data-role= "button" href= "demo.html" data-transition= "slideup" data-direction= "reverse" >slideup</a>

The demo page appears below the original page and moves up to the center.

<a data-role= "button" href= "demo.html" data-transition= "Slidedown" data-direction= "reverse" >slidedown</a >

The demo page appears above the original page and moves down to the center.

<a data-role= "button" href= "demo.html" data-transition= "None" data-direction= "Reverse" >none</a>

Without any effect.

Note: In the above 10 kinds of animations, in addition to the fade and none two effects are supported by all browsers, the other 8 effects of the implementation of the need to rely on the device browser with 3D support. As a result, many effects are invalid for Android 2.Xs devices, and the switch effect is converted to fade by default. There are also some devices that can achieve these effects, but due to the hardware itself limitations, in the implementation of these effects will be at the end of the lag and page flicker problems. So developers have to be very cautious when using these effects, but as technology improves, devices that are incompatible with these effects will eventually exit our horizons, which is good news for developers.

In the official jquery mobile document is given a way to deal with the incompatibility, that is, in the CSS file to add such a code, after the author's experiment, it is true to a certain extent, to solve the problem of screen flash switching.

.ui-page {-webkit-backface-visibility: hidden; }

But to really fundamentally solve the problem of screen switching, but also rely on the development of hardware, the author has been convinced that the day will come soon.

Jquerymobile availability is getting higher, the entry threshold is low, and you can write less code to create a mobile-friendly interface. "Building cross-platform App:jquery Mobile mobile app" This book uses an instance-driven approach to introduce app development under Jquerymobile, which provides more than 70 practical cases to teach readers to develop mobile Finally, through 6 small projects to review and consolidate the knowledge points learned.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.