Show spinner until the web page finishes loading completely

Could anyone guide me on how to display Ring.html for a brief moment until About.html finishes loading completely? I need the Ring.html page to vanish once About.html is fully loaded. As a beginner in web development, I would greatly appreciate your assistance. If jQuery is necessary, please provide step-by-step instructions on where and how to insert the code. I've tried looking at other solutions, but I'm having trouble applying them to my own code.

This is the Ring.html page for my spinner

   <!doctype html>
<html>
    <head>
        <meta charset="utf-8">
        <link href="https://fonts.googleapis.com/css2?family=Pacifico&display=swap" rel="stylesheet">
        <link href="Ring.css" rel="stylesheet">
    </head>
    <body>
        <div class="ring">
            Loading
        <span></span>
        </div>
    </body>
</html>

This is the Ring.css code for my spinner

body
{
    margin:0;
    padding:0;
    background:#262626;
}
.ring
{
    position:absolute;
    top: 50%;
    left:50%;
    transform: translate(-50%,-50%);
    width:150px;
    height:150px;
    background:transparent;
    border-radius:50%;
    text-align:center;
    line-height:150px;
    font-family: 'Pacifico', cursive;;
    font-size:20px;
    color:#9e1ac9;
    letter-spacing:4px;
    text-shadow:0 0 10px #9e1ac9;
    box-shadow:0 0 20px rgba(0,0,0,.5);
}
.ring
{
     border:3px solid #3c3c3c;
}
.ring:before
{
    content:'';
    position:absolute;
    top:0;
    left:0;
    width:100%;
    height:100%;
    border-radius: 50%;
    animation: animateCircle 2s linear infinite;
}
.ring:before
{
    border: 3px solid transparent;
    border-top: 3px solid #9e1ac9;
    border-right: 3px solid #9e1ac9;
}
span
{
    display:block;
    position: absolute;
    top: calc(50% - 2px);
    Left: 50%;
    width: 50%;
    height: 4px;
    background: transparent;
    transform-origin: left;
    animation: animate 2s linear infinite;
}
span:before
{
    content:'';
    position:absolute;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #9e1ac9;
    top: -6px;
    right: -8px;
    box-shadow: 0 0 20px #9e1ac9;
}
@keyframes animateCircle
{
    0%
    {
        transform:rotate(0deg);

    }
    100%
    {
        transform:rotate(360deg);
    }
}
@keyframes animate
{
    0%
    {
        transform:rotate(45deg);

    }
    100%
    {
        transform:rotate(405deg);
    }
}

This is the About.html

<!DOCTYPE html>

    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Elite Prep</title>
</head>
<body>
  <header>
  <!-- The video -->
     <video autoplay muted loop id="myVideo">
      <source src="Nebula2.mp4" type="video/mp4">
    </video>
  <!-- NavBar-->
  <div class="navbar">
    <ul>
      <li>Elite Prep</li>
      <li><a href="Index.html">Home</a></li>
      <li><a href="About.html">About</a></li></li>
      <li><a href="Team.html">Team</a></li></li>
      <li><a href="Pricing.html">Pricing</a></li></li>
      <li><a href="Contact.html">Contact</a></li></li>
    </ul>
 </div>
 </navbar>
   <!-- About Us-->
         <div class="About" id="About">
            <div class="roll-in-left" id="roll-in-left">
            <h1>Welcome to Elite Prep !</h1>
            <p class="text1">On insensible possession oh particular attachment at excellence in. The books arose but miles happy she. It building contempt or interest children mistress of unlocked no. Offending she contained mrs led listening resembled. Delicate marianne absolute men dashwood landlord and offended. Suppose cottage between and way. Minuter him own clothes but observe country. Agreement far boy otherwise rapturous incommode favourite.
            Behind sooner dining so window excuse he summer. Breakfast met certainty and fulfilled propriety repetition, injected humour, or non-characteristic words etc. </p>
            <span> I have no idea what I'm talkin about. This is utterly bullshit </span>
        </div>
        </div>
   </header>

</body>

I want to show Ring.html for a few seconds until About.html fully loads. Ring.html should disappear when About.html fully loads. Since I am new to web developing, I would highly appreciate your help. If jQuery is to be used then please tell me how and where to add the code in baby steps.

Answer №1

While @REv3nG3's answer could be effective, here is another solution:

document.addEventListener('DOMContentLoaded', function() {
   document.querySelector('#loader').style.display = 'none';
});

Make sure that your loader element has an id of "loader" for this code to work correctly.

Keep coding happily! Tilier

Answer №2

<body>
    <div id="load"></div>
    <div id="contents">
          jlkjjlkjlkjlkjlklk
    </div>
</body>

This is the content of your body section.

document.onreadystatechange = function () {
  var state = document.readyState
  if (state == 'interactive') {
       document.getElementById('contents').style.visibility="hidden";
  } else if (state == 'complete') {
      setTimeout(function(){
         document.getElementById('interactive');
         document.getElementById('load').style.visibility="hidden";
         document.getElementById('contents').style.visibility="visible";
      },1000);
  }
}

This code will execute when the readyState is complete. document.readyState can have three values: loading, interactive, and complete.

If the document.readyState is complete, the spinner will be hidden.

Ensure that your spinner covers the entire screen and stays on top of all elements.

