How to add pre-loader to website with animation

wp nav menu3

Add HTML:

Put this HTML in your website after BODY tag.

HTML Structure description:
  1. .loader_backdrop: This element is used to cover full width and height of device sceen.
  2. .loader: This element is used to wrap animation.
  3. .animate: This element is used for Spin animation.
<div class="loader_backdrop">
	<div class="loader"><span class="animate"></span></div>
</div>

Add CSS:

Put this style in your CSS file.

.loader_backdrop {
  width: 100%;
  height: 100%;
  position: fixed; z-index:1000;
  top: 0;
  left: 0;
  background-color: #000000;
  display:flex;
  justify-content: center;
  align-items: center;
}
.loader_backdrop .loader {
  display: inline-block;
}
.loader_backdrop .loader .animate {
	border: 16px solid #f3f3f3;
	border-top: 16px solid #3498db;
	border-radius: 50%;
	width: 30px;
	height: 30px;
	animation: spin 2s linear infinite;
	display: block;
}
@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

Add JavaScript:

Put this script in your JS file or in bottom of HTML file before end </html> tag.

jQuery(window).on("load",function(){
  jQuery(".loader_backdrop").fadeOut("slow");
});

Leave a Reply