Preloaders are a fantastic addition to any Divi WordPress website. As the first element your users encounter upon entering your site, preloaders remain visible until the entire page is fully loaded. This not only prevents users from experiencing delays while waiting for website resources to load but also provides a seamless, professional feel to your site. Follow this guide to easily add a preloader to your website using CSS.
Adding a Preloader to Your Divi Site
Details
Snippets Demo
Code
Description:
Add the following CSS to the Theme Options > General > Custom CSS section. Be sure to update the background image URL to a GIF that you have uploaded to your Media Library. Additionally, adjust the width and height CSS properties to accommodate the size of your GIF.
Language: CSS
Where to add: Divi Theme Options
/* PRELOADER */
.preloader {
position: fixed; /* Fixes the preloader to the viewport */
top: 0; /* Aligns the preloader to the top of the viewport */
left: 0; /* Aligns the preloader to the left of the viewport */
right: 0; /* Extends the preloader to the right edge of the viewport */
bottom: 0; /* Extends the preloader to the bottom edge of the viewport */
background-color: #fefefe; /* Sets the background color of the preloader */
z-index: 100000; /* Ensures the preloader is on top of all other elements */
height: 100%; /* Sets the height to cover the entire viewport */
width: 100%; /* Sets the width to cover the entire viewport */
overflow: hidden !important; /* Prevents any overflow content */
}
.preloader .status {
width: 50px; /* Sets the width of the loading GIF */
height: 50px; /* Sets the height of the loading GIF */
position: absolute; /* Positions the GIF absolutely within the preloader */
left: 50%; /* Centers the GIF horizontally */
top: 50%; /* Centers the GIF vertically */
background-image: url(/wp-content/.../loading.gif); /* Sets the loading GIF image */
background-repeat: no-repeat; /* Prevents the background image from repeating */
background-position: center; /* Centers the background image */
-webkit-background-size: cover; /* Ensures the background image covers the container (for WebKit browsers) */
background-size: cover; /* Ensures the background image covers the container */
margin: -50px 0 0 -50px; /* Offsets the GIF to perfectly center it */
opacity: .5; /* Sets the opacity of the GIF */
}
Description:
Add the following JavaScript to the
Language: Javascript
Where to add: Divi Theme Options
// Ensures the whole site is loaded before running the script
jQuery(window).load(function () {
"use strict"; // Enforces strict mode to catch common coding errors
// Checks if the Divi Builder (backend and frontend) is not active
if (jQuery('.et-bfb').length <= 0 && jQuery('.et-fb').length <= 0) {
// Fades out the loading animation
jQuery(".status").fadeOut();
// Delays for 1 second, then fades out the whole preloader DIV
jQuery(".preloader").delay(1000).fadeOut("slow");
} else {
// If Divi Builder is active, hides the preloader immediately
jQuery(".preloader").css('display', 'none');
}
});
<!-- Preloader DIV that covers the entire website -->
<div class="preloader">
<!-- Status DIV for the loading animation -->
<div class="status"></div>
</div>
Related Snippets
Easy | CSS
How to Align the Search Button in Divi Engine Filter: A Simple CSS Snippet
Aug 27 2024
Easy | CSSJavascript
Implementing a Lightbox for ACF Images in Your WordPress Site
Jul 10 2024
Explore more from Divi Engine
Divi Form Builder
From simple contact forms to complex frontend post or product creation, Divi Form Builder has you covered.
Divi Machine
Build complex websites that displays dynamic fields you can filter, search and so much more with the Divi Builder.
Divi BodyCommerce
A versatile toolkit for developers using Divi and WooCommerce together, designed to boost your e-commerce site and achieve greater conversion rates.
Divi Membership
Monetize your Divi websites by transforming them into membership sites with seamless subscription management, user-friendly interfaces, and customizable membership tiers.
Divi Machine Accounts
Build an account area for your customers to edit their details, access wishlist, submitted posts and more. *Note: Requires Divi Machine installed and active
Divi Ajax Filter
Filter WooCommerce, Posts & Custom Posts without reloading the page.
Divi Mobile
Divi Mobile helps you create beautiful looking mobile menus without having to code.
Divi Nitro
Give your Divi website that extra boost of speed with our Divi Nitro plugin to enhance your customer's experience.
Divi Protect
Password protect the content of your Divi website with our Divi Protect plugin. Keep unwanted eyes out!
Divi Mega Menu
Improve the user experience of your Divi website with our Divi Mega Menu plugin by creating dynamic menus using the Divi Builder.