[英]How to show Page Loading html file until the page has finished loading?
I need a different page loader file (like: loader.html
) in which i have only loader.gif
image with some css styling not in the same index.html
file. 我需要一个不同的页面加载器文件(如: loader.html
),其中我只有loader.gif
图像,其中一些css样式不在同一个index.html
文件中。 So now i want to load my index.html
file before it loads i want to show my loader.html
file and if my all content loaded hide the loader.html
file and show index.html
file content. 所以现在我想在加载之前加载我的index.html
文件我想显示我的loader.html
文件,如果我加载了所有内容,则隐藏loader.html
文件并显示index.html
文件内容。 Hope you understand what i am saying please help :) 希望你理解我在说什么,请帮助:)
I tried this Code: 我试过这个代码:
$(window).load(function(){
if($("body").load("loader.html").fadeOut(5000)){
$("loader.html").hide();
$("index.html").show();
}
});
You can do this: 你可以这样做:
.gif
or loader .html
in some <div>
as you required. 在页面加载中,根据需要在某些<div>
显示.gif
或加载器.html
。 gif/loader.html
and show your index.html
. gif/loader.html
并显示你的index.html
。 This might solve your problem. 这可能会解决您的问题。
jQuery jQuery的
$(document).ready(function () {
//for demo, I used timer for 3 second
var timer = window.setTimeout(requestPage, 3000);
function requestPage(){
sendRequest("index.php", function(sResponse){
clearTimeout(timer);
//clear everything everything in body HTML
//change inner html with sResponse
$("body").children().fadeOut(300, function(){
$(this).remove();
$("body").html(sResponse)
});
});
}
function sendRequest(url, oncomplete){
$.ajax({
url: url,
type: 'POST',
dataType: 'html',
cache: false,
timeout: 60000,
complete: function(e, xhr, opt) {
if(typeof oncomplete === "function") oncomplete(e.responseText);
}
});
}
});
HTML HTML
<div class="loader"><img src="loader.gif" /> <em>Loading page. Please wait...</em></div>
Hope you can help 希望你能帮忙
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.