Last active
March 14, 2016 12:39
-
-
Save themorgantown/11070756 to your computer and use it in GitHub Desktop.
This demonstrates a flexible document placed within an iframe. The iframe will resize based on the dimensions of the <div> that it is placed within. This has the effect of closing any space above and below the 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<title></title> | |
</head> | |
<body> | |
<div>Content up here.</div> | |
<!-- If this 'container' div is set to be responsive, it will adjust the height and width of | |
the Tumult Hype document placed below --> | |
<div id="container"> | |
<!-- We're setting the height here to the default size of the document. It will adjust | |
based on the dimensions of the 'container' div --> | |
<iframe id="hypeFrame" style="border: none;" src="http://site.com/yourtumultdocument.html" | |
height="831" width="100%" frameborder="0" scrolling="no"></iframe> | |
</div> | |
<div>Another div with some text.</div> | |
<script type="text/javascript"> | |
window.onresize = function(event) { | |
// Input the Width and the Height of your original document. Just Numbers! | |
var ratioScale = 1108 / 831; | |
// get the width of the enclosing Div for the Hype element | |
var currentWidth = document.getElementById('container').offsetWidth; | |
// Use the width of the Div, and divide it by the Ratio of the W/H of the document | |
// and set this as the variable for the height of the Iframe. | |
var iFrameNewHeight = currentWidth / ratioScale; | |
// set the iframe to have the correct height. | |
document.getElementById('hypeFrame').style.height = iFrameNewHeight + "px"; | |
};</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The following weren't initially clear to me but ended up working: