Skip to content

Instantly share code, notes, and snippets.

@drrobotnik
Created January 20, 2014 19:06
Show Gist options
  • Save drrobotnik/8526914 to your computer and use it in GitHub Desktop.
Save drrobotnik/8526914 to your computer and use it in GitHub Desktop.
autoheight div w/ratio
function aspectRatioRespond(){
elements = jQuery('[data-ratio]');
console.log(elements);
elements.each(function(){
container = jQuery(this);
autoHeight = container.data('ratio');
ratio = autoHeight.match(/(\d+)\:(\d+)/);
ratio = ratio[1] / ratio[2];
console.log(ratio);
container.height( container.width() / ratio );
});
}
$(window).on('load resize orientationchange',aspectRatioRespond);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment