Struggling to assign a landscape or portrait class to images in a Wordpress gallery by measuring dimensions on load. Successfully tested in Safari, but encountering issues with Firefox and Chrome. Feeling stumped, any assistance would be appreciated!
jQuery(window).on('load', function () {
jQuery(".blocks-gallery-grid img").each(function() {
var aspectRatio = jQuery(this).css('width', 'auto').width()/jQuery(this).css('height', 'auto').height();
console.log(jQuery(this).attr('src'));
console.log(jQuery(this).width());
console.log(jQuery(this).height());
jQuery(this).data("aspect-ratio", aspectRatio);
if(aspectRatio > 1) {
jQuery(this).parent().parent().parent('li').addClass( "landscape" );
} else if (aspectRatio < 1) {
jQuery(this).parent().parent().parent('li').addClass( "portrait" );
} else {
jQuery(this).parent().parent().parent('li').addClass( "landscape" );
}
});
});