繁体   English   中英

在页面加载时显示启动屏幕,但至少持续x秒

[英]Show splash screen when page loads, but at least for x seconds

我有一个带有初始屏幕元素的div。 此元素将在页面加载时隐藏。 但是,我还想确保启动屏幕至少显示了x秒。

我知道这不应该全部都格式化为代码,但是自动格式化程序让我做到了。

使用逻辑:显示启动屏幕至少x秒。 如果到那时页面已加载,请隐藏此div。

该代码是页面加载后立即隐藏div的部分。

<!DOCTYPE html>
<html>
    <head>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js">
            $(document).on("pageload",function(){
                $('#splashscreen').hide();
            });
        </script>
        <title>Thomas Shera</title>
    </head>
    <body>
        <div id="splashscreen">
        </div>
    </body>
</html>

这是我显示启动屏幕x秒钟的部分。

<!DOCTYPE html>
<html>
    <head>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js">
            $(function() {
                $("#div2").show().delay(x).hide();
            });
        </script>
        <title>Thomas Shera</title>
    </head>
    <body>
        <div id="splashscreen">
        </div>
    </body>
</html>

所以,基本上我在问,如何结合这两个jQuery代码?

编辑:我现在正在尝试此代码,但仍然无法正常工作。

<!DOCTYPE html>
<html>
<head>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js">

    $(document).on("pageload",function(){
               $('#splashscreen').hide();
});

$(function() {
     $("splashscreen").show().delay(1000).hide();
 });

</script>

<style type="text/css">
  @import url(https://fonts.googleapis.com/css?family=Cutive+Mono);

  .skills
  {
    font-family: 'Cultive Mono', monospace;
    font-size: 400pt;
  }

</style>

<title>Thomas Shera</title>

</head>
<body>
  <div id="splashscreen">
    <p i="skills">
      Javascript  Technical writing   VBA scripting with Microsoft Office   Excel
      Entrepreneur
    </p>
  </div>
</body>
</html>

希望这可以帮助。

的HTML

<body onload="splash(3000)">

Java脚本

function splash(param) {
 var time = param;
 setTimeout(function () {
   $('#splashscreen').hide();
 }, time);
}

在CSS中显示#splashscreen元素块,当页面加载时,它将在javascript中隐藏。

如果要进行测试,请从Google加载高分辨率图像。 如果从浏览器缓存中加载了网站内容,则您的初始消息将在网站内容加载中可见,或者至少x秒。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM