🔔 Alert..!! Get 2 Month Free Cloud Hosting With $200 Bonus From Digital Ocean ACTIVATE DEAL

Just another jQuery responsive iframe plugin which dynamically resizes the embedded iframes (e.g. Youtube/Vimeo videos) while preserving the aspect ratio you specify.

responsive-iframe

Documentation

keep-ratio

A jQuery plugin to calculate the ration of Iframe Video embbeds and other stuff


How to use it

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.

Examples

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(); });

Important Note

You need to pass first the ratio param in the width:height order.

ToDO

  • Calculate the ratio based on element's height rather than width

You May Also Like