Last active
May 18, 2016 09:29
-
-
Save dnikonov/28c4d204d2f5cacb5690 to your computer and use it in GitHub Desktop.
JS: aspect
This file contains 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
<div data-aspect="1.5"></div> | |
<script> | |
$(function($) { | |
var onResizeWindow = function(){ | |
$('[data-aspect]').each(function(){ | |
var aspect = $(this).data('aspect') || 1; | |
$(this).css('height', $(this).outerWidth() / aspect); | |
}); | |
}; | |
onResizeWindow(); | |
$(window).on('resize', function(){ | |
onResizeWindow(); | |
}); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment