Created
January 20, 2014 19:06
-
-
Save drrobotnik/8526914 to your computer and use it in GitHub Desktop.
autoheight div w/ratio
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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