Skip to content

Instantly share code, notes, and snippets.

@apertureless
Last active August 29, 2015 14:11
Show Gist options
  • Save apertureless/772e8c32b7e04d30b69f to your computer and use it in GitHub Desktop.
Save apertureless/772e8c32b7e04d30b69f to your computer and use it in GitHub Desktop.
Responsive iFrame js
jQuery(document).ready(function( $ ){
function responsiveFrame() {
$( 'iframe' ).each(function(){
var fh = $( this ).height();
var fw = $( this ).width();
var fp = $( this ).parent().width();
var fpw = fp/fw;
var fpwh = Math.round( fh*fpw );
$( this ).css({
'width': fp,
'height': fpwh,
});
});
}
responsiveFrame();
$(window).resize(function(){
responsiveFrame();
});
var watch_body = $( 'body' );
var body_height = watch_body.innerHeight();
window.setInternal(function(){
var new_height = watch_body.innerHeight();
if ( new_height != body_height ) {
body_height = new_height;
responsiveFrame();
}
}, 200);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment