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

隐身守侯 提交于 2021-02-08 11:27:49

问题


I have a div with a splashscreen element. This element will be hidden on page load. However, I also want to make sure the splash screen is shown for at least x seconds.

I know this is not all supposed to be formatted as code but the auto formatter made me do it.

To use logic: Show splash screen for at least x seconds. If the page is loaded by that time hide this div.

This code is the part where it hides the div as soon as the page is loaded.

<!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>

This is the part where I show the splash screen for x seconds.

<!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>

So basically I am asking, how can I combine these two jquery codes?

EDIT: I am now trying this code but something still doesn't work.

<!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>

回答1:


Hope this helps.

HTML

<body onload="splash(3000)">

Javascript

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

From CSS display the #splashscreen element block and when the page loads it'll hide from javascript.

If you want to test this out, load a high resolution image from Google. Your splash will be visible either the website content loads or at least x number of seconds if the website content loaded from the browser cache.



来源:https://stackoverflow.com/questions/36561936/show-splash-screen-when-page-loads-but-at-least-for-x-seconds

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!