Skip to content

Instantly share code, notes, and snippets.

@leikind
Created February 13, 2014 22:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leikind/8984868 to your computer and use it in GitHub Desktop.
Save leikind/8984868 to your computer and use it in GitHub Desktop.
// Resize iframe height
jQuery(function(){
var iframes = $('iframe.resize-to-max-height');
var pageY = function (elem) {
return elem.offsetParent ? (elem.offsetTop + pageY(elem.offsetParent)) : elem.offsetTop;
}
if (iframes.length){
var resizeAllIframes = function(){
var buffer = 20,
height = document.documentElement.clientHeight,
iframeHeight;
iframes.each(function(idx, iframe){
iframeHeight = height - (pageY(iframe) + buffer);
iframeHeight = (iframeHeight < 0) ? 0 : iframeHeight;
$(iframe).css({'height': iframeHeight + 'px'});
});
}
window.onresize = resizeAllIframes;
resizeAllIframes();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment