jyoseph.com
«    »

Fake Image Preloader for Photoblogs

03.17.2008     Comments     Related    
Why not spice up your blog or photoblog by displaying a preloading image while your main photo is loading? This is by no means a new technique, I've been doing it for quite a few years and you see it all over the web now. A few years back I had a short DIY on how to do this but it got moved somewhere. So, here it is again!

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:

Your image goes inside this div. When your main image loads, it hides the background loading image.
Tags: css   html   photoblog   tutorial  
Share: Ping This! Add to Delicious Add to Digg Add to Newsvine Add to Reddit Add to technorati Add to Yahoo Add to Spurl Add to Smarking Add to Magnolia

Possibly Related

Like what you see? Snag my blog feed and stay up to date. Check out all of my site feeds here.

Back Up