Emulate Ajax Image Loading with CSS

This is just a nifty little trick to add a simple ajax-style loader graphic to your images. It gives the vistor a visual indication that the images are still loading. It works great for image galleries or anywhere it might take a few seconds for an image to load initially. It’s all done with a little css and takes just a couple of minutes to do.

ajax style loader

Here’s some basic markup

<div id=”main”>
<img src=”images/something.jpg” alt=”something” title=”image1″ width=”450″ height=”300″ />
</div>

and here’s the CSS needed to add the loader image…

#main img {
    background-color:#FFF;
    background-image:url(images/ajax-loader.gif);
    background-repeat:no-repeat;
    background-position: center center;
}

That’s pretty much it. It really works best when you define the height and width of the image in the markup or else with CSS. Also, this isn’t really a good choice for images with transparency since the loader image would still be visible in the background.

Click Here to See the Demo Page

You can create some custom ajax-style downloder images at the AjaxLoad website.

This entry was posted in Misc. Stuff. Bookmark the permalink.

24 Responses to Emulate Ajax Image Loading with CSS

  1. Pingback: University Update - AJAX - Emuate Ajax Image Loading with CSS

  2. Hermawan says:

    cool.. have a lot and more creativities and imaginary.. things… brilliant… ! nice…

    i like your style… ^^

  3. c00lryguy says:

    Awesome stuff dude, love to keep things simple like this.

  4. Lamiseaunet says:

    Well done ! It so simple, as usual good ideas.

  5. Do you see the image partially loading, i.e. is it all or nothing?

  6. Pingback: links for 2007-08-18 | giancarlo.dimassa.net

  7. FavHost says:

    Good stuff. I’ll be using it in some of the websites I design.

    Thanks for the info!

  8. unTECHy.com says:

    Thanks for the info. I’m just learning about ajax and I’m liking it.

  9. Pingback: CSSVault Blog » Blog Archive » Emuate AJAX Image Loading with CSS

  10. I like this alot. Thanks for sharing this.

  11. John M says:

    Wow. CSS Ajax image loader…

    Stunning! Great work, thanks for sharing!

    John

  12. Luxbot says:

    Thank You! We will pass this on to our blog!

  13. Sadia says:

    Nice Trick , but i think there is no Ajax Involved , it is simple CSS , you applied the Background image on Table Cells :) , Good

  14. Hmmm. You think? That’s exactly the point, hence the post about emulating the ajax style loaders. No ajax, just a nice way to stick some little loader images in with CSS.

  15. That Guy says:

    Perhaps I’m wrong..but wouldn’t this in fact use more bandwidth and slow down the loading process of multiple images by now instead of displaying a single image, you are displaying two (loading image and actual image).

    Or is that just me?

  16. Heavy says:

    Very neat…good work, thanks.

  17. You would in theory choose a very small loader gif image for the background, which you would apply to all the images via the CSS. Essentially, you’re just loading one small image in addtion to the others so there shouldn’t be any bandwith concerns or other performance problems.

  18. Pingback: Sexta-feira dos Web Standards #3 · project.47 - Portfolio e blog sobre Web Standards

  19. I am using Mozilla Firefox 2.0.0.10 under Gnome Desktop Environment on Fedora 8. When I opened this page (more precisely viewing “LOADING” demo frame) the X sucked my CPU resources ( almost 100% CPU usage).

    Maybe problem with firefox and X, maybe NOT?! I don’t know, just sharing my experience with this CSS stuff!

  20. Nadia Dxb says:

    Good one. I will use it in some of the websites I design.

  21. Wow, so simple, yet so smart. Awesome trick dude. I love trying new things with CSS.

    - Dwayne Charrington.
    http://www.dwaynecharrington.com

  22. Tim B. says:

    Great trick, not sure why I hadn’t thought of doing that before… I love to make things look complex when they in fact are not. I implemented this in a matter of about 5 minutes or less, impacting litterally thousands of thumbnails and images, not all on one page of course…

  23. minikperi says:

    Great article1 ÅŸ’ll use it but i was looking for loading image to a spacific area with ajax when mouse over an element.

  24. k?z oyunlar? says:

    HI i need your help i really want to create my own website/web page but i dont know how to go about doing it so can you please help me out