欧美国产另类久热|951超碰伊人久久|伊人影视久久久久|色婷婷亚洲小电影|色东京热69XX|婷婷玖玖深爱网|加勒比东京热网站|无码A级毛片在线观看|一级a毛一级a看|中文字幕人妻欧美

jQuery mobile在頁面加載時添加加載中效果 document.ready 和window.onload執(zhí)行順序比較
來源:易賢網 閱讀:1486 次 日期:2016-07-27 15:28:00
溫馨提示:易賢網小編為您整理了“jQuery mobile在頁面加載時添加加載中效果 document.ready 和window.onload執(zhí)行順序比較”,方便廣大網友查閱!

想要添加這個效果,先來弄明白頁面的加載和事件執(zhí)行順序,看這個簡單例子:

<html xmlns="http://www.w3.org/1999/xhtml">

<head >

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>驗證加載順序</title>

<script src="../Scripts/jquery-1.7.1.js"></script>

<link href="../Scripts/Mobile/jquery.mobile-1.4.0.min.css" rel="stylesheet" />

<script src="../Scripts/Mobile/jquery.mobile-1.4.0.min.js"></script>

<script>

alert("DOM還沒加載");

window.onload = function () {

alert('onload,圖片加載完');

}

$(document).ready(function () {

alert('ready,dom加載完');

})

</script>

</head>

<body >

<form id="form1" runat="server">

<img src="http://images.aviary.com/imagesv5/feather_default.jpg" />

<img src="http://car0.autoimg.cn/car/upload/2015/1/8/v_20150108092921264345010.jpg" />

</form>

</body>

</html>

執(zhí)行結果:9行>14行>11行,9行代碼放置的上下位置不同,結果依然是一樣的。弄明白上面的順序之后,如果想讓頁面在加載之前顯示jquery mobile的加載器,然后等頁面數據請求執(zhí)行完,圖片等多媒體加載完之后,再關閉加載器的話,就可以按照以下思路來解決:

<html xmlns="http://www.w3.org/1999/xhtml">

<head >

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>驗證加載順序</title>

<script src="../Scripts/jquery-1.7.1.js"></script>

<link href="../Scripts/Mobile/jquery.mobile-1.4.0.min.css" rel="stylesheet" />

<script src="../Scripts/Mobile/jquery.mobile-1.4.0.min.js"></script>

<script>

setTimeout('showLoader()', 100);//這里要延遲一下,直接調用無法顯示加載器

//顯示加載器.for jQuery Mobile 1.2.0

function showLoader() {

$.mobile.loading('show', {

text: '正在登陸...', //加載器中顯示的文字

textVisible: true, //是否顯示文字

theme: 'a', //加載器主題樣式a-e

textonly: false, //是否只顯示文字

html: "" //要顯示的html內容,如圖片等

});

}

//隱藏加載器.for jQuery Mobile 1.2.0

function hideLoader() {

$.mobile.loading('hide');

}

window.onload = function () {

hideLoader();

//setTimeout('hideLoader()', 5000);//延遲5秒,模擬圖片和多媒體加載耗時

}

$(document).ready(function () {

//setTimeout('hideLoader()', 5000);//延遲5秒,模擬頁面請求數據耗時,ajax異步請求等放在這里

})

</script>

</head>

<body >

<form id="form1" runat="server">

<img src="http://images.aviary.com/imagesv5/feather_default.jpg" />

<img src="http://car0.autoimg.cn/car/upload/2015/1/8/v_20150108092921264345010.jpg" />

</form>

</body>

</html>

說明:

1)9行的代碼要稍作延遲執(zhí)行,否則有可能上面引用的js文件還沒有加載完,這時候調用showLoader方法,是無法正確執(zhí)行,就不能顯示加載器

2)關閉加載器可以放在document.ready或者window.onload中,具體看頁面的執(zhí)行情況需要。

3)如果網速足夠快,兩個圖片瞬間加載完成,有可能看不到明顯的加載器顯示和關閉的過程。

以上所述是小編給大家介紹的jQuery mobile在頁面加載時添加加載中效果 document.ready 和window.onload執(zhí)行順序比較 ,希望對大家有所幫助

更多信息請查看網絡編程
關于我們 | 聯(lián)系我們 | 人才招聘 | 網站聲明 | 網站幫助 | 非正式的簡要咨詢 | 簡要咨詢須知 | 新媒體/短視頻平臺 | 手機站點

版權所有:易賢網