Created
December 4, 2016 00:36
-
-
Save Phocacius/c28c828d4171f6d030cedc62b9a4485b to your computer and use it in GitHub Desktop.
automatically adapts the width of an iframe to the available width, needs ratio set via width/height attributes and width set to 100% via CSS
This file contains 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
/* Responsive iFrames | |
- - - - - - - - - - - - - - - - - - - - */ | |
var $iframes = $('.iframe-responsive'); | |
if($iframes.length) { | |
var adaptIframes = function() { | |
$iframes.each(function(index, item) { | |
var $iframe = $(item); | |
var ratio = $iframes.attr('width') / $iframes.width(); | |
$iframe.css('height', $iframes.attr('height') / ratio); | |
}); | |
}; | |
adaptIframes(); | |
$(window).on('resize', adaptIframes); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment