Skip to content

Instantly share code, notes, and snippets.

@0ncorhynchus
Last active December 19, 2015 05:09
Show Gist options
  • Save 0ncorhynchus/5902088 to your computer and use it in GitHub Desktop.
Save 0ncorhynchus/5902088 to your computer and use it in GitHub Desktop.
Inline Frame Height Adjustment from codepen
<div id="wrap">
<h1>Inline Frame Height Adjustment</h1>
<iframe id="frame" src="/"></iframe>
</div>
$(function() {
function adjustHeight() {
var body =
$("#frame").contents().find("body").children();
var height = 0;
for (var i = 0; i < body.size(); i++) {
var c = body.eq(i);
var h = c.offset().top+c.outerHeight(true);
if (height < h) {
height = h;
}
}
$("#frame").delay(500).height(height);
}
$("#frame").load(function() {
adjustHeight();
});
setInterval(function(){adjustHeight();},500);
});
#wrap {
width: 900px;
margin: auto;
}
#frame {
width: 100%;
margin-bottom: 50px;
border: 1px solid #ff0000;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment