Skip to content

Instantly share code, notes, and snippets.

@softiconic
Last active December 2, 2023 18:34
Show Gist options
  • Save softiconic/afc50628def8b563c0faae1c7a89da95 to your computer and use it in GitHub Desktop.
Save softiconic/afc50628def8b563c0faae1c7a89da95 to your computer and use it in GitHub Desktop.
Smart Preloader for WordPress
window.addEventListener('load', function(event) {
fadeAway();
function fadeAway() {
var delay = 1000; // Adjust the delay in milliseconds as needed
var duration = 500; // Adjust the duration in milliseconds as needed
// Check if jQuery is defined and if not, load it
if (typeof jQuery === 'undefined') {
var script = document.createElement('script');
script.src = 'https://code.jquery.com/jquery-3.6.0.min.js'; // You can change the jQuery version as needed
script.onload = function() {
jQueryLoaded();
};
document.head.appendChild(script);
} else {
jQueryLoaded();
}
function jQueryLoaded() {
setTimeout(function() {
jQuery('.smart-page-loader').fadeOut(duration, function() {
jQuery('body:not(".elementor-editor-active")').removeClass('wp-smart-body');
});
}, delay);
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment