views:

63

answers:

1

Hi,

I want to load images from my server to an image gallery. The problem is that after loading the web page my program loads all the images first and then displays them all at the same time. As a result, there is a significant wait for them to load.

I would like to display the images one at a time as they load, showing an "busy" indicator on the images that haven't loaded yet.

Here is my code:

controller.labelForIndex = function (index) { 
    var arrayIndexNO=(index%(temp.length/2))*2;
    var appID=temp[arrayIndexNO];
    var iconImage=appID+".png";

    $(".ad-carousel-view .cells > li").css("background-image", "url("+iconImage+")");

    return temp[arrayIndexNO+1];
};

This function is called 10 times to load 10 pngs and display them in a cell, but my code loads all images first and then displays them all at the same time.

+1  A: 

http://www.mail-archive.com/[email protected]/msg00377.html

Joni
hi...i see the code...but i don't know how to add the plugin....i want to add the image here $(".ad-carousel-view .cells > li").css("background-image", "url("+iconImage+")");....then how to call the plug in??
Rony
I think that you can not fetch background-images asynchronously. You should use real images instead.First make images with no src and then with javascript load those images and update all src attributes.
Joni
can u give code plz??
Rony
Please try to move your images to real ones instead of background-images and show us your updated code. What I would like to see is that you try to ask more specific questions if you face any problems.
Joni
Hi,look at this $(".ad-carousel-view .cells > li").css("background-image", "url("+iconImage+")");1>here iconImage is an URL of image which i want to load from server2>this is called suppose 10 times...3>each time it will get new iconImage URL.4>my prob is that all the image load and display synchronously...i want asynchronously...
Rony
I think you have a problem here when using css property background-image and not <img src="iconImage">. I suggest you to try real image elements instead stylesheet background.You could also load images with javascript and after load is complete update your css attributes to use wanted background-image. While ajax is loading your images you could use your busy indicator image instead.
Joni
i think u are talking about exactly what i am wanting.....i am actually an iPhone Application Developer.....very little know javascript.......i am developing an application where i need javascript and have to add it with the total code...so can u plz give u simple but straightforward code to do that...just the coding version of ur above idea...i have no intension to copy but i actually want to learn by observing...
Rony
Something not working, but might give you some hints.<html><head><title>t</title></head><body><img class="myimage" data-name="cat.jpg" src="indicator.jpg"><script><!-- $(document).onLoad(function(){ $(".myimage").ajax( url: $(this).getAttr("data-name"), context: document.body, success: function(){ $(this).src = $(this).getAttr("data-name") } })
Joni