Skip to content

Instantly share code, notes, and snippets.

@ivarvong
Created September 6, 2016 15:17
Show Gist options
  • Save ivarvong/d962cfd4bf13ae8847a3e29ff5d64f3b to your computer and use it in GitHub Desktop.
Save ivarvong/d962cfd4bf13ae8847a3e29ff5d64f3b to your computer and use it in GitHub Desktop.
window.addEventListener('message', function(e) {
var data;
try {
data = JSON.parse(e.data);
} catch (e) {
return false;
}
if (data.context !== 'iframe.resize') {
return false;
}
var iframe = document.querySelector('iframe[src="' + data.src + '"]');
if (!iframe) {
return false;
}
var div = iframe.parentNode;
// Update the responsive div.
div.style.paddingBottom = ((data.height/iframe.offsetWidth)*100).toPrecision(4) + '%'
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment