javascript 在 HTML5 中创建启动页面
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20828799/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Creating a splash page in HTML5
提问by DMEM
I want to create a splash page for the app I'm creating using HTML5.
The splash pageshould be displayed while the main pageis being loaded (but the display should be at least 2 seconds even if the main page was already loaded). Say my main page is called main.html
and the splash page is called index.html
我想为我使用 HTML5 创建的应用程序创建一个启动页面。的初始页面,而应被显示的主网页正在装载(但应显示至少2秒,即使已经加载到主页)。假设我的主页被调用main.html
,启动页面被调用index.html
I'm new to JavaScript, so I would really appreciate code example in addition to any explanations.
我是 JavaScript 的新手,所以除了任何解释之外,我真的很感激代码示例。
Thank you!
谢谢!
回答by s3lph
You could do something like this:
你可以这样做:
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
$('#splash').ready()
{
$('#main').load('file.html');
setTimeout(function() {
$('#main').ready(function() {
$('#splash').remove();
window.location.href = "file.html";
});
}, 2000);
}
</script>
</head>
<body>
<div id="splash" style="position: absolute; top: 0px; bottom: 0px; left: 0px; right: 0px; z-index: 10;">
<!--Put splash here-->
</div>
<div id="main">
<!-- keep empty -->
</div>
</body>
</html>
Not really tested, might contain bugs... Uses jQuery
没有真正测试过,可能包含错误......使用 jQuery