Skip to content

Instantly share code, notes, and snippets.

@cdnsteve
Created April 10, 2013 19:53
Show Gist options
  • Save cdnsteve/5357886 to your computer and use it in GitHub Desktop.
Save cdnsteve/5357886 to your computer and use it in GitHub Desktop.
(function() {
var iframes = document.getElementsByTagName('iframe');
for (var i = 0; i < iframes.length; i++) {
var iframe = iframes[i];
var players = /www.youtube.com|player.vimeo.com/;
if(iframe.src.search(players) !== -1) {
var videoRatio = (iframe.height / iframe.width) * 100;
iframe.style.position = 'absolute';
iframe.style.top = '0';
iframe.style.left = '0';
iframe.width = '100%';
iframe.height = '100%';
var div = document.createElement('div');
div.className = 'video-wrap';
div.style.width = '100%';
div.style.position = 'relative';
div.style.paddingTop = videoRatio + '%';
var parentNode = iframe.parentNode;
parentNode.insertBefore(div, iframe);
div.appendChild(iframe);
}
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment