Hi again Paul,
So I would prefer to assign a function to the load event of the image, but I'm having difficulty. I have changed my code to add a load function:
Code:
$(document).ready(function(){
$('.thumb img').each(function(){
$(this).load(function(){
var width = $(this).width();
var height = $(this).height();
if (width > height){ //landscape
imgHeight = 50;
imgWidth = width/height*50;
} else { //square or portrait
imgHeight = height/width*50;
imgWidth = 50;
}
$(this).css({height: imgHeight, width: imgWidth});
});
});
alert($('.thumb img:first').clientHeight());
$('.thumb').click(function(){
var src = 'url(' + $(this).children(':first').attr('src') + ')';
$('#photoframe').css({backgroundImage: src, backgroundRepeat: 'no-repeat', backgroundPosition: 'center'});
});
});
But the script is still running before the images are loaded. Any ideas?
Many thnaks,
Mike
Bookmarks