mobileinit event

mobileinit

mobileinit eventversion added: 1.0

Description: Event indicating that jQuery Mobile has finished loading.

  • jQuery( ".selector" ).on( "mobileinit", function( event ) { ... } )

This event is triggered after jQuery Mobile has finished loading, but before it has started enhancing the start page. Thus, handlers of this event have the opportunity to modify jQuery Mobile's global configuration options and all the widgets' default option values before they influence the library's behavior-

You must connect a handler to the mobileinit event before you load jQuery Mobile, because it is triggered as part of the library's loading process- The easiest way of achieving this is to place a script tag after the script tag that loads jQuery, and before the script tag that loads jQuery Mobile:

<!doctype html>
<html>
<head>
  <title>Example illustrating use of the "mobileinit" event</title>
  <meta charset=utf-8 />
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet"  href="/doc_/-code-jquery-com-mobile-1-4-5-jquery-mobile-1-4-5-min-css.html?lang=en" />
  <script src="//code.jquery.com/jquery-1.10.2.min.js" rel="external nofollow" ></script>
  <script>
// Update configuration to our liking
$( document ).on( "mobileinit", function() {
 
  // We want popups to cover the page behind them with a dark background
  $.mobile.popup.prototype.options.overlayTheme = "b";
 
  // Set a namespace for jQuery Mobile data attributes
  $.mobile.ns = "jqm-";
});
  </script>
  <script src="//code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js" rel="external nofollow" ></script>
</head>
<body>
  <div data-jqm-role="page">
    <div data-jqm-role="header">
      <h2>jQuery Mobile Example</h2>
    </div>
    <div data-jqm-role="content">
      <div id="the-popup" data-jqm-role="popup" data-jqm-position-to="window">
        <p>Example popup.</p>
      </div>
      <a href="#the-popup" data-jqm-rel="popup" class="ui-btn ui-corner-all ui-shadow">Open Popup</a>
    </div>
  </div>
</body>
</html>

© The jQuery Foundation and other contributors
Licensed under the MIT License.
https://api.jquerymobile.com/mobileinit

在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号

意见反馈
返回顶部