Javascript – Dynamic resize of Vimeo Video (or Youtube)

csshtmljavascriptjquery

I added to to the iframe a class with css

width:100%;
height:auto;

but does not work for the height.

Any ideas better than jquery dirty fix

$(window).resize(function(){
    var tempwidth=$(".vimeoiframe").width();
    var tempheight=tempwidth/1.25;
    $(".vimeoiframe").css("height",tempheight);
});

Since not all my videos have this aspect ratio.

Best Answer

You should take a look at this jQuery plugin, seams that was wrote for you

FitVids.js

There is an entire article about it on CSS Tricks as well

Fluid Width YouTube Videos

And his .net magazine article

Create fluid width videos