I'm new to web-dev so please sorry me if this is a dumb question. I am confused about image preloader. I'm writing a gallery containing more or less 30-40 big images. The gally has some thumbs and if click on ones it shows the big one.
For now my HTML looks like this:
<script type="text/javascript">
var gallery_smallsize_urls = [
"0_small.jpg", "1_small.jpg",
"2_small.jpg", "3_small.jpg",
...
];
var gallery_fullsize_urls = [
"0_full.jpg", "1_full.jpg",
"2_full.jpg", "3_full.jpg",
...
];
</script>
<div id="gallery_thumbs">
<ul>
<li> <img id="gallery_thumb0" src="loading.gif" alt="0"> </li>
<li> <img id="gallery_thumb1" src="loading.gif" alt="0"> </li>
<li> <img id="gallery_thumb2" src="loading.gif" alt="0"> </li>
<li> <img id="gallery_thumb3" src="loading.gif" alt="0"> </li>
...
</ul>
</div>
now, i have 2 features in my mind:
Queue of loading. The page is loaded. On document ready the js begin the queue of thumbs. That means: load the 1° thumb and only when it finished begin to load the 2°. And so on.
Preloading of the fill size image. When the user click on the thumb is has to wait less time possible to show the full (because the full size images are already cached in memory).
Now, i have found this voted answer:
function preload(arrayOfImages) {
$(arrayOfImages).each(function(){
$('<img/>')[0].src = this;
// Alternatively you could use:
// (new Image()).src = this;
});
}
but i think it is only the answer of the point 2. What happens here? The images are loaded in the same time? I don't know how to approach the point 1. I think that the best way is using the Deferred object....
Some advice?