I have found a code here on stackoverflow to check if the picture was portrait or landscape oriented, and add css width and height formatting.
After getting it to work (hence the $LSC everywhere), I found that it immediately jumps to "else", and outputs only that result. (all images get width auto and height 100%)
My question is, what should I change in the code to make it work and really compare width and height?
var $LSC = jQuery.noConflict(); $LSC(document).ready(function(){ $LSC(".pg-cat-image").each(function(){ var real_width = $LSC(this).width(); var real_height = $LSC(this).height(); var parentwidth = $LSC(this).parent().width(); var parentheight = $LSC(this).parent().height(); var ratioParent = parentwidth / parentheight; var ratio = real_width / real_height; if (ratioParent < ratio) { $LSC(this).css({'width' : '100%', 'height' : 'auto'}); }else{ $LSC(this).css({'width' : 'auto', 'height' : '100%'}); } }); });
ratioandratioParentare what you expect them to be?