Is it possible to implement a loading animation that remains visible until the entire page has finished loading?

After deploying my website on netlify, I noticed that only the HTML content is displayed until the page finishes loading. Does anyone have advice on how to make the website visible only after it has fully loaded?

I have created a custom loading animation, but I'm unsure of how to implement it in this scenario.

Answer №1

Utilize the Window: load event for optimal results.

The load event triggers upon complete page rendering, including all associated resources like stylesheets and images.

For a practical example, refer to the snippet below.

<!DOCTYPE html>
<html lang="en">
  <head>
    <style>
      #loader {
      height: 100vh;
      width: 100%;
      background-color: black;
      position: fixed;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
      z-index: 999;
    }

    #loader img {
      position: absolute;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
      width: 30%;
    }
    </style>

    <title>The Loader</title>
  </head>
  <body>
    <!-- Div for loader placement -->
    <div id="loader">
      <img src="loader.gif" />
    </div>

      <div>
        <span>Your inquiry will be addressed shortly!</span>
      </div>
    </section>

<script>

  //conceal the loader once the page is fully loaded
  var loader = document.getElementById("loader");
  window.addEventListener("load", function () {
    loader.style.height = "100%";
    loader.style.width = "100%";

    loader.style.borderRadius = "50%";
    loader.style.visibility = "hidden";
  });

</script>
  </body>
</html>

Answer №2

It seems that my timing was unfortunate as I had just completed writing this before the servers unexpectedly went down.

<!doctype html>
<html>

<head>
  <meta charset="UTF-8">
  <title>My Site</title>
  <style>
    .main {
      visibility: hidden
    }
  </style>
  <script>
    window.addEventListener("load", function() {
      document.getElementById("animation").style.display = "none";
      document.getElementById("main").style.visibility = "visible";

    })
  </script>
</head>

<body>
  <div id="animation">img src="animated.gif" /></div>
  <div id="main">
    Rest of the site
  </div>
</body>

</html>

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

onsubmit function was never triggered

Seems like a silly mistake, but I'm encountering an issue with my HTML form. Here's a snippet of the code: <form onsubmit="updateProfile();"> <input type="submit" value="Update Account"> .. ... </form> However, w ...

The callback function does not seem to work when using MUI v4 PropFunc

Encountering an issue with custom styling using PropFunc in Material UI (MUI) v4 (4.12.4). When providing a PropFunc in the traditional callback way to get CSS, it works as expected: const useStyles = makeStyles((theme) => { return { input: { ...

How to use a string condition to filter a list of objects in Javascript?

Below is the structure of the object: var objList = [ { "age": 19, "valueField": 34, "booleanField": false }, { "age": 15, "valueField": 5, "booleanField": false }, { "age": 22, "valueField": 17, "booleanField": true } ]; Given the condition ...

Iframe Interactivity

My goal is to create an interactive iframe that will match the current parent URL (). For example, if I have an iframe pointing to http://www.google.com and click a link within the iframe, it should update the parent URL to , and then load the clicked con ...

What is the best way to verify that a check should have various attributes using chai-things?

Searching for a way to verify if an array in my mocha tests consists of an Object in my Node.js application, I discovered that with Chai-Things, I can use: [{ pet: 'cat' }, { pet: 'dog' }].should.include({ pet: 'cat' }) or ...

Interactive radio button that only registers the most recent click

Homepage.jsx const Homepage = () => { const [categories, setCategories] = useState([]) const [products, setProducts] = useState([]) const [selected, setSelected] = useState("all") const getAllCategories = async() => { try{ ...

"Implementing a toggle switch in jQuery to activate and deactivate a function

My website has 2 jquery codes that I am working with. The first code is : function bottom_open() { $('.cartouche_bottom').css('position','absolute').animate({ top :$(".top_table").height() - 1, ...

Adding color to structured text in emacs org mode for html export

Are there any techniques for maintaining the color scheme of a structured document in emacs org-mode when exporting to an HTML file? ...

Implementing File Retrieval in a Controller

I have a specific file where I declared the URL for my videouploadfolder, and now I need to reference that file in my JavaScript config.js. var filepath = { uploadVideoUrl : './public/videos' } In my Node.js script, I included it like th ...

Tips for controlling or concealing slot elements within child components in Vue Js

I'm working with a named slot: <div name="checkAnswer" class="w-[70%] mx-[15%] flex items-center justify-center" > <button class="p-3 rounded-3xl shadow-md font-bold m-4 px-10 border-2 bo ...

Tips for preventing window.location from becoming relative to the file

Despite my best efforts, I couldn't figure out why this issue was occurring or how to resolve it. Here is the code in question: window.location.href=("www.google.com"); The intended functionality of this code is to redirect to google.com, but inst ...

I'm encountering some challenges with my functions in ReactJS when it comes to updating state and working with promises

Currently, I am handling form field validation by running regex checks and updating the state to 'success' or 'error' accordingly (utilizing react-bootstrap). I have a total of 6 functions that require execution, but the validation fun ...

I seem to be facing an issue in my Reactjs script, but the exact cause of the problem eludes me

I'm currently coding in React and I have an icon that I want to add a hover effect to, similar to CSS. However, I need to achieve this within my React application. Below is the code snippet I've been working on: import React from 'react&apo ...

AngularJs: The ability to rate or rate functionality

I've been attempting to incorporate a likes/dislikes feature into my project, but it doesn't seem to be functioning correctly. As someone new to this type of functionality, I could use some guidance. Below is the snippet of code that outlines wh ...

Utilizing Bootstrap 4: The Use of an anchor tag in a button element

I am facing a situation where I have an icon represented by the HTML code <a>, which acts as a link redirecting to a different page. This <a> is nested inside a collapsible button, meaning that clicking on the icon expands the menu before actua ...

"Maximizing Bootstrap Functionality with Angular 2: Step-by

I'm experiencing an issue with Angular2, Bootstrap 3.3.7, and Bootstrap Plugins. I have imported all the necessary stylesheets and JavaScript files in the 'index.html' file. Below is the snippet from the index.html: <!-- Bootstrap & ...

What is the best way to show the selected values of dropdown and checkboxes on a redirected page for confirmation using PHP?

<form action="action.php" method="POST" target="_self"> <table class="main" border="1" height="100%" align="center">t; <h3> <p id="id1" style="background-color: #9FF" >Registration form</p></h3> <tr><t ...

Creating a cookie on click event to change the background

I am working on changing the background of a div onclick and storing it with a cookie. However, I am facing some issues with my code. I can't determine if the cookie has been properly set, and I am unsure about changing the background with the value o ...

The attribute "property" is not found in the specified type of "Request<ParamsDictionary>"

Struggling to enhance the Request interface in the express package with custom properties, I keep encountering this TypeScript error: TS2339: Property '' does not exist on type 'Request<ParamsDictionary>'. Any ideas on how to re ...

Is there a way to extract shared properties within a Material UI style declaration?

I am working with a specific set of style rules that define different statuses: status_in_progress: { fontSize: 14, backgroundColor: theme.palette.success.dark, padding: 2, paddingLeft: 5, paddingRight: 5, display: "inline-bl ...