Skip to content

Instantly share code, notes, and snippets.

@dnikonov
Last active May 18, 2016 09:29
Show Gist options
  • Save dnikonov/28c4d204d2f5cacb5690 to your computer and use it in GitHub Desktop.
Save dnikonov/28c4d204d2f5cacb5690 to your computer and use it in GitHub Desktop.
JS: aspect
<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