Created
September 5, 2018 17:59
-
-
Save zrubinrattet/e9b79ba1239f0a2323b52ddae733dfb4 to your computer and use it in GitHub Desktop.
Insect Post Content with Javascript
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
<script> | |
// self-executing function to protect $ and set it to jQuery | |
(function($, document, window){ | |
// fire when document ready | |
$(document).ready(function(){ | |
// handles the iframes | |
var IframeHandler = { | |
// the iframes | |
iframes : $('.post-content iframe'), | |
// the entry point | |
_init : function(){ | |
// listen for load and resize events on the window object | |
$(window).on('resize load', IframeHandler._resizeLoadHandler); | |
}, | |
// sets the height of the iframes based on the width and their css | |
_resizeLoadHandler : function(e){ | |
// set the iframes to hide their overflow on load | |
if( e.type == 'load' ){ | |
IframeHandler.iframes.each(function(index, el){ | |
$(el).css('overflow', 'hidden'); | |
}); | |
} | |
// on load and resize then resize the iframes height | |
IframeHandler.iframes.each(function(index, el){ | |
// get the width | |
var width = $(el).width(); | |
// set the height | |
$(el).css('height', width / (16/9)); | |
}); | |
} | |
} | |
// call the entry point | |
IframeHandler._init(); | |
}); | |
})(jQuery, document, window); | |
</script> | |
<iframe src="https://lab.sfmoma.org/insectropolis/millipede.html" width="100%" style="height:-webkit-fill-available;" frameborder="0" scrolling="no"></iframe> | |
<iframe src="https://lab.sfmoma.org/insectropolis/bee.html" width="100%" style="height:-webkit-fill-available;" scrolling="no"></iframe> | |
<iframe src="https://lab.sfmoma.org/insectropolis/ant.html" width="100%" style="height:-webkit-fill-available;" scrolling="no"><span data-mce-type="bookmark" style="display: inline-block; width: 0px; overflow: hidden; line-height: 0;" class="mce_SELRES_start"></span></iframe> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment