Forked from aarongustafson/responsive-iframes.css
Last active
January 4, 2016 00:29
-
-
Save grahamlicence/8542442 to your computer and use it in GitHub Desktop.
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
iframe { | |
max-width: 100%; | |
} |
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
<!-- All you need is a defined width & height --> | |
<iframe frameborder="0" height="900" width="1600" src="http://example.com/"></iframe> |
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
var iframe = { | |
adjustIframes: function() { | |
iframe.$iframe.each(function() { | |
var $this = $(this), | |
proportion = $this.data( 'proportion' ), | |
w = $this.attr('width'), | |
actual_w = $this.width(); | |
if ( ! proportion ) { | |
proportion = $this.attr('height') / w; | |
$this.data( 'proportion', proportion ); | |
} | |
if ( actual_w != w ) { | |
$this.css( 'height', Math.round( actual_w * proportion ) + 'px' ); | |
} | |
}); | |
}, | |
init: function() { | |
this.$iframe = $('iframe'); | |
if (this.$iframe.length) { | |
this.adjustIframes(); | |
$(window).on('resize load', iframe.adjustIframes); | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment