I'm currently utilizing Bootstrap and am looking to insert some images into my div while ensuring they are all the same size (standardized).
If the images are too large (as they typically are), I want to resize them to fit within my div and crop them if needed.
Here is what I have attempted so far:
I have tried adjusting the image style using jQuery within a function:
• If the height exceeds the width, I modify the style to max-width:100% and auto for height.
• Conversely, if the width is greater than the height.
However, since I am new to jQuery, I suspect I may be making a mistake; can someone provide guidance?
Below is my jQuery code:
$(document).ready(function(){
photoResize();
$(window).resize(function(){
photoResize();
});
});
function photoResize(){
image_w = $('img').width();
image_h = $('img').height();
if(image_h > image_w)
{
$('img').css("max-width","100%");
$('img').height("auto");
}
else if(image_w > image_h)
{
$('img').css("max-height","100%");
$('img').width("auto");
}
}
For a better visual, you can view the Fiddle here: https://jsfiddle.net/Baldrani/DTcHh/9801/