Hide elements in hidden divs until the page is fully loaded to reduce initial page

www.prismasites.com

I am creating a unique world map by using SVG DIVs shaped like Continents.

Upon clicking on a continent on the world map, it conceals the world map DIV and displays the respective continent DIV with SVG.

I have successfully achieved this functionality.

However, each continent's SVG is housed within a .php file.

The .php files are loaded and placed inside hidden DIVs as shown below:

<div id="TestimonialsMap">
<?php locate_template( array( 'worldmap.php', 'worldmap.php', 'worldmap.php' ), true, false ); ?>
</div>
<div id="TestimonialsMapNorthAmerica" style="display:none;">
<?php locate_template( array( 'WorldMapNorthAmerica.php', 'WorldMapNorthAmerica.php', 'WorldMapNorthAmerica.php' ), true, false ); ?>
</div>
<div id="TestimonialsMapSouthAmerica"  style="display:none;">
<?php locate_template( array( 'WorldMapSouthAmerica.php', 'WorldMapSouthAmerica.php', 'WorldMapSouthAmerica.php' ), true, false ); ?>
</div>
<div id="TestimonialsMapEurope" style="display:none;">
<?php locate_template( array( 'WorldMapEurope.php', 'WorldMapEurope.php', 'WorldMapEurope.php' ), true, false ); ?>
</div>
<div id="TestimonialsMapAfrica" style="display:none;">
<?php locate_template( array( 'WorldMapAfrica.php', 'WorldMapAfrica.php', 'WorldMapAfrica.php' ), true, false ); ?>
</div>
<div id="TestimonialsMapMiddleEast" style="display:none;">
<?php locate_template( array( 'WorldMapMiddleEast.php', 'WorldMapMiddleEast.php', 'WorldMapMiddleEast.php' ), true, false ); ?>
</div>
<div id="TestimonialsMapAsia" style="display:none;">
<?php locate_template( array( 'WorldMapAsia.php', 'WorldMapAsia.php', 'WorldMapAsia.php' ), true, false ); ?>
</div>
<div id="TestimonialsMapOceania" style="display:none;">
<?php locate_template( array( 'WorldMapOceania.php', 'WorldMapOceania.php', 'WorldMapOceania.php' ), true, false ); ?>
</div>

THE ISSUE:

The browser loads all DIVs in sequential order, including hidden DIVs.

Hidden DIVs still load all Continent SVGs, which are large vector files and take a long time to load.

When the page is initially loaded, it stops before Testimonials to load all hidden DIVs, causing a delay.

Instead of loading hidden DIVs first, I want the browser to prioritize loading smaller basic box DIVs that load faster before larger complex-shaped DIVs.

I desire for the FAQ and Contact Sections to be loaded before the hidden DIVs in the Testimonial Section.

To achieve this, I need to prevent the browser from loading hidden DIVs at startup or only load them upon mouse click.

Answer №1

window.onload = function(){
  
  document.getElementById("complex").innerHTML="LOADING COMPLEX HERE"
 };

function clickme(e){

e.innerHTML="your content is now being loaded blah blagh";
};
img{max-width:100px;max-height:100px;}
<img src="http://lorempixel.com/400/200/" alt="Lorem Pixel" /><img src="http://lorempixel.com/400/300/" alt="Lorem Pixel" /><img src="http://lorempixel.com/400/400/" alt="Lorem Pixel" /><img src="http://lorempixel.com/400/200/" alt="Lorem Pixel" />

<div id="complex">
  <img src="http://ppt4web.ru/assets/2c736062/img/loading.gif" alt="loading"  />

</div>

<img src="http://lorempixel.com/400/600/" alt="Lorem Pixel" />
<img src="http://lorempixel.com/400/700/" alt="Lorem Pixel" /><img src="http://lorempixel.com/200/200/" alt="Lorem Pixel" /><img src="http://lorempixel.com/300/200/" alt="Lorem Pixel" /><img src="http://lorempixel.com/400/200/" alt="Lorem Pixel" /><img src="http://lorempixel.com/500/200/" alt="Lorem Pixel" /><img src="http://lorempixel.com/600/200/" alt="Lorem Pixel" /><img src="http://lorempixel.com/700/200/" alt="Lorem Pixel" /><img src="http://lorempixel.com/800/200/" alt="Lorem Pixel" /><img src="http://lorempixel.com/900/200/" alt="Lorem Pixel" />
<img src="http://lorempixel.com/444/344/" alt="Lorem Pixel" />
<img src="http://lorempixel.com/604/350/" alt="Lorem Pixel" />
<img src="http://lorempixel.com/408/366/" alt="Lorem Pixel" />
<img src="http://lorempixel.com/400/320/" alt="Lorem Pixel" />
<img src="http://lorempixel.com/400/340/" alt="Lorem Pixel" />
<img src="http://lorempixel.com/999/306/" alt="Lorem Pixel" />
<img src="http://lorempixel.com/998/306/" alt="Lorem Pixel" />
<img src="http://lorempixel.com/976/306/" alt="Lorem Pixel" />
<img src="http://lorempixel.com/996/306/" alt="Lorem Pixel" />
<img src="http://lorempixel.com/985/306/" alt="Lorem Pixel" />
<img src="http://lorempixel.com/974/306/" alt="Lorem Pixel" />

