Last active
August 29, 2015 14:05
-
-
Save ourmaninamsterdam/b7c9194c73bdbbdba09d to your computer and use it in GitHub Desktop.
Iframe resizer (using jQuery)
This file contains hidden or 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 (root, factory) { | |
if (typeof define === 'function' && define.amd) { | |
define(['jquery'],function (jQuery) { | |
return (root.iframeResizer = factory(jQuery)); | |
}); | |
} else { | |
root.iframeResizer = factory(root.jQuery); | |
} | |
}(this, function ($) { | |
return function(messageId, minPageHeight, $animatedElements) { | |
var timer; | |
minPageHeight = minPageHeight || 250; | |
return { | |
start : function() { | |
if(!window.postMessage) return; | |
var currentHeight = 0, | |
$body = $('body'); | |
$('html').css('overflow','hidden'); | |
timer = setInterval(function() { | |
var documentHeight = Math.max($body.outerHeight(true), minPageHeight); | |
if(documentHeight !== currentHeight && !$animatedElements.filter(':animated').length) { | |
window.parent.postMessage(messageId + (documentHeight), '*'); | |
currentHeight = documentHeight; | |
} | |
}, 200); | |
}, | |
stop: function() { | |
clearInterval(timer); | |
} | |
} | |
} | |
})); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage