tags:

views:

64

answers:

1

any technique that can be used to place on image-holder while waiting for image to load. a typical way of doing is placing dummy image while waiting for real image to load.

my image code like below

<div id="realimage" style="background-image: real_image.jpg"/>
  1. any nice way to put as image holder without putting dummy image? using pure css without javascript possible?
+1  A: 

You can use the data URI scheme as the source of the dummy image. It will load with the HTML and will not require an additional request.

So, in your CSS you could do this (embedding a red dot):

.realimage {background: url('data:image/png;base64,
iVBORw0KGgoAAAANSUhEUgAAABAAAAAQAQMAAAAlPW0iAAAABlBMVEUAAAD/
//+l2Z/dAAAAM0lEQVR4nGP4/5/h/1+G/58ZDrAz3D/McH8yw83NDDeNGe4U
g9C9zwz3gVLMDA/A6P9/AFGGFyjOXZtQAAAAAElFTkSuQmCC')}

This is not supported on IE 6/7 and in IE 8 there is a 32k limit on the size of the image.

Oded
I don't think this will answer the question, because he's already using `background-image` for the *real* image. Also, my brain, upon seeing this, is going "images don't belong in CSS files! They just don't!" Best answer given the circumstance though
Yi Jiang
@Yi Jiang - I know where you are coming from. Data URIs can also be placed directly in the `<img src="" />` tag, if that's any comfort.
Oded
@Oded , the dummy image that you suggested. how do i use pure css to replace the realimage in the 'div' ?
cometta
@cometta - What I had posted _is_ pure CSS
Oded
@Oded anyway to do when the page first loaded, dummy image is used, when real image is ready, it replace the dummy image?
cometta
@cometta - you will have to use javascript for that, replacing the page src and clearing out the background url from the style.
Oded