2010-03-23 6 views

Répondre

5

Une solution pure javascript est ceci:

var realImage = document.getElementById('realImageId'); 
var loadingImage = document.getElementById('loadingImage'); 
loadingImage.style.display = 'inline'; 
realImage.style.display = 'none'; 

// Create new image 
var imgPreloader = new Image(); 
// define onload (= image loaded) 
imgPreloader.onload = function() { 
    realImage.src = imgPreloader.src; 
    realImage.style.display = 'inline'; 
    loadingImage.style.display = 'none'; 
}; 
// set image source 
imgPreloader.src = 'path/to/imagefile'; 
Questions connexes