Skip to content

Instantly share code, notes, and snippets.

@kashmiriapp
Created July 6, 2021 06:44
Show Gist options
  • Save kashmiriapp/ba14d190f4ac8ae8c92934e1e199cb9c to your computer and use it in GitHub Desktop.
Save kashmiriapp/ba14d190f4ac8ae8c92934e1e199cb9c to your computer and use it in GitHub Desktop.
PreLoadMe, a lightweight jQuery website preloader
<!-- Preloader -->
<div id="preloader">
<div id="status">&nbsp;</div>
</div>
<img width="100%" src='https://unsplash.it/3000/3000/?random' />

PreLoadMe, a lightweight jQuery website preloader

PreLoadMe is a lightweight preloader for any webcontent. Powered by jQuery and CSS it is fully responsive and will run on all modern desktop- and mobile browsers with no additionals plugins. PreLoadMe displays a loading animation until the browser fetched the whole webcontent and will fade out the moment the page has been completely chached. Because the simplicity of PreLoadMe, it can be easily customized and adapted to your needs.

A Pen by Niklaus Gerber on CodePen.

License.

$(window).on('load', function() { // makes sure the whole site is loaded
$('#status').fadeOut(); // will first fade out the loading animation
$('#preloader').delay(350).fadeOut('slow'); // will fade out the white DIV that covers the website.
$('body').delay(350).css({'overflow':'visible'});
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
body {
overflow: hidden;
}
/* Preloader */
#preloader {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: #fff;
/* change if the mask should have another color then white */
z-index: 99;
/* makes sure it stays on top */
}
#status {
width: 200px;
height: 200px;
position: absolute;
left: 50%;
/* centers the loading animation horizontally one the screen */
top: 50%;
/* centers the loading animation vertically one the screen */
background-image: url(https://raw.githubusercontent.com/niklausgerber/PreLoadMe/master/img/status.gif);
/* path to your loading animation */
background-repeat: no-repeat;
background-position: center;
margin: -100px 0 0 -100px;
/* is width and height divided by two */
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment