Jquery-mobile-jqm-custom-html

提供:Dev Guides
移動先:案内検索

jQuery Mobile-カスタムHTMLウィジェット

説明

*_data-html_* 属性を使用して、ローダーに任意のHTMLを追加できます。

次の例では、jQuery Mobileフレームワークでの_custom html widget_の使用について説明します。

<!DOCTYPE html>
<html>
   <head>
      <meta name = "viewport" content = "width = device-width, initial-scale = 1">
      <link rel = "stylesheet" href = "https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css">
      <script src = "https://code.jquery.com/jquery-1.11.3.min.js"></script>
      <script src = "https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>

      <script>
         $( document ).on( "click", ".load_msg", function() {
            var $this  =  $( this ),
            theme  =  $this.jqmData( "theme" ) || $.mobile.loader.prototype.options.theme,
            msgText  =  $this.jqmData( "msgtext" ) || $.mobile.loader.prototype.options.text,
            textVisible  =  $this.jqmData( "textvisible" ) || $.mobile.loader.prototype.options.textVisible,
            textonly  =  !!$this.jqmData( "textonly" );
            $.mobile.loading( "show", {
               text: msgText,
               textVisible: textVisible,
               theme: theme,
               textonly: textonly
            });
         })

         .on( "click", ".hide_page", function() {
            $.mobile.loading( "hide" );
         });
      </script>
   </head>

   <body>
      <button class = "load_msg" data-theme = "b" data-textonly = "true"
         data-textvisible = "true" data-msgtext = "This is custom loading..."
         data-inline = "true" data-html = <span class = "ui-bar  ui-shadow
         ui-overlay-d ui-corner-all"><img src = "/jquery_mobile/images/img1.png">
         <h2>its loading...</h2></span>This is Custom HTML</button>
      <button class = "hide_page" data-inline = "true"
         data-icon = "delete">It hides the page</button>
   </body>
</html>

出力

上記のコードがどのように機能するかを確認するために、次の手順を実行してみましょう-

  • 上記のHTMLコードを jqm_custom_htmll ファイルとしてサーバーのルートフォルダーに保存します。
  • このHTMLファイルをhttp://localhost/jqm_custom_htmllとして開くと、次の出力が表示されます。