2011-11-29 85 views
26

似乎jQuery手機在啓動頁面附加了加載消息。我真的不知道發生了什麼事情,但考慮下面這個簡單的代碼片段:jQuery手機將「加載標題」附加到頁面

<!DOCTYPE html> 
<html> 
    <head> 
    <title>sadFace</title> 
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no;" /> 
    <meta charset="utf-8" /> 
    <script src="http://code.jquery.com/jquery-1.6.4.min.js"></script> 
    <script src="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.js"></script> 
    </head> 
    <body> 
    <h1>;__;</h1> 
    </body> 
</html> 

我甚至不得不向下滾動以查看加載消息。所以我認爲這可能會發生,因爲我沒有遵循典型的jQuery手機網頁解剖結構,但是:

<!DOCTYPE html> 
<html> 
    <head> 
    <title>Page Title</title> 
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.5.2.min.js"></script> 
    <script type="text/javascript" src="http://code.jquery.com/mobile/1.0a4.1/jquery.mobile-1.0a4.1.min.js"></script> 
</head> 
<body> 
<div data-role="page"> 
    <div data-role="header"> 
     <h1>;_;</h1> 
    </div><!-- /header --> 

    <div data-role="content"> 
     <p>Same shit, different page.</p>  
    </div><!-- /content --> 

    <div data-role="footer"> 
     <h4><a href="http://www.google.com/pacman/">need cookies :C</a></h4> 
    </div><!-- /footer --> 
</div><!-- /page --> 
</body> 
</html> 

相同。我完全被這種行爲震驚。即使從上週開始我的項目,我也測試jQuery1.0rc2具有相同的結果,它看起來很好。這是怎麼回事<。 <

仰望jQuery Mobile' js我認爲這initializePage: function()是負責的消息。我可以註釋掉

//cue page loading message 
$.mobile.showPageLoadingMsg(); 

或設置autoInitializePage: false但我寧可選擇這不涉及修改的jQuery文件的解決方案(除非它是一個bug)。

回答

37

您必須添加CSS過,那麼這將是罰款:

<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.css" /> 

詳細:

它總是把下面的HTML在你的身體的底部:

<div class='ui-loader ui-body-a ui-corner-all'><span class='ui-icon ui-icon-loading spin'></span><h1></h1></div> 

這是相關的CSS(所以也許你可以自己玩,如果你想)

.ui-loading .ui-loader { display: block; } 
.ui-loader { display: none; position: absolute; opacity: .85; z-index: 100; left: 50%; width: 200px; margin-left: -130px; margin-top: -35px; padding: 10px 30px; } 

功能showPageLoadingMsg添加CSS類「的.ui加載」到HTML標記,然後將它變爲可見

+0

除了CSS和所有這些框架都做同樣令人討厭的事情 - 並試圖覆蓋基本元素的佈局首選項,如 ... –

+0

我該如何阻止它放置h1? – Jayen

16

您可以通過以下之前,您加載jQuery的移動圖書館停止autoInitializePage

jQuery(document).on("mobileinit", function() { 
    jQuery.mobile.autoInitializePage = false; 
}); 

此處瞭解詳情:http://api.jquerymobile.com/global-config/

2

添加到您的JS文件的頂部

$.mobile.autoInitializePage = false;