How to Make Full Screen Page Loader using JavaScript

When you search for a solution for full-screen overlay, the most website provides solutions using JavaScript or jQuery. The following solution is using CSS and JavaScript of jQuery. Here we are going to create a page loader window those overlays an existing HTML page and disabling all links and bringing into focus on the page loader window.

CSS code

<style>
.overlay {
    background: #e9e9e9;
    display: none;
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    opacity: 0.5;
}
#loader {
    -moz-border-bottom-colors: none;
    -moz-border-left-colors: none;
    -moz-border-right-colors: none;
    -moz-border-top-colors: none;
    animation: spin 2s linear infinite;
    border-color: #3498db #f3f3f3 #f3f3f3;
    border-image: none;
    border-radius: 50%;
    border-style: solid;
    border-width: 16px;
    height: 120px;
    left: 50%;
    margin: -75px 0 0 -75px;
    position: absolute;
    top: 50%;
    width: 120px;
    z-index: 1;
}
@-webkit-keyframes spin {
  0% { -webkit-transform: rotate(0deg); }
  100% { -webkit-transform: rotate(360deg); }
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}
</style>

HTML code

<body>
<div id="loaderbg" style="position: fixed; top: 0px; left: 0px; background: rgba(0, 0, 0, 0.6) none repeat scroll 0% 0%;
	 z-index: 5; width: 100%; height: 100%; display: none;">
	<div id="loader"></div>
</div>
</body>

jQuery/JavaScript code

<script>
	function showPageloader() {
		document.getElementById("loaderbg").style.display = "";
	}	
	function hidePageloader() {
		document.getElementById("loaderbg").style.display = "none";
	}
</script>	

Leave a Reply

Your email address will not be published. Required fields are marked *