Skip to content

Instantly share code, notes, and snippets.

@zrubinrattet
Created September 5, 2018 17:59
Show Gist options
  • Save zrubinrattet/e9b79ba1239f0a2323b52ddae733dfb4 to your computer and use it in GitHub Desktop.
Save zrubinrattet/e9b79ba1239f0a2323b52ddae733dfb4 to your computer and use it in GitHub Desktop.
Insect Post Content with Javascript
<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