While this may seem super simple and obvious to some, others may not know how to do this so it bears writing. We're not going to use any fancy javacript or anything, just a simple div and a little styling with an image.
In a nutshell, you're going to wrap a div around your image and give it a class. Then, in your stylesheet you'll style the div with css. Head over to AjaxLoad.info and create your own loading image, that's where I got the one I use on my photoblog.
The HTML
<div class="img-preloader">
<img src="/path/to/your/image.jpg" alt="My Image" />
</div>
As you can see we just wrapped a div with a class of img-preloader around our main image. Now let's check out the styling.
The CSS
.img-preloader{
background: url (/path/to/your/preloader/image/preloader.gif) 50% 50% no-repeat;
}
What this does is gives your div, the one you wrapped around your main image, a background image. The background image is set to appear in the center of your div. When the page loads you see the preloading image and your main image hides the preloading image. Make sense?
Here is an example of the div without the image inside:
Like what you see? Snag my blog feed and stay up to date. Check out all of my site feeds here.
Back Up