tags:

views:

22

answers:

2

i have a div element, with very big size background image. so, is it possible, to set a little size image as backgrount, untill the big size image loads.

thanks

+2  A: 

I guess you could put another div element underneath it (using the z-index property) and give that the faster loading background image.

Whether that is practical to do, depends on your Layout, you'd have to give more information about that.

There's also the ages-old lowsrc HTML 4 property that still seems to be pretty well supported (I have not tried it myself since Netscape 4), but that won't work for background images.

Pekka
it's just a single <div>, but it hasn't position absolute( how i know, in that case i cant use Z-index?)
Syom
@Syom yup, then it becomes really difficult, especially if it has a variable height/width. If it doesn't, you may be able to put both above each other using `position: absolute`.
Pekka
@Pekka no, it has it's own height, and width, and content in it:(
Syom
+1  A: 

CSS:

.that-div {
    background-image:url(/path/to/small-image.png);
}

jQuery:

$(function () {
    var bigImg = new Image(),
        bigImgSrc = '/path/to/big-image.png';

    bigImg.src = bigImgSrc;

    $(bigImg).load(function(){
        $('.that-div').css('background-image':'url('+bigImgSrc+')');
    });
});
gryzzly
I'm sorry, I should definitely suggest a pure JavaScript version.
gryzzly
@gryzzly i like you solution, thanks;) i'll use it's logic to write the same with javascript
Syom