Preload Images with CSS

Filed in: Web Development — April 24th, 2006

advertisement

Forget about complex javascript, we can now preload web page images with a simple CSS trick.

The Code

The trick is done via two parts, the css code and the html code.

CSS code:

CSS:
  1. #preloadedImages {
  2.        width: 0px;
  3.        height: 0px;
  4.        display: inline;
  5.        background-image: url(path/to/image1.png);
  6.        background-image: url(path/to/image2.png);
  7.        background-image: url(path/to/image3.png);
  8.        background-image: url(path/to/image4.png);
  9.        background-image: url();
  10. }


HTML code

HTML:
  1. <div id="preloadedImages"></div>

How does it work?

When the browser loads the preloadedImages CSS style, it will loads the background images without displaying it. Then, you can reference to the images elsewhere, and the images will laod instantly from browser cache memory.

[via Specere Blogs]

Bookmark and Share

Read also:

  • Thanks its worked perfect!
  • Brilliant. Worked perfectly for me too. I'm going to use this in the future..
blog comments powered by Disqus