Forked from aarongustafson/responsive-iframes.css
Last active
March 21, 2017 16:02
-
-
Save michaelslevy/45936329bd2670c7edfa2a050368a7eb to your computer and use it in GitHub Desktop.
Responsive iFrames with jQuery
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
<!-- All you need is a defined width & height --> | |
<iframe frameborder="0" height="426" src="http://www.slideshare.net/slideshow/embed_code/9812085?rel=0" width="510"></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 adjustIframes() | |
{ | |
$('iframe').each(function(){ | |
var | |
$this = $(this), | |
w = $this.attr('width'), | |
h = $this.attr('height'), | |
proportion = h / w; | |
var new_w=$this.parent().width(); | |
var new_h=Math.round( new_w * proportion ); | |
$this.height(new_h); | |
$this.width(new_w); | |
}); | |
} | |
$(window).on('resize load',adjustIframes); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Removed the CSS to make the JavaScript self-contained.