1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
   |  
<html>
<head>
<style type="text/css">
ul#portfolio { margin:0; padding:0; }
ul#portfolio li { float:left; margin:0 5px 0 0; width:250px; height:250px; list-style:none; }
ul#portfolio li.loading { background: url(spinner.gif) no-repeat center center; }
</style>
<script>
// DOM ready
$(function () {
 
// image source en forme de tableau
var images = new Array();
	images[0] = 'http://farm4.static.flickr.com/3293/2805001285_4164179461_m.jpg';
	images[1] = 'http://farm4.static.flickr.com/3103/2801920553_656406f2dd_m.jpg';
	images[2] = 'http://farm4.static.flickr.com/3248/2802705514_b7a0ba55c9_m.jpg';
 
                        // on parcours tout les éléments li
			$("ul#portfolio li").each(function(index,el){
			// new image object
			        var img = new Image();
			// image onload
			        $(img).load(function () {
			// on cache les images en premier
			            $(this).css('display','none'); 
 
			            $(el).removeClass('loading').append(this);
			            $(this).fadeIn();
			        }).error(function () {
						$(el).remove();
			        }).attr('src', images[index]);
			});
 
		});
</script>
</head>
<body>
<ul id="portfolio">
<li class="loading"></li>
<li class="loading"></li>
<li class="loading"></li>
</ul>
</body>
</html> | 
Partager