Skip to content

Instantly share code, notes, and snippets.

@neovea
Last active August 29, 2015 14:19
Show Gist options
  • Save neovea/2bbe5a675149433797c6 to your computer and use it in GitHub Desktop.
Save neovea/2bbe5a675149433797c6 to your computer and use it in GitHub Desktop.
Responsive iframe for youtube or any embeded content
function resizeIframe() {
if ( $('iframe') ) {
var iframe = $('iframe');
iframe.each(function(){
var parent = $(this).parent();
var ratio = $(this).attr('width') / $(this).attr('height');
$(this).attr('width', parent.width());
$(this).attr('height', parent.width()/ratio);
});
}
}
// Event on document load
$(document).ready(function(){
resizeIframe();
});
// Event on resize window
$(window).resize(function(){
resizeIframe();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment