I need to size a container based on the orientation of the img that is in it. So as to have a width:50% container for portrait images and a width:100% container for landscape images.
The JQuery i was able to come up with, does not work. It just adds one of the two classes independant of the content it seems.
Javascript:
$(".galleryelement").addClass(function() {
if (".galleryelement img".height > ".galleryelement img".width) {
return "portrait";
} else {
return "landscape";
}
});
Rough HTML:
<div class="gallery">
<div class="galleryelement"><img></div>
<div class="galleryelement"><img></div>
<div class="galleryelement"><img></div>
<div class="galleryelement"><img></div>
</div>
CSS:
.portrait {
width: 50%;
}
.landscape {
width: 100%;
}
I produced a Fiddle to illustrate the problem: JSFiddle
Hope someone spots my mistakes and can help. The code uses the flickity slider.