Só mostrar a imagem depois de carregar
Essa semana, comecei mexer um pouco no jquery, e, embora existam "mil soluções" que carreguem uma imagem, resolvi fazer algo simples para entender melhor o funcionamento.
Cheguei no seguinte código:
$("a[rel=galeria]").click ( function() { // Click
var img = $(this).attr("href");
$.ajax({ // Ajax
url: "galeria.php",
type: "POST",
data: ({url: img }),
success:function(html){
//alert(html);
$('#imagem')
.removeClass('carregando')
.append(html);
$("#imagem img").fadeIn();
},
/*complete: function() {
//$('#imagem').removeClass('carregando');
},*/
beforeSend: function() {
$('#imagem').addClass('carregando');
$("#imagem img").remove();
}
}); // Fim Ajax
return false;
}); // Fim Click
galeria.php
<?php
echo("<img src={$_POST['url']}>");
?>
O problema desse código é que, ele vai mostrando a imagem aos poucos, e não, totalmente, como no lightbox, por exemplo.
Onde estou errando?
Abs
Discussão (2)
Carregando comentários...