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

Angular is used to call a function that captures a specific div and then waits for the capture to be completed before

I'm facing a challenge where I need to handle the capturing of a div using a method called capture() within another method. Take a look at the code snippet below: theimage; // declaring the variable callcapture() { // perform certain actions t ...

Enhancing User Experience with Load Indicator during State Changes in React Native

I'm facing an issue where the page for displaying a single item is loading slowly - I need to delay the page from loading until the object has changed. After checking the navigation params through console log, I can see that the id changes when each b ...

Leveraging split and map functions within JSX code

const array = ['name', 'contact number'] const Application = () => ( <div style={styles}> Unable to display Add name & contact, encountering issues with splitting the array). </div> ); I'm facing difficul ...

The CSS dropdown menu is malfunctioning on Internet Explorer and Firefox

After searching for a solution and coming up empty-handed, I have decided to ask a question. The drop-down menu on my computer and other devices at home works perfectly in Chrome but not in Firefox and IE. #menu { position: absolute; left: 50%; bottom ...

I am hoping for JavaScript to perform three distinct actions depending on the names of the files that are currently open in Photoshop

Currently, I am in the process of developing a JavaScript script for Photoshop. The main objective of this script is to prompt the user to choose a folder containing multiple files. Subsequently, the script will open each file within the folder and perform ...

Leveraging property values in Angular 2 to dynamically generate HTML elements as tag names

Is it feasible to use a property as an HTML tag name? For instance, something along the lines of: <{{property.name}}>Hello world</{{property.name}}> ...

How can I achieve a letter-spacing of 0.5 pixels in CSS?

Encountering an issue, I set out to enhance readability by adjusting letter-spacing to 1px. Displeased with the result, I attempted a half pixel spacing of 0.5px but found it ineffective. Subsequently, I experimented with em attributes but failed to accomp ...

HTML: Learn how to concatenate the href attribute of an anchor tag instead of replacing it

I am currently on the page www.myUniqueWebsite.com/sign-up?type=explore In the navigation menu, there is a link to switch languages. <a href="?lang=es">Spanish</a> When I click on this link, it redirects me to www.myUniqueWebsite.com/ ...

Leveraging React's useEffect hook to asynchronously fetch and load data

In my coding scenario, there is a parent component containing a child component which loads data asynchronously. This is what I currently have: <Parent> <AsyncChild data={props.data} /> <Child /> </Parent> Within the AsyncChil ...

Determining the live total number of Protovis Sparkbar instances

I am currently working on a project where I need to show the ratings and corresponding dates (in string format) from a JSON file in tipsy tooltips. The data consists of a list of dates and ratings. For example: var data = [{"dates":["2010-07-01","2010-07 ...

Deleting various classes (jQuery)

Is there a more effective alternative to rewriting the following code snippet? $('element').removeClass('class1').removeClass('class2'); I am unable to utilize removeClass(); because it would eliminate ALL classes, and that ...

How can I incorporate JSON data retrieved from my backend server into the content of Tabs in a ReactJS application, utilizing either the map() or forEach() method

I need help assigning a key from an object to each tab using a loop in order to navigate to its content when clicked on. I attempted to use map() but it didn't work, so I'm looking for guidance as I am new to React. Below is the code. Any assist ...

A step-by-step guide on coding a slider image

<?php $query1="SELECT * FROM user_photos_offline WHERE ssmid='$ssmid' AND status='1' ORDER BY date_uploaded DESC LIMIT 0,5"; $sql=mysql_query($query1); $count=mysql_num_rows($sql); ...

javascript - Convert a string into a JSON object

Looking for assistance here as I am fairly new to this. My goal is to transform the fullName string returned from a webapp UI using Selenium WebDriverIO. Here's what I have: const fullName = "Mr Jason Biggs"; The desired outcome should be structured ...

How to retrieve data from an undefined table using Sequelize that is created through association

I've encountered a new challenge while working on my latest project; Imagine the tables User and Project in Sequelize have been defined. There's also a third table in the database called ProjectsUsers, and I need to retrieve data from there. T ...

Ensure that the text within the ng-repeat is wrapped in a span element and each

When using ng repeat in span, I encountered a word breaking into a new line. Here is the actual output: https://i.stack.imgur.com/k4c9k.png To style this, I implemented the following CSS: border: 1px solid #ECE9E6; border-radius: 3px; text- ...

The button will be disabled if any cells in the schedule are left unchecked

I am seeking help on how to dynamically disable the save button when all checkboxes are unchecked. Additionally, I need assistance with enabling the save button if at least one hour is selected in the schedule. Below is my code snippet for reference: htt ...

Using the NodeJS driver for MongoDB to Update Documents

I'm currently working on updating a document using the MongoDB Node.js driver, without utilizing Mongoose. However, I keep receiving an undefined result for the updated document. I'm struggling to pinpoint what might be causing this issue. var M ...

The Facebook like button seems to be missing from the webpage

Hi everyone, I'm having trouble getting the like button code to work. I used the wizard on Facebook but the button still isn't showing up, even with a simple HTML setup like this: <!DOCTYPE html> <html> <head> </head> < ...

Is the presence of a 'disabled' attribute on a non-input element enough to render your document invalid in HTML?

Originally intended for <input/> elements, the disabled attribute raises a question when applied to non-input elements. Could this potentially lead to document invalidation? ...