Skip to content

Instantly share code, notes, and snippets.

@02Tea
Created July 25, 2017 13:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 02Tea/f2718ae315bfd269a0211524dd52693f to your computer and use it in GitHub Desktop.
Save 02Tea/f2718ae315bfd269a0211524dd52693f to your computer and use it in GitHub Desktop.
[Dynamic image sizes] #js #jquery
$(document).ready(function(){
$('.events__deck > img').each(function(){
$(this).on('load', function(){
var w = $(this).prop("naturalWidth");
var h = $(this).prop("naturalHeight");
var ex = 0.10;
// expand images
w += w * ex;
h += h * ex;
$(this).css({"max-width":w + "px", "height":h + "px"});
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment