When using jquery mobile development, sometimes we need to display the load prompt box during the request for Ajax (for example: a rotated picture + a hint: loading ... )。 This time, we can manually display the jquery mobile loader, the approximate process is as follows:
1. Boot loader, display "Loading ...";
2. Make an AJAX request, update the page data after the request is completed, and refresh the jquery mobile control style;
3. Close the loader.
Here's how to manually display the loader in jquery Mobile 1.2.0 and 1.1.0 (very simply, a few lines of code will be OK!). )。
The first is the jQuery Mobile 1.2.0 Reference:
[HTML]View Plaincopy
- <! DOCTYPE HTML>
- <html>
- <head>
- <title>ajax test </title>
- <meta charset="GBK">
- <meta name="viewport" content="width=device-width, initial-scale=1">
- <!--from the official downloaded file in the project's Jquery-mobile directory --
- <link rel= "stylesheet" href="jquery-mobile/jquery.mobile-1.2.0.min.css"/>
- <link rel= "stylesheet" href= "jquery-mobile/jquery.mobile.structure-1.2.0.min.css " />
- <script src="Jquery-mobile/jquery-1.8.2.min.js"></script>
- <script src="Jquery-mobile/jquery.mobile-1.2.0.min.js"></script>
- <head>
Write JavaScript functions:
[JavaScript]View Plaincopy
- <script>
- Display Loader
- function Showloader () {
- //Display loader. For jQuery Mobile 1.2.0
- $.mobile.loading (' show ', {
- Text: ' loading in ... ', //loader display
- Textvisible: True, //Whether the text is displayed
- Theme: ' A ', //loader theme style A-e
- TextOnly: false, //Whether only text is displayed
- HTML: "" //HTML content to display, slices, etc.
- });
- }
- Hides the loader. For JQuery Mobile 1.2.0
- function Hideloader ()
- {
- //Hide Loader
- $.mobile.loading (' hide ');
- }
- </script>
Prepare two buttons, one for the launcher (display) loader, and one for the Stop (hide) Loader:
[HTML]View Plaincopy
- <body>
- <div data-role="page">
- <!--head --
- <div data-role="header">
- <h3>ajax test </h3>
- </div>
- <!--content --
- <div data-role="Content">
- <h3>ajax test </h3>
- <input type="button" value="show Ajax loader" onclick="Showloader ()"/>
- <input type="button" value="Hide ajax loader" onclick="Hideloader ()"/>
- </div>
- </body>
The effect is as follows (subject: ' A '):
Of course, you can adjust the $.mobile.loading (' show ', {...} Experiment with different loader effects in the parameters.
for details of the loader, see the jquery Mobile 1.2.0 official demo demo :
Http://jquerymobile.com/demos/1.2.0/docs/pages/loader.html
Note: The Ajax loader shown in JQuery Mobile1.1.0 is completely different from the 1.2.0 version! Hang Daddy!
The code for the JQuery Mobile 1.1.0 display loader is as follows:
[JavaScript]View Plaincopy
- <script>
- //Display loader
- function Showloader () {
- //Display loader. For jQuery Mobile 1.1.0
- $.mobile.loadingmessage = ' loading in ... '; //display of text
- $.mobile.loadingmessagetextvisible = true; //Whether to display text
- $.mobile.loadingmessagetheme = ' a '; //loader theme style A-e
- $.mobile.showpageloadingmsg (); //Display loader
- }
- //Hide loader. For jQuery Mobile 1.1.0
- function Hideloader () {
- //Hide Loader
- $.mobile.hidepageloadingmsg ();
- }
- </script>
The effect of the display is quite similar.
The description of 1.1.0 in the official 1.2.0 documentation is as follows:
The page Loading dialog is previously configured globally with three settings
$.mobile.loadingmessage,
$.mobile.loadingmessagetextvisible, and
$.mobile.loadingmessagetheme
Which is now deprecated. In addition to the methods for showing and hiding,
$.mobile.showpageloadingmsg and
$.mobile.hidepageloadingmsg is also deprecated.
This means: in 1.2.0, the $.mobile.showpageloadingmsg and $.mobile.hidepageloadingmsg are not used to display the loader.
Have questions welcome to the exchange of questions!
JQuery Mobile Displays the Ajax loader manually, prompting for loading ...