.ring {
    width:100%;
    height:100%;
    position:fixed;
    z-index:999;
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Manipulating the 'display' attribute with jQuery

Is there a way to show an element that has been hidden using the following CSS? .pds-pd-link { display: none !important; } Can jQuery be used to enable the display of the .pds-pd-link CSS? For example, would $(.pds-pd-link).css("display",""); ...

Vue.js - updating npm to patch version with unclean git working directory

I recently followed a tutorial on how to publish packages to NpmJS. However, I encountered an error when trying to update the package after making changes to the README.MD: npm version patch npm ERR! Git working directory not clean. npm ERR! A .gitignore ...

ERROR: The variable countryCallingCode has not been defined

I encountered an error when attempting to assign a value to my property countryCallingCode, which does not exist in the first option. this.allData.customerFacingPhone.countryCallingCode = newItem.countryCallingCode The error message I received was: ERROR ...

Update the CSS of a different element when hovering

Hello to all the jQuery developers out there! I have a question that's fairly simple. I'm trying to change a CSS attribute for an element when I hover over a different element on the page. I've created a fiddle for you to review, and I&apos ...

Is there a way to include an edit, delete, details, and create new icon in an @html.actionLink within MVC?

This HTML code is specific to MVC and represents the formatting used: 1. @*@Html.ActionLink("Delete", "Delete", new { id=item.ActivityDepreciationTypeId })*@ 2. @*@Html.ActionLink("Details", "Details", new { id=item.ActivityDepreciationTypeId })*@ ...

Error: Unsupported Media Type when attempting to send JSON data from an AngularJS frontend to a Spring controller

Below is the controller function code snippet @RequestMapping(value = "/logInChecker", method = RequestMethod.POST, consumes = {"application/json"}) public @ResponseBody String logInCheckerFn(@RequestBody UserLogData userLogData){ Integer user ...

Error: Unable to extract the 'id' property from 'this.props.Name' because it is undefined in ReactJS

Can you please assist me in resolving this issue? Error: Cannot destructure property 'id' of 'this.props.Name' as it is undefined. src/component/Detail.js file import React, { Component } from 'react'; import { Character } f ...

Tips for eliminating the gap separating the authentication design from the additional elements within the Laravel, Vue, and Inertia framework

I'm currently working with Laravel and Vue using Inertia. When I log into the system, the authentication layout creates a space at the top of the page. How can I resolve this issue? Here is an image highlighting the space I need to remove, marked wit ...

Troubleshooting head.js and jQuery problems in Chrome/Firefox 5

After rendering the page, it looks something like this: <!DOCTYPE html> <html> <head> <script> head.js("js/jquery.js", "js/jquery.autocomplete.js"); </script> </head> <body> ... content ...

"Exploring the Depths: How Node.js Utilizes Recursive Calls

I need assistance generating a comprehensive list of all users' flairs on a specific subreddit. To achieve this, Reddit breaks down the requests into chunks of 1,000 and offers both "before" and "after" parameters for fetching purposes. However, I am ...

Exploring the compatibility of Husky with Typicode using Yarn

Currently, I have implemented the use of husky to configure git hooks for prettier. However, I am facing a persistent issue whenever I attempt to commit or push: > husky - Can't find npm in PATH. Skipping precommit script in package.json My curre ...

Downloading the file from the specified URL is taking too much time when using the save as blob function

I have developed a service to retrieve and save files from a specified URL. (function() { angular.module('SOME_APP') .service("downloadService", downloadService); function downloadService($http){ var downloadFil ...

What is the best way to align a jQuery Cycle 2 Slider in the middle of the

Having some trouble centering a jQuery Cycle 2 Slider on my page. You can see the slider here. I've attempted multiple methods to center it, but none have been successful. Check out the HTML code: <div class="slider"> <div id=outside> ...

Having trouble removing objects from a map results in having to invoke the function three times

I am facing an issue with the function findPrice where I need to call it multiple times to delete objects that match a specific price. The problem arises when dealing with large maps and two functions. Here is the JSON format: [ { _id: 5c6c408dbec3ab457c ...

Angular - Clear the selection of <select><option> if I opt out of accepting the change

I have created a dropdown menu using HTML <select> and <option> tags, along with a JavaScript function that triggers a confirmation dialogue when an option is selected. The confirmation offers a simple choice between "yes" or "no." If the user ...

I am looking to initiate the animation by triggering the keyframe upon clicking a button

Is there a way to create an animation triggered by a button click instead of loading the page? Each table data cell has its own class with a unique keyframe defining the style changes over time. @-webkit-keyframes fadeIn { from { opacity:0; ...

Using jQuery to serialize parameters for AJAX requests

I could use some help figuring out how to set up parameters for a $.ajax submission. Currently, I have multiple pairs of HTML inputs (i pairs): > <input type="hidden" value="31" name="product_id"> <input > type="hidden" value="3" name="qua ...

Ways to display scrollbar even when inner container lacks fixed height within a fixed position outer container

I am trying to display a scrollbar in an inner container without specifying a fixed height, while the outer container has a fixed position. However, I am encountering an issue where setting a fixed height for the innerContainer results in content being hid ...

Issue with current time malfunctioning

For my latest project, I've been tasked with creating a karaoke application using javascript. The challenge is to synchronize the lyrics with the song as it plays. Here's a snippet of my HTML code: <div id="lyric"></div> <audio i ...

Attempting to transmit unique symbols using JQuery Ajax to a PHP script

I am using JQuery Ajax to send special characters to a PHP file. sending_special_characters.js var special_chars = '!@#$%^&*()_+-='; var dataToSend = 'data=' + special_chars; $.ajax({ type: "POST", ...