在网站上工作时遇到视频输出问题。
//站点是:http://tastethemovement.org
在帖子中,我嵌入了一个宽度为 560px 的 Youtube 视频。它在帖子中看起来很棒。但是当该图像被拉到主页上时,它超出了允许的尺寸。我只希望它最大为 316 像素。
我已经尝试在我的 css 中添加一个宽度属性,一个类到我的 iframe,但无法让它工作。如果我设置一个 iframe 类并且只允许 316px 的宽度,那么帖子中的视频也会减少。
任何帮助都会很棒!
最佳答案
我在 jsFiddle 中有这段 jQuery 代码,它将 iframe 扩展到内容的最大大小。
在您添加此 HTML 代码的帖子中:
<article>
<p><iframe width="400" height="400" src="http://www.youtube.com/...."></iframe></p>
</article>
在模板中添加以下 jQuery 代码。
<script type='text/javascript'>
jQuery(document).ready(function($) {
$(function() {
var $allVideos = $("iframe[src^='http://player.vimeo.com'], iframe[src^='http://www.youtube.com'], object, embed"),
$fluidEl = $("p");
$allVideos.each(function() {
$(this)
// jQuery .data does not work on object/embed elements
.attr('data-aspectRatio', this.height / this.width)
.removeAttr('height')
.removeAttr('width');
});
$(window).resize(function() {
var newWidth = $fluidEl.width();
$allVideos.each(function() {
var $el = $(this);
$el
.width(newWidth)
.height(newWidth * $el.attr('data-aspectRatio'));
});
}).resize();
});
});
</script>
我在我的 Wordpress 网站上尝试了代码并且它有效。
关于css - Wordpress - 在主页上更改视频 (iframe) 尺寸,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15599304/