A jQuery plugin to calculate the ration of Iframe Video embbeds and other stuff
Just call it on the element you wanna keep the ratio. The default ratio is 16/9, and you can pass any ratio-string you like through the parameters.
Call it on Document Ready
<iframe width="100%" class="keepItRatio" height="315" src="https://www.youtube.com/embed/YOUTUBEID" frameborder="0" allowfullscreen></iframe>
$(document).ready(function() {
$(".keepItRatio").keepRatio("4:3");
});
Call it on Window Resize (Too keep the ratio during resizes)
$(window).resize(function() {
$(".keepItRatio").keepRatio();
});
You need to pass first the ratio param in the width:height order.
- Calculate the ratio based on element's height rather than width