Possible Duplicate:
jQuery callback on image load (even when the image is cached)
I have a #mainImg img
with a property of opacity:0;
.
When the page loads, I trigger the following jQuery code :
$("#mainImg img").load(function(){
$("#mainImg img").center(); // center everything
$("#mainImg img").animate({"opacity": "1"}, "400"); // fade the image in
});
It works il firefox/chrome/safari. I use the .load()
method because in webkit browsers, the width and height are set after the image is loaded.
But when I try to load another image when I click on a thumbnail, the image doesn't work in safari (and works in chrome and firefox).
Here is my code for the thumbnail system :
$("#th2").click(function() {
$("#mainImg").html('<img src="' + new_th2_link + '" />');
$("#mainImg img").load(function(){
$("#mainImg img").center();
$("#mainImg img").animate({"opacity": "1"}, "400");
});
});
In Safari the #mainImg img
has a property of width:0; height:0;
. Is Safari too fast ?