The website is not displaying even 2 seconds after jQuery window load

I want to create a loading screen that appears before the index.html loads for the client

Here is the HTML Code:

<section class="loading text-center">
                <div class="spinner">
                    <img class="img" src="img/logo.png" width="160" height="211" />
                </div>
    </section>

CSS Code: This code customizes the design of the loading page

.loading {
    background-color: #fcfdff;
    color: #000;
    position: absolute;
    z-index: 9999;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;

}

.spinner {
    position: fixed;
    top: 30%;
    left: 45%;
    transform: translate(-50%, -50%);
    background-color: transparent;
    -webkit-animation: sk-rotateplane 1.2s infinite ease-in-out;
    animation: sk-rotateplane 1.2s infinite ease-in-out;
}

.img {
    -webkit-animation: sk-rotateplane 1.2s infinite ease-in-out;
    animation: sk-rotateplane 1.2s infinite ease-in-out;

}

@-webkit-keyframes sk-rotateplane {
    0% {
        -webkit-transform: perspective(0px)
    }

    50% {
        -webkit-transform: perspective(0px) rotateY(180deg)
    }

    100% {
        -webkit-transform: perspective(0px) rotateY(180deg) rotateX(180deg)
    }
}

@keyframes sk-rotateplane {
    0% {
        transform: perspective(0px) rotateX(0deg) rotateY(0deg);
        -webkit-transform: perspective(0px) rotateX(0deg) rotateY(0deg)
    }

    50% {
        transform: perspective(0px) rotateX(-180.1deg) rotateY(0deg);
        -webkit-transform: perspective(0px) rotateX(-180.1deg) rotateY(0deg)
    }

    100% {
        transform: perspective(0px) rotateX(-180deg) rotateY(-179.9deg);
        -webkit-transform: perspective(0px) rotateX(-180deg) rotateY(-179.9deg);
    }
}

jQuery Code: This code controls when the scroll should show after the loading screen

/*global $, window, document, jQuery */
// Loading Screen
$(window).load(function () {
    "use strict";
    $(".loading .spinner").fadeOut(2000, function () {
        $(this).parent().fadeOut(2000, function () {
            //Show The Scroll
            $("body").css("overflow", "auto");
            $(this).remove();
        });
    });
});

However, the issue is that the loading page appears, everything seems fine, but the index.html does not appear after 2ms to display the website

Answer №1

