Skip to content

Instantly share code, notes, and snippets.

@LouisWhit
Created April 26, 2019 14:26
Show Gist options
  • Save LouisWhit/83b712082ccba38eb5d5526a31ba81fa to your computer and use it in GitHub Desktop.
Save LouisWhit/83b712082ccba38eb5d5526a31ba81fa to your computer and use it in GitHub Desktop.
$('.fullWidthBanner img').on('bestfit',function(){
var css;
var ratio=$(this).width() / $(this).height();
var pratio=$(this).parent().width() / $(this).parent().height();
if (ratio<pratio) css={width:'auto', height:'100%'};
else css={width:'100%', height:'auto'};
$(this).css(css);
}).on('load', function(){
$(this).trigger('bestfit');
}).trigger('bestfit');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment