Skip to content

Instantly share code, notes, and snippets.

@DrewAPicture
Forked from tammyhart/responsive-iframes.js
Created March 20, 2014 21:53
Show Gist options
  • Save DrewAPicture/9674723 to your computer and use it in GitHub Desktop.
Save DrewAPicture/9674723 to your computer and use it in GitHub Desktop.
// iframes
var $iframes = $( document.querySelectorAll( '.videos iframe' ) );
function iframeSizing() {
var $this = $( this ),
width = $this.width(),
height = $this.height(),
containerWidth = $this.parent().width(),
heightRatio = height / width,
newHeight = heightRatio * containerWidth;
$this.width( containerWidth );
$this.height( newHeight );
}
function iframesEachSizing() {
$iframes.each( iframeSizing );
}
iframesEachSizing();
$( window ).resize( iframesEachSizing );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment