javascript preloader
Posted: Wed Oct 08, 2008 10:11 am
i ve a table that contains images in its tds. i'd like to run a preloader image pending the time the images in the tds load, but when ever i run the preloadimages() onload event of the body tag the preloaders are loaded and are not repalced wen the real images are loaded. im sure its a bug on my script pls help me resolve it.
Again i'd would like to understand the concept behind the javascript image object, when does the image begin to load? is it when the object src is set to the image path or when ?
function initialiseImgs(){
var imgs = document.getElementById('content').getElementsByTagName('img')
return imgs
}
function preloadImages(){
var imgs = initialiseImgs();
var count = imgs.length
var imageSrc=''
var virtualImg = new Image()
for(i=0; i<count; i++){
imageSrc = imgs.src
virtualImg.onload = function(){imgs.src=imageSrc;}
imgs.src = 'loader.gif'
virtualImg.src = imageSrc
}
}
Again i'd would like to understand the concept behind the javascript image object, when does the image begin to load? is it when the object src is set to the image path or when ?
function initialiseImgs(){
var imgs = document.getElementById('content').getElementsByTagName('img')
return imgs
}
function preloadImages(){
var imgs = initialiseImgs();
var count = imgs.length
var imageSrc=''
var virtualImg = new Image()
for(i=0; i<count; i++){
imageSrc = imgs.src
virtualImg.onload = function(){imgs.src=imageSrc;}
imgs.src = 'loader.gif'
virtualImg.src = imageSrc
}
}