6
I’m creating a mural of images inside thumbnails adjusting them automatically, 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 feathers an image, it calculates well, but when I have images of different sizes it finds a bug. I was wondering if there’s a way for me to perform that function every time I find one div
with the class .thumb
, so I can treat image by image and structure them within their specific div’s.
There was no need to change the references to
$('.thumb')
.– bfavaretto
the $('.Thumb') will not be this as I am running the loop directly on the img type elements that have this class, and not only in the class. but it could also be done only in class. but my understanding of the question said that it was only in this specific situation, correct me if I am wrong please.
– Guerra
Wonderful, thank you! was starting to smell burning here in the room rsrs... Thanks @Guerra
– LeandroLuk
No problems Leandroluk, don’t forget to mark the correct answer as "right" to help future users with the same question.
– Guerra
Just need to see this $('.Thumb') right there because if it has more than 1 element it will return an array and you will not be able to get the width or height as you want, how will it work? will be a model element?
– Guerra
If all the
.thumb
have the same dimensions there will be no problem ($('.thumb').width()
returns the width of the first element found). I understood that it would be necessary to take the container of each specific image, so I used$(this).closest('.thumb')
in my reply.– bfavaretto
Really @bfavaretto is right, you have to see exactly what $('.Thumb') you want, to make the correct capture
– Guerra