【问题标题】:Show splash screen when page loads, but at least for x seconds页面加载时显示启动画面,但至少持续 x 秒
【发布时间】:2016-04-12 10:06:04
【问题描述】:

我有一个带有闪屏元素的 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>

【问题讨论】:

    标签: jquery html


    【解决方案1】:

    希望这会有所帮助。

    HTML

    <body onload="splash(3000)">
    

    Javascript

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

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

    如果您想对此进行测试,请从 Google 加载高分辨率图片。如果网站内容从浏览器缓存加载,则您的启动画面将在网站内容加载或至少 x 秒内可见。

    【讨论】:

    • 给我一点时间,我做了这样的飞溅,但我不想放 x 秒数来显示飞溅。我会更新代码。 :)
    • 测试了代码并完美运行。厚颜无耻的 html 和 javascript 代码,但工作正常。
    猜你喜欢
    • 1970-01-01
    • 2022-12-28
    • 1970-01-01
    • 2015-10-07
    • 2013-04-10
    • 1970-01-01
    • 2022-10-23
    • 1970-01-01
    • 2018-07-16
    相关资源
    最近更新 更多