<h2>OR</h2>

<div onclick="clickme(this)">Click me</div>

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

Achieving this result in HTML using a jQuery accordion component

Hey there, I'm looking to create a full-height accordion that extends from the bottom to the top of the page, similar to what you see on this website: . I also have a footer positioned below the accordion. The content should load when the page loads ...

Using EJS Tags within an external CSS file

I have been working on refactoring a Node.js project, and I currently have my CSS code within my .ejs file. I need to incorporate some dynamic data into my CSS file. It works fine when the CSS is within the EJS file. However, when I move my CSS to an exte ...

checking the validity of serialized information in Ajax

I am facing a specific issue where I need to validate data before it is saved through an ajax call. When the user switches to a different URL, the save_ass_rub function is triggered. Within my application, there is a custom Window that allows users to inp ...

Is it possible to implement CSS code from a server request into a React application?

With a single React app that hosts numerous customer websites which can be customized in various ways, I want to enable users to apply their own CSS code to their respective sites. Since users typically don't switch directly between websites, applying ...

Application utilizing electron technology featuring various tabbed browsing windows connecting to secure websites

Currently, I am in the process of developing my own unique version of a platform similar to using Electron technology. The objective for this app is to provide users with the ability to view multiple URLs simultaneously, such as and , through a tabbed i ...

Can someone help me troubleshoot why my ASP.NET web service call is not working properly?

I am trying to use jQuery to call a web service method, but I keep encountering the following error: Uncaught SyntaxError: Unexpected token < This error seems to be related to the URL of my service method. Here is the code I am using: $("#btnDialog") ...

Extracting content from HTML-formatted email

When I receive inbound emails with HTML formatting that has been copied and pasted from office applications like Outlook, it often causes formatting issues when displayed on my HTML enabled UI. To address this problem, I usually copy the HTML content to an ...

Items that share identical height and margin values will appear with divergent visual presentations

I am trying to align three horizontal lines so that they are the same height and have an equal spacing between each other. However, due to variations in height and margins, some lines appear larger or smaller than others. How can I ensure they all have th ...

An issue has been identified where the Export to Excel and PDF functionality is not functioning properly within a Datatable after applying a

I am using multiple select option filtering with ajax, jQuery, and PHP in a datatable. The records are being filtered correctly, but after changing the select option, the Export to Excel/ PDF functionality is not working properly. Note:- (1) It always do ...

Access the value of localStorage when the body has finished loading or when the document is fully

Utilizing jQuery UI 1.12.1 alongside jQuery 3.1.1, I have implemented a function to save the state of two tabs in localStorage under currentIdx: $("#tabs").tabs({ active: localStorage.getItem("currentIdx"), activate: function(event, ui) { localSto ...

Is there a way to emphasize the Html.ValidationMessage during an AJAX Post?

Recently, I built a form that is submitted using jQuery AJAX. When errors are detected in the ModelState of my controller, these errors are returned in a ContentResult and displayed to the user in a DIV on the page. I'm trying to figure out how to di ...

What is the correct method to choose an element in jQuery based on the function's id parameter

I'm having trouble deleting an item in my to-do list app. deleteToDoItem: function(id) { $(id).remove(); console.log(id); }, Here is the function that calls deleteToDoItem: function deleteItem(event) { var itemID, splitID, t ...

Utilizing Odometer to pass a variable to jQuery

I'm interested in incorporating a jQuery odometer into a master page to display dynamic information. I found a helpful resource for this at this link. To achieve this, I need to fetch data from a SQL Server database using C# and then pass it to the J ...

Having trouble modifying a value in a form and submitting it to the following jsp page

I'm encountering an issue with changing the value in a hidden input element before submitting data to another JSP file (db.jsp) for processing. The value should be different depending on which button is clicked, but it always remains as the default va ...

How to traverse up to the parent element using XPath in nightwatch

Here is the structure I am dealing with: <div class="class"> <h4 class="class2"> "Condition" </h4> <div class = "click_class">Click_text </div> </div> I need to click on the element with class ="click ...

Using Javascript to retrieve a variable and dynamically updating the source of an HTML iframe

I have two JavaScript variables, 'long' and 'lat', in the code below. My challenge is to append these values to the end of the iframe URL. I would appreciate assistance on modifying the code below to achieve this. The iframe code bel ...

Modify the button's color based on a separate column within the table

Currently, I am implementing Datatables along with X-editable and including some bootstrap buttons within a table. My objective is to change the color of the button in the 'Validated' column to green when the user updates the editable 'Statu ...

Unusual scroll bar movements when using jQuery validation

When I click the Add Dependent link button, I wanted the scroll bar to automatically scroll to the bottom, and it does just that. However, there is a small issue after the postback where the text "Please fix the following problems:" briefly appears, even t ...

Is there a way to display additional data alongside form submissions that do not directly correlate with the form fields?

I am working on incorporating event registration functionality using CodeIgniter. The goal is to showcase event details and allow users to register for an event. For registration, users will be required to log in before proceeding. Once logged in, their i ...

Achieving a fixed footer at the bottom with absolute positioning on a webpage

I'm facing an issue with positioning a footer on my webpage, which is made up of div sections that are absolutely positioned. The problem arises because using the bottom property fixes the footer to the bottom of the screen rather than the bottom of t ...