Skip to content

Instantly share code, notes, and snippets.

@dominicvogl
Last active December 15, 2015 16:39
Show Gist options
  • Save dominicvogl/5290509 to your computer and use it in GitHub Desktop.
Save dominicvogl/5290509 to your computer and use it in GitHub Desktop.
<div class="postbox">
<img src="http://placehold.it/500x400/" width="500" height="400" alt="Placehold.it" />
</div> <!-- /.postbox -->
function responsivePostImg() {
var h = $(window).height()-110;
var ih = $('.postbox img').attr('height');
var iw = $('.postbox img').attr('width');
var ratio = iw/ih;
//console.log(ratio);
$('.postbox').css({maxWidth:h*ratio});
}
$(document).ready(function(){
responsivePostImg();
});
$(window).resize(function(){
responsivePostImg();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment