Ho messo il tutto su altervista aggiungendo anche una immagine prima del caricamento dell'immagine.
Codice PHP:
var GALLERY = {
container: '#gallery',
url: 'getImages',
delay: 5000,
load: function() {
var _gallery = this;
jQuery.ajax({
type:"get",
url: this.url,
beforeSend: function() {
// fade out and remove the old images
jQuery(_gallery.container)
.find('img')
.fadeOut('slow', function() {
jQuery(this).remove();
});
// add the spinner
jQuery('<div></div>')
.attr('class', 'spinner')
.hide()
.appendTo(_gallery.container)
.fadeTo('slow', 0.6);
},
success: function(data){
var images = data.split('|');
jQuery.each(images, function() {
_gallery.display(this);
});
},
complete: function() {
setTimeout(function() {
_gallery.load();
}, _gallery.delay);
// remove the spinner
jQuery('.spinner').fadeOut('slow', function() {
jQuery(this).remove();
});
}
});
},
display: function(image_url) {
jQuery('<img></img>')
.attr('src', '../../images/' + image_url)
.hide()
.load(function() {
jQuery(this).fadeIn();
})
.appendTo('#gallery');
}
}
jQuery(document).ready(function(){
GALLERY.load();
});
Il problema è che l'immagine che indica il caricamento nel mio caso lo spinner si rivisualizza anche dopo che l'immagine sono caricate.