Created
September 6, 2016 15:17
-
-
Save ivarvong/d962cfd4bf13ae8847a3e29ff5d64f3b to your computer and use it in GitHub Desktop.
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
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