簡體   English   中英

如何在jQuery Mobile中更改默認加載ajax加載器gif

[英]how to change the default load ajax loader gif in jquery mobile

我已經看過jquery mobile的文檔,但是不知道如何將其集成到我的移動網站上。 文檔在這里

http://jquerymobile.com/demos/1.2.0-pre/docs/pages/loader.html

實際上,gif圖像在2.x android設備上沒有動畫,因此我正在考慮制作僅預加載小部件的文本。

我試圖通過這樣的CSS更改它

.ui-icon-loading {
            background: url(themes/images/custom-ajax-loader.gif);
        }

但是新的imag無法正確縮放,並且舊的背景仍然可見。

我對javascript完全陌生。有人可以幫我嗎?

您提到的是jQM 1.2 Alpha文檔,因此我的答案基於此jQM版本。

您可以在下面找到2個更改默認加載程序映像的選項。

解決方案1

如jQM 1.2 Alpha Docs所述:

jQuery Mobile啟動時,它將觸發文檔對象上的mobileinit事件。 要覆蓋默認設置,請綁定到mobileinit。 由於mobileinit事件是立即觸發的,因此您需要在加載jQuery Mobile之前綁定事件處理程序。 按以下順序鏈接到您的JavaScript文件:

 <script src="jquery.js"></script> <script src="custom-scripting.js"></script> <script src="jquery-mobile.js"></script> 

要全局配置加載對話框,可以在mobileinit事件期間在其原型上定義以下設置:

$( document ).bind( 'mobileinit', function(){
  $.mobile.loader.prototype.options.text = "loading";
  $.mobile.loader.prototype.options.textVisible = false;
  $.mobile.loader.prototype.options.theme = "a";
  $.mobile.loader.prototype.options.html = "";
});

在下面,您可以找到一個有效的示例,您可以在其中完全自定義html prototype選項中的加載程序。

例:

<!DOCTYPE html> 
<html> 
    <head> 
        <title>Page Title</title> 
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <link rel="stylesheet" href="http://code.jquery.com/mobile/1.2.0-alpha.1/jquery.mobile-1.2.0-alpha.1.min.css" />
        <script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
        <script>
            $(document).bind( 'mobileinit', function(){
              $.mobile.loader.prototype.options.text = "loading";
              $.mobile.loader.prototype.options.textVisible = true;
              $.mobile.loader.prototype.options.theme = "a";
              $.mobile.loader.prototype.options.textonly = false;
              $.mobile.loader.prototype.options.html = "<span class='ui-bar ui-overlay-c ui-corner-all'><img src='../images/my-custom-image.png' /><h2>loading</h2></span>";
            });
        </script>
        <script src="http://code.jquery.com/mobile/1.2.0-alpha.1/jquery.mobile-1.2.0-alpha.1.min.js"></script>
        <script>
            $(document).on("click", ".show-page-loading-msg", function() {          
                $.mobile.loading('show');
            });
        </script>
    </head> 

    <body>
        <!-- /page -->
        <div data-role="page" class="page-map" style="width:100%; height:100%;">
            <!-- /header -->
            <div data-role="header" data-theme="b">
                <h1>Test</h1>
            </div>
            <!-- /content -->
            <div data-role="content" class="ui-bar-c ui-corner-all ui-shadow" style="padding:1em;">
                <button class="show-page-loading-msg">Click</button>
            </div>
        </div>
    </body>
</html>

解決方案2

覆蓋用於描述頁面加載器的默認CSS樣式。

EDITED

對於jQM 1.1.1版本 ,有以下可配置選項:

  • loadingMessage字符串,默認值:“ loading”
    設置頁面加載時顯示的文本。 如果設置為false,則完全不會顯示該消息。
  • loadingMessageTextVisible布爾值,默認值:false
    顯示加載消息時,文本是否應可見。 對於加載錯誤,該文本始終可見。
  • loadingMessageTheme字符串,默認值:“ a”
    文本可見時,加載消息框使用的主題。

代碼示例:

<!DOCTYPE html> 
<html> 
    <head> 
        <title>Page Title</title> 
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <link rel="stylesheet" href="http://code.jquery.com/mobile/1.1.1/jquery.mobile-1.1.1.min.css" />
        <script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
        <script>
            $(document).bind( 'mobileinit', function(){
               $.mobile.loadingMessageTheme = 'e';
               $.mobile.loadingMessageTextVisible = true;
                $.mobile.loadingMessage = "test";
            });
        </script>
        <script src="http://code.jquery.com/mobile/1.1.1/jquery.mobile-1.1.1.min.js"></script>
        <script>
            $(document).on("click", ".show-page-loading-msg", function() {          
                $.mobile.showPageLoadingMsg();
            });
        </script>
    </head> 

    <body>
        <!-- /page -->
        <div data-role="page" class="page-map" style="width:100%; height:100%;">
            <!-- /header -->
            <div data-role="header" data-theme="b">
                <h1>Test</h1>
            </div>
            <!-- /content -->
            <div data-role="content" class="ui-bar-c ui-corner-all ui-shadow" style="padding:1em;">
                <button class="show-page-loading-msg">Click</button>
            </div>
        </div>
    </body>
</html>

此外,您可以嘗試覆蓋用於設置jQM加載程序樣式的默認CSS。 更具體地說,您可以修改或覆蓋部分加載屏幕中的樣式以及用於描述頁面加載器的部分加載圖標中的樣式。

您將在此處找到jQM 1.1.1中使用的CSS。

/* loading icon */
.ui-icon-loading {
    background: url(images/ajax-loader.gif);
    background-size: 46px 46px;
}

/* loading screen */
.ui-loading .ui-loader { display: block; }
.ui-loader { display: none; z-index: 9999999; position: fixed; top: 50%; left: 50%; border:0; }
.ui-loader-default { background: none; opacity: .18; width: 46px; height: 46px; margin-left: -23px; margin-top: -23px; }
.ui-loader-verbose { width: 200px; opacity: .88; box-shadow: 0 1px 1px -1px #fff; height: auto; margin-left: -110px; margin-top: -43px; padding: 10px; }
.ui-loader-default h1 { font-size: 0; width: 0; height: 0; overflow: hidden; }
.ui-loader-verbose h1 { font-size: 16px; margin: 0; text-align: center; }
.ui-loader .ui-icon { background-color: #000; display: block; margin: 0; width: 44px; height: 44px; padding: 1px; -webkit-border-radius: 36px; -moz-border-radius: 36px; border-radius: 36px; }
.ui-loader-verbose .ui-icon { margin: 0 auto 10px; opacity: .75; }
.ui-loader-textonly { padding: 15px; margin-left: -115px; }
.ui-loader-textonly .ui-icon { display: none; }
.ui-loader-fakefix { position: absolute; }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM