Code Snippet

Home » Code Snippets » jQuery » Display Loading Graphic Until Page Fully Loaded

Display Loading Graphic Until Page Fully Loaded

<!DOCTYPE html>
<html class="no-js">

<head>
	<meta charset='UTF-8'>

	<title>Simple Loader</title>

	<style>
		/* This only works with JavaScript,
		   if it's not present, don't show loader */
		.no-js #loader { display: none;  }
		.js #loader { display: block; position: absolute; left: 100px; top: 0; }
	</style>

	
	<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>

	
	<script src="https://github.com/Modernizr/Modernizr/raw/master/modernizr.js"></script>
	<script>
		// Wait for window load
		$(window).load(function() {
			// Animate loader off screen
			$("#loader").animate({
				top: -200
			}, 1500);
		});
	</script>
</head>

<body>

	
	<img src="download.png" id="loader">

	
	<img src="http://farm6.static.flickr.com/5299/5400751421_55d49b2786_o.jpg">

</body>

</html>

Reference URL

Subscribe to The Thread

  1. Avkash

    Thanks for sharing….. Actually I’m finding the same thing. Very helpful to me….

  2. Seems really good, just; I’d change the
    <img src=”download.png” id=”loader”>
    to
    <img src=”download.gif” id=”loader”>
    Otherwise it wouldn’t be animated.

Speak, my friend

At this moment, you have an awesome opportunity* to be the person your mother always wanted you to be: kind, helpful, and smart. Do that, and we'll give you a big ol' gold star for the day (literally).

Posting tips:
  • You can use basic HTML
  • When posting code, please turn all
    < characters into &lt;
  • If the code is multi-line, use
    <pre><code></code></pre>
Thank you,
~ The Management ~