Skip to content

Instantly share code, notes, and snippets.

@OscarGodson
Created January 11, 2013 20:46
Show Gist options
  • Save OscarGodson/4513837 to your computer and use it in GitHub Desktop.
Save OscarGodson/4513837 to your computer and use it in GitHub Desktop.
vimeo and youtube videos at 100% and resize on browser window resize too on tumblr blogs. patch to: http://oscargodson.com/posts/making-vimeo-videos-bigger-than-500px-on-tumblr.html
// MAKE SURE TO CHANGE "container" to the name of the ID of the container that's
// 100% width you want the video to fit in
var resizeVideos = function () {
console.log('resized')
var iframes = document.body.getElementsByTagName('iframe')
, newVimeoWidth = document.getElementById('container').offsetWidth
, newVimeoHeight = 'auto';
console.log(newVimeoWidth)
for(x in iframes){
if(iframes[x].src && iframes[x].src.indexOf('player.vimeo.com') > -1 ||
iframes[x].src && iframes[x].src.indexOf('youtube.com') > -1){
if(newVimeoHeight == 'auto'){
newVimeoHeight = ( newVimeoWidth * 9 ) / 16;
}
iframes[x].width = newVimeoWidth;
iframes[x].height = newVimeoHeight
}
}
};
window.onresize = resizeVideos;
resizeVideos();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment