Skip to content

Instantly share code, notes, and snippets.

@makbeta
Created August 1, 2013 20:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save makbeta/6135033 to your computer and use it in GitHub Desktop.
Save makbeta/6135033 to your computer and use it in GitHub Desktop.
JS: Resize javascript to the width of the container if it's smaller than iframe
function resizeIframes($iframes) {
$iframes.each(function() {
var $iframe = $(this);
var height = $iframe.height();
var width = $iframe.width();
var parentWidth = $iframe.parent().width();
var newHeight = Math.ceil(parentWidth*(height/width));
if(parentWidth <= width) {
$iframe.attr('width', parentWidth);
$iframe.width(parentWidth);
$iframe.attr('height', newHeight);
$iframe.height(newHeight);
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment