I am working on a Phonegap application in which I am trying to display a varying amount of images to the user. My GUI follows the principles found in this article.
I know how many images I will be getting before I make my ajax GET request, so I add the correct amount of images that display a loading gif to the relevant div using jQuery's append method. I then begin my ajax request.
In my success callback I have the following method
imageblock.forEach(function(entry)
{
changeImage(i, entry, i*1000);
i++;
});
the changeImage() function is as follows:
function changeImage(index, src, timeout)
{
setTimeout(function()
{
$("#image"+index).attr("src", 'data:image/png;base64,'+src);
},timeout);
}//changeImage
Without using the setTimeout() I have observed the app to hang while it renders the images. So this works just fine, as it apparently gives the browser enough time to render the image.
I was wondering if there was a better way than waiting a fixed interval of time to load the next image. I looked into onLoad() but that seems to fire when I originally create the image tag that displays the loading gif. Is there any way to tell when the image is done rendering?