Basically, you want to listen to load or readystatechange events from the img element.
So you need to do this:
$(window).load(function(){
$('.image-principale img').on("load readystatechange", function(){
// Here you can check whether it state complete by checking
// if(this.complete || (this.readyState == 'complete' && e.type == 'readystatechange') ) { }
$(this).parent().css('height', $(this).height());
});
});
But... this way have a few ( big ) caveats. Namely that it will not "always" work, and it will not work with "cache" images ( sometimes ).
The best way is actually an extent of the code above ( that will check some more conditions that are quite hard to check ) from Desandro, a library called jquery.imagesLoaded
It will check for loading events, and some more conditions ( like broken images, cached images, loaded element, ... ) and gives you a feedback when ALL elements are loaded.
Usage is ( you can see more on the website ) :
// Loading script
var dfd = $('#my-container').imagesLoaded(function($images, $proper, $broken){
//Here you can do a loop on $proper that is the list of images that properly loaded.
}); // save a deferred object and use dfd later
You can also have, for every image loaded, a callback:
dfd.progress(function( isBroken, $images, $proper, $broken ){ });
I'm quite sure this will solve your ( very old... sorry ) problem. I post it here as it could help some other people.