I have a little problem that I just found after I thought this project was finished. It worked fine on my local server, but when I pushed the code in real time, the images could take half a second to properly load the reason for the appearance of a small thumbnail of the page on top of the loaded image. grrr
alt text http://img815.imageshack.us/img815/985/loading.jpg
So what's going on? First, the function first works on window.load, which created a large number of list items with the loading of the gif as a bg image.
This function then issues the tag <img>to the first element of the list with the help onloadthat calls the second function
This second function loops through the XML file and wraps the URL in xml with a tag <img>and puts it in the next empty one LI. that's the problem. At the moment, it puts <img src=$variable onload=loadnextimage() />in a list item before it loads.
My code is:
$(window).load(function() {
txt="";
for(d=0;d<100;d++)
{
txt=txt + "<li class='gif' id='loading"+d+"'></li>";
}
document.getElementById('page-wrap').innerHTML=txt;
document.getElementById('loading0').innerHTML="<img src='images/0.jpg' onLoad='loadImages(0)' />";
});
function loadImages(i){
i++
$.ajax
({
type: "GET",
url: "sites.xml",
dataType: "xml",
async: "true",
success: function(xml)
{
var img = $(xml).find('image[id=' + i + ']'),
id = img.attr('id'),
url = img.find('url').text();
$('#loading'+i).html('<img src="'+url+'" onLoad="loadImages('+i+')" />').hide();
$('#loading'+i).fadeIn();
}
});
}
I have a feeling that it can be quite difficult to achieve this, as I configured it, and I have a feeling that I may need to create an img object and wait to load it.
Once the page is cached, loading clearly works fine, but it hurts a bit before loading, so I need to fix it. any advice welcome :) thanks
source
share