gpt4 book ai didi

Javascript/Jquery - 在其他脚本运行后运行脚本

转载 作者:行者123 更新时间:2023-11-30 10:18:48 24 4
gpt4 key购买 nike

我的网页遇到了问题。我有一个启动画面,它应该在页面加载时运行,而且效果很好。我还有一个加载屏幕,我想在启动屏幕之后运行,但我不知道如何让启动屏幕运行,然后加载下一行代码,这将是加载屏幕的加载。我如何让启动画面运行然后加载屏幕运行?你可以看到下面的代码。

<script type="text/javascript">
$(window).load(function() {
$("#spinner").fadeOut( 3000 );
})
function SplashDone() {
document.getElementById('splash').style.display = 'none';
}
function Init() {
document.getElementById('splash').style.display = 'block';
setTimeout(function(){ SplashDone(); }, 3000);
}
window.onload = Init;
</script>
<body>
<div id="spinner">
<p>Loading</p>
</div>
<div id="splash">
<p>Splash</p>
<p><a href="#" onclick="SplashDone(); return false;">Skip</a></p>
</div>

所以我基本上要问的是,如何在页面加载后作为脚本运行,然后在该脚本运行后运行另一个脚本?

最佳答案

您可以做的是从splashDone 函数showLoading 屏幕。通过这种方式,您可以确保在两种情况下都会出现加载屏幕:如果超时用完,以及如果用户单击 Skip 按钮:

window.onload = init;

function init() {
setTimeout(splashDone, 3000);
}

function splashDone() {
document.getElementById('splash').style.display = 'none';
showLoading();
}

function showLoading() {
setTimeout(loadingDone, 3000);
}

function loadingDone() {
document.getElementById('spinner').style.display = 'none';
}

我还为此目的添加了 showLoading 函数和一些 CSS 以使启动画面和加载在默认情况下可见,这样您就不必在页面加载时一开始就显示它们。

演示:http://jsfiddle.net/P8evf/1/

关于Javascript/Jquery - 在其他脚本运行后运行脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22387427/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com