Created
August 1, 2013 20:35
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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