Buongiorno ragazzi!
Ho una gallery che sfrutta jQuery, la gallery attende che tutte le immagini siano precaricate prima di far partire lo slideshow. Questa cosa è un po' 'rognosetta' nel caso di molte immagini in quanto l'utente potrebbe dover attendere parecchi secondi prima di poter visualizzare la gallery.
Il mio intento è quello di fare in modo che si avvii non appena le prime 2 o 3 foto siano state caricate e che attenda nel caso l'immagine successiva non sia ancora stata caricata (di modo da non mostrare immagini parziali).
Grazie di cuore a chiunque mi darà una mano!!!
Di seguito la porzione di codice:
$.Slideshow.prototype = {
_init : function( options ) {
this.options = $.extend( true, {}, $.Slideshow.defaults, options );
// set the opacity of the title elements and the image items
this.$imgItems.css( 'opacity', 0 );
this.$imgItems.find('div.ei-title > *').css( 'opacity', 0 );
// index of current visible slider
this.current = 0;
var _self = this;
// preload images
// add loading status
this.$loading = $('<div class="ei-slider-loading">Loading</div>').prependTo( _self.$el );
$.when( this._preloadImages() ).done( function() {
// hide loading status
_self.$loading.hide();
// calculate size and position for each image
_self._setImagesSize();
// configure thumbs container
_self._initThumbs();
// show first
_self.$imgItems.eq( _self.current ).css({
'opacity' : 1,
'z-index' : 10
}).show().find('div.ei-title > *').css( 'opacity', 1 );
// if autoplay is true
if( _self.options.autoplay ) {
_self._startSlideshow();
}
// initialize the events
_self._initEvents();
});
},
e poi:
_preloadImages : function() {
// preloads all the large images
var _self = this,
loaded = 0;
return $.Deferred(
function(dfd) {
_self.$images.each( function( i ) {
$('<img/>').load( function() {
if( ++loaded === _self.itemsCount ) {
dfd.resolve();
}
}).attr( 'src', $(this).attr('src') );
});
}
 .promise();
},