css - Wordpress - 在主页上更改视频 (iframe) 尺寸

标签 css wordpress iframe youtube

在网站上工作时遇到视频输出问题。

//站点是: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/

相关文章:

asp.net - 在图像标签中使用 css sprites

javascript - ff/ie 中的 CSS 六边形渲染问题

CSS 'background-attribute: fixed' 但对于图像

css - 如何更改溢出Y滚动条样式

javascript - 从 Iframe 加载父窗口中的页面

css - 如何确定通过CSS实现Photoshop效果的通用方法?

php - Magento 季节性主题时间表?

Python mysql 包未运行 REPLACE 语句

javascript - IFrame 内容交换错误?

javascript - 如何在 PhantomJS 中使用 iframe 获取完整解释的 html 源代码