I have a very sad tomato, because it’s not resizing, poor thing. If I don’t put the “load” function then some of my thumbs won’t resize, and if I do then the other ones won’t resize.
startDiv.find('img').each(function(p) {
$(this).parent().css({ height: thumbs_size, width:thumbs_size });
$(this).css({ height: thumbs_size, width: thumbs_size }); //temporary
$(this).load(function() {
if ($(this).height() > $(this).width()) {
var w = thumbs_size;
var h = Math.ceil($(this).height() / $(this).width() * thumbs_size);
} else {
var h = thumbs_size;
var w = Math.ceil($(this).width() / $(this).height() * thumbs_size);
}
$(this).css({ height: h, width: w });
});
});
Can anyone save my tomato?
Thanks! 🙂
It’s because some may already be loaded when you call
$(this).load(. Do the following, or something like itOr you could just use it in the onload handler which guarantees that all images in the DOM are loaded (also all scripts)
You may want to give your images default widths and heights with CSS