For example, Is there a way this could work?
function resizer() {
$(".rezimg").each(sizing($(".rezimg")))
}
function sizing(im) {
im.css({"width": "auto", "height": "auto"});
var imight = im.height();
var imidth = im.width();
var idth = im.parent().width();
var ight = im.parent().height();
var aspecti = (imight/imidth);
var aspectc = (ight/idth);
if (aspectc>aspecti){
im.css({"width": idth+"px", "height": "auto"})
}
else if(aspectc<aspecti){
im.css({"height": ight+"px", "width": "auto"});
}
else if(aspectc==aspecti){
im.css({"width": idth+"px", "height": ight+"px"});
}
}
I hope my intention is clear here. sizing() is a function that compares the height of an image to a container and fits it accordingly. I want to use it at different points throughout my code. thanks.
Yes it can, but it needs some changes. The following should work: