Is this preloader code actually preloading something?

Struggling to add a preloader on my website. I came across the following code that appears to be functioning (I can see the CSS animation before the images load - check out this JSFiddle). However, I'm unsure about how the JS code actually operates...

Which section of the code indicates when all the images have loaded and it's safe to stop the pre-loader animation? Can this method be trusted?

Thank you in advance!

JS:

var show_loader = function(){};
var hide_loader = function(){};
jQuery(document).ready(function($){

    /*Make Loader Height Same as Window*/
    $(".loader_cont").css("height",$(window).height());
    /*Make Loader Height Same as Window*/

    /*
    *
    *Window Resize
    *
    */
    $(window).resize(function(){
        move_bottom_border();
        fit_menu();
        $(".loader_cont").css("height",$(window).height());
    });
    /*
     *
     *Window Load
     *
     */
    $(window).load(function(){
        hide_loader();

    });
    /*Hide And Show Loader*/
    hide_loader = function(){
        $(".loader_cont").hide();
    }
    show_loader = function(){
        $(".loader_cont").css("height",$(window).height());
        $(".loader_cont").show();
    }
    /*Hide And Show Loader*/
});

HTML

<div class="loader_cont">
    <div class="bubblingG">
        <span id="bubblingG_1">
        </span>
        <span id="bubblingG_2">
        </span>
        <span id="bubblingG_3">
        </span>
    </div>
</div>
Then link to images...

CSS:

Answer №1

When utilizing the jQuery .load() function, it is activated once the specified element and all of its child elements have finished loading completely. In this case, it is applied to $(window), which indicates that it will only execute once every element on the current page has been loaded, triggering the handler to hide the animation.

To summarize, this snippet of code waits for the entire window to be fully loaded before concealing the animation.

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

Check to see if the moment function has been executed and if the resulting output is accurate

I have a function called moment that formats a date received from the server in milliseconds. I am attempting to write tests using Enzyme and Jest to check if the moment function has been called (1), and whether the output of the function matches the expec ...

The jquery accordion title width does not align with the content width when an icon is included

Is there a way to adjust the widths of the heading and div elements after adding edit and delete icons to match the standard accordion style? Thanks <div id="accordion"> <h3><a href="javascript:;"> ...

Utilizing PHP to populate a form with the <select> element

I am currently working on developing a system for managing addresses within our CMS. My goal is to extract addresses from a SQL database and automatically populate a form with the retrieved data upon selection using a SELECT element. Although I have been ...

Exploring the efficiency of different CSS selectors

I am struggling with the following code: HTML: <ul class="list"> <li class="list-item"> item 1 </li> <li class="list-item list-item_active"> Active item </li> <li class="list-item"> item 3 </li> ...

A comprehensive guide on associating a JavaScript function with an element attribute

I am looking for a way to assign a JavaScript function to an HTML attribute. For example: <li data-ng-repeat="job in jobList" class= dynamicClass(str) data-filter = "dynamicFilter(str)"> The reason I want to do this is because the class name and ...

Tips for creating an effective dark mode toggle switch on a website

I was experimenting with creating a dark-mode switch for a website, but I'm not convinced that my implementation is the most efficient. Essentially, I ended up duplicating each file and adding a "2" at the end to create modified versions for each sect ...

Setting the default TAB in a specific Menu Tab within the Menu Bar

I'm encountering some issues with this code. Specifically, the menu bar JavaScript is automatically clicking on the Second TAB instead of the First TAB when run. JS CODE. var dolphintabs = { subcontainers: [], last_accessed_tab: null, ...

What is the reason for webpack adding "-es5" and "es2015" to my TypeScript files?

When Webpack converts my typescript files into Javascript files, it appends -es5 to the name. For instance, I expect the file to be named background.js, but it actually generates 4 separate files: background-es5.js background-es5.js.map background-es2015. ...

Prevent table content from appearing above the 'sticky' header

I am facing an issue with a single table that has a fixed header and scrolling body. The problem arises when the body extends beyond the header while scrolling. I have provided a zoomed-in clip of the problem. Can anyone offer a solution for this without u ...

What is the best way to send props to a CSS module in React?

Currently utilizing NextJS, I have a route named about that is displayed through page.js. Within /about/page.js, I am incorporating a component called <Hero /> and aiming to pass a prop to <Hero heroHeight={'height: 400px'} /> to my C ...

Difficulty arises when trying to add various text fields to a collection

Lately, I've been making modifications to the Meteor1.3+React Todos app to familiarize myself with the basics, and I must say, it's been a smooth ride so far. However, I have encountered a roadblock. I want to incorporate an additional text field ...

Display arrays in a list layout using React

I'm struggling with displaying some specific data. The structure of the data is shown below: View Data Structure In each object within the array, there are keys such as matchday, awayTeam, homeTeam, and result. All keys except for matchday have an a ...

What is the process for building an interactive quiz using JavaScript?

In the process of creating a quiz, I envision a user interface that presents questions in a "card" format. These questions will include simple yes/no inquiries and some multiple-choice options. As the user progresses through the quiz, their answers will de ...

Displaying HTML code through Alert() is a convenient way to showcase snippets of

Can alert() or another pop-up be used to show actual HTML code? For instance, the following code snippet: var range = selection.getRangeAt(0); var newNode = document.createElement('span'); newNode.setAttribute("class", "selectedText"); range.sur ...

The dropdown menu is extending beyond the bounds of the screen on mobile devices

When viewing my website on a mobile device, the select dropdown is going off the screen. I am using the bootstrap class form-control. Here is my code: <select name="service" formControlName="service" class="form-control shadow-none" style="width:100%"& ...

Unable to execute multiple queries within a CloudCode query

In my quest to discover new users who I have not connected with before using a cloud function, I am utilizing several tables: Users table - This standard table includes an additional "hasLight" boolean column Connected table: 'user' - a point ...

"Experiencing overflow issues with flex items on Firefox browser

Currently, I am working on constructing a form where the first row consists of a single text field with 100% width and the second row contains three equidistant fields. The layout works perfectly in Chrome but is experiencing overflow issues in Firefox. ...

What is the best way to format dates in jQuery AJAX requests?

Utilizing jquery to interact with a REST API in (ASP.net Web API). I've constructed a basic object and then utilized jquery to 'PUT' it on the server: var myObject = { name: 'just a name', createDate: new Date() } $.ajax({ ...

How to efficiently search MongoDB for existing records and group them by unique array values

My dataset is structured like this: { "_id" : 1, "category" : [ { "name": "category1" }, { "name": "category2" } ], "event": [ { type: "house" ...

Ways to modify div content depending on the size of the screen

When the screen size becomes small, my goal is to modify the content within the row divs of the indices_container. Currently, all screen sizes display the index name, price, 1-day change, and year-to-date (YTD) change for each row. I only want to show the ...