You can make a Event load for each image that returns from Ajax and calls a function when all are loaded.
A suggestion would be to create a div hidden to receive the return of Ajax with the images, count how many images returned and make a .each() creating a on load for each one. The images will be hidden in the div, and when all are loaded, you send the HTML of that div for the the div end and makes the fadeIn().
Create a div hidden anywhere:
<div id="oculta"></div>
And put in her CSS:
#oculta{
display: none;
}
Create a function that will make the transition:
function mostraDiv(){
// envia o HTML da div oculta e faz o fadeIn na div principal
$("#div-da-aba").html( $("#oculta").html() ).hide().fadeIn();
$("#oculta").empty(); // esvazia div oculta
}
In the success ajax:
success: function(data){
$("#oculta").html(data); // envia o retorno para a div oculta
var imgs = $("img", "#oculta"); // busca imagens pela tag img
var imgs_conta = imgs.length; // conta o número de imagens
var conta = 0; // seta um contador
// aqui eu crio um event load para cada imagem
imgs.each(function(i,e){
e.onload = function(){
conta++; // quando a imagem é carregada, incremento o contador
// se o contador alcançar o número de imagens, chamo a função
if(conta == imgs_conta) mostraDiv();
}
});
}
Why did I suggest using a hidden div?
So that in the div main you can place a message of "Opening..." or "Loading..." or some animated upload while the images are being loaded in hidden.
I believe the best is to decrease the size of the images
– Costamilam
Unfortunately this possibility does not exist, and even if it existed if the user is with a slow connection the images will take to load independent of the size...
– Guilherme Barbosa
Managed to solve?
– Sam