javascript Vimeo 视频(或 Youtube)的动态调整大小

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10487478/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 10:03:57  来源:igfitidea点击:

Dynamic resize of Vimeo Video (or Youtube)

javascriptjqueryhtmlcss

提问by Daniel

I added to to the iframe a class with css

我在 iframe 中添加了一个带有 css 的类

width:100%;
height:auto;

but does not work for the height.

但不适用于高度。

Any ideas better than jquery dirty fix

任何比 jquery 脏修复更好的想法

$(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.

因为不是我所有的视频都有这个纵横比。

采纳答案by balexandre

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

你应该看看这个 jQuery 插件,为你写的接缝

FitVids.js

FitVids.js

There is an entire article about it on CSS Tricksas well

有关于它的一整篇文章CSS技巧以及

Fluid Width YouTube Videos

流体宽度 YouTube 视频

And his .net magazinearticle

和他的.net 杂志文章

Create fluid width videos

创建流体宽度视频

回答by max

Or you could use percentage ratios, http://codepen.io/maxmckenzie/pen/hFzakthe video dose not load in codepen for some reason.

或者您可以使用百分比比率,http://codepen.io/maxmckenzie/pen/hFzak 由于某种原因,视频不会在 codepen 中加载。