Permalink
Cannot retrieve contributors at this time
Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign up
Fetching contributors…
| /* | |
| # Aspect Ratio Mixin for reproCSS | |
| ## version 0.0.10 | |
| Define a height for HTML elements based on the element's width and a supplied aspect ratio. | |
| ### Syntax | |
| aspectRatio(selector, ratio) | |
| - `selector` is a CSS selector | |
| - `ratio` is a ratio expressed as `width/height` or a number | |
| ### Example | |
| aspectRatio('iframe', 16/9) | |
| - https://github.com/tomhodgins/reprocss | |
| Author: Tommy Hodgins | |
| License: MIT | |
| */ | |
| function aspectRatio(selector, ratio) { | |
| var tag = document.querySelectorAll(selector) | |
| var style = '' | |
| var count = 0 | |
| for (var i=0; i < tag.length; i++) { | |
| var attr = selector.replace(/\W+/g, '') | |
| tag[i].setAttribute('data-aspect-ratio-' + attr, count) | |
| style += '\n/* ' + selector + ' { aspect-ratio: ' + ratio + '; } */\n' | |
| + '[data-aspect-ratio-' + attr + '="' + count + '"] {\n' | |
| + ' height: ' + (tag[i].offsetWidth / ratio) + 'px;\n' | |
| + '}\n' | |
| count++ | |
| } | |
| return style | |
| } |