Last active
December 19, 2015 05:09
-
-
Save 0ncorhynchus/5902088 to your computer and use it in GitHub Desktop.
Inline Frame Height Adjustment
from codepen
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
<div id="wrap"> | |
<h1>Inline Frame Height Adjustment</h1> | |
<iframe id="frame" src="/"></iframe> | |
</div> |
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
$(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); | |
}); |
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
#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