Update: The code $(window).load(function () { is causing the code block to run 'too early' (before the page is fully loaded/ready) - switch it to $(document).ready(function () { to ensure it runs after the document/page is ready.

Previous Code:

// Loading Screen
$(window).load(function () {
    ...
}

Current Code:

// Loading Screen
$(document).ready(function () {
    ...
}

Additional Note:

@charlietfl mentioned using a shorter version of $(document).ready():

// Loading Screen
$(function () {
    ...
})

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

What are the steps to retrieve data using jQuery ajax?

I attempted to utilize jQuery and Ajax to populate a jqxGrid, but unfortunately, I was not successful. Here is my jQuery code: $.ajax( { url: "Cliente.aspx/GetClient", type: "POST", data: {}, dataType: "json", ...

Error message: Cannot access 'addEventListener' property of null in Three.js React.js integration

While following a tutorial at https://youtu.be/V8GnInBUMLo, I encountered an error upon completion: TypeError: Cannot read properties of null (reading 'addEventListener') I attempted to add an if(element) check inside my addeventlisteners func ...

How can one ensure efficient execution of heavy JavaScript tasks without causing any blocking issues?

Currently, I'm utilizing webgl to load a 3D model and running some code to manipulate it before displaying it. The issue is that this process takes several seconds and completely restricts the user from performing any other tasks during that time. It ...

Using Bootstrap 4 to validate credit card information with personalized error messages

How can I apply Bootstrap 4 validation to ensure that the credit card number contains only numbers, is 16 digits long, and display appropriate messages based on user input? I want to display three distinct messages: 1. When no input is provided, show "Cre ...

Error in node - Invalid URI received during npm-request operations

var request = require('request'); var options = { url: 'https://connect1on1.com/api/web/index.php/v1/message/save-message', method:'POST', body:JSON.stringify({"id": data.user_id, "message": data.me ...

Tips for leveraging JSON for state management in React?

I am working with JSON data and utilizing SetState in the constructor { index:index, key: key, all: { 0: {name:'qwerty', id:'1', surname:'foo'} 1: {name:'bar', id:'2', surname ...

Is there a way to invoke a client-side function from the server?

Is there a way to display an alert at the top of the browser if the SQL query returns empty results? I tried using the "alert" function, but I'm struggling with customizing its appearance. I have a function in my HTML code that triggers an alert, but ...

Have Babel transpile configuration files into CommonJS format

I'm having trouble getting my Nuxt app to work with Jest for testing. I have a setupFilesAfterEnv property set with a setupTests.ts file that imports a translation file. The translations file uses ES6 import/export module syntax, but it seems like my ...

IE 11 does not support the use of absolute positioning with a height of 100%, however, this functionality works perfectly on Microsoft Edge

It appears that in IE 11, my absolutely positioned element is not displaying within another element with a height:100%. Strangely, it only works if I assign a fixed height to the element (even though its parent has a fixed height). Here is the HTML code: ...

How to modify a Python script to print in a specific div element instead of the Chrome console?

Currently conducting preliminary tests on executing a Python script within a Chrome extension. The code provided below is functional, but I am seeking assistance on how to display the value in a div element instead of logging it to the console. Unfortunate ...

What is the reason for the clearInterval consistently functioning after the completion of the function?

Just starting out in web programming and currently delving into javascript and jquery ajax.. This snippet represents my javascript code. The refresh variable controls an interval for updating the chat by fetching chats from the database and displaying the ...

Retrieve the values of the rows that have been selected in the Kartik GridView located within a modal, and then transfer

I am attempting to extract data from a Bootstrap modal (which contains a table of Kartik GridView) and pass the selected value to the parent form (an action create form). Can anyone provide guidance on how to achieve this? The modal form includes fields su ...

How can I receive user input in JavaScript while incorporating three.js?

I am currently exploring the functionalities of this three.js example () and I am interested in enabling users to input specified X, Y, and Z positions for boxes dynamically. Initially, I considered utilizing a JavaScript prompt like below: var boxes = p ...

Modifying an image using JavaScript and CSS

I've been experimenting with adding an Adblock detector that will show one image when detecting Adblock and another when not detecting it. The challenge lies in the fact that CSS controls the display and formatting of the image. Is there a way to mani ...

Utilizing Bootstrap's responsive design to create optimal spacing between boxes

I have designed this webpage layout using Bootstrap. Although I have manually added margin between the rows, I now want to include vertical spacing between the columns when the page is resized. Can anyone help me achieve this? Full-size browser: Resize ...

Would you like to learn how to dynamically alter a button's color upon clicking it and revert it back to its original color upon clicking it again?

My Upvote button starts off transparent, but when I click on it, the background color changes to green. What I need is for the button to become transparent again when clicked a second time. I've attempted using the following code snippet: function ...

Issue with nested tabs functionality within a pill tab panel in Bootstrap not functioning as expected

I'm facing a challenge with integrating tabs into a vertical pill tab panel in Bootstrap 4. Below is a brief code snippet: <html> <head> <link href="bootstrap.min.css" rel="stylesheet"> </head> <body> <script ...

The correct way to link a separate CSS stylesheet called "stylesheet" to an HTML page is by using the proper syntax

How can you correctly link a CSS file called "stylesheet" to an HTML page when both files are located in the same directory? ...

Dealing with ASP.NET forms that involve a javascript plugin generating substitute input

I'm facing an issue with my ASP.NET MVC webpage where I submit a form using AJAX in the following way: function ValidateFormAndAjaxSubmit(formId, callingElement) { if (IsNotDblClick(callingElement.id)) { var _form = $("#" + formId); ...

The like button seems to be malfunctioning and I'm not sure what the issue is

I've added the ability for users to like my posts, but it's not working as intended. Here's the code snippet I used: models.py class Post(models.Model): title = models.CharField(max_length=100) content = models.TextField(blank=Tru ...