I'm creating a picture gallery within thumbnails by automatically setting them where I use the calculation below:
if($('.thumb img').width()<$('.thumb img').height()){//portrait
$('.thumb img').css({
maxWidth:'100%'
});
$('.thumb img').css({
marginTop:-(($('.thumb img').height()-$('.thumb').height())/2)
});
}else{//landscape
$('.thumb img').css({
maxHeight:'100%'
});
$('.thumb img').css({
marginLeft:-(($('.thumb img').width()-$('.thumb').width())/2)
});
}
If I have an image, it calculates well, but when I have images of different sizes it encounters a bug . I want to know if there is a way I can execute this function every time I find a div
with class .thumb
, so I can treat image by image and structure them within their specific div's.