【发布时间】:2014-06-21 05:46:44
【问题描述】:
我有一个 Blogger 网站:http://ildesign-blogger-demo-1.blogspot.fr
我的脚本有两个问题,这将非常有用,但我似乎不了解它的功能。我想要的是:它应该只在 .post-body 中调整 youtube 和 vimeo iframe 的大小。
问题:
在文章页面(类型项目页面)上,它调整所有视频 iframe 的大小,这些 iframe 不仅在 .post-body 中,而且在页面上,例如在页脚中。页面:http://ildesign-blogger-demo-1.blogspot.fr/2014/04/1st-article.html
在页面的存档类型列表(按日期存档)中,视频在 .post-body 中没有调整大小(但应该如此),在页脚中也没有(没关系)。页面:http://ildesign-blogger-demo-1.blogspot.fr/2014_04_01_archive.html
总结:
所以,我的脚本似乎只适用于一种类型的页面(项目),尽管我在</body> 标记之前插入了脚本,而不是在 if 条件下。
此外,它似乎影响(它是有效的)页面上的所有视频,而不仅仅是 .post-body 中的视频(我想要的)。
有人可以告诉我如何重写脚本以实现我想要的吗?
<script type='text/javascript'>
//<![CDATA[
$(document).ready(function() {
// Find all YouTube and Vimeo videos, all types can be added with iframe integration
var $allVideos = $('iframe[src^="http://player.vimeo.com"], iframe[src^="//www.youtube.com"], object, embed'), $fluidEl = $('.post-body');
// Figure out and save aspect ratio for each video
$allVideos.each(function() {
$(this)
.attr('data-aspectRatio', this.height / this.width)
.removeAttr('height')
.removeAttr('width');
});
// When the window is resized
$(window).resize(function() {
var newWidth = $fluidEl.width();
// Resize all videos according to their own aspect ratio
$allVideos.each(function() {
var $el = $(this);
$el
.width(newWidth)
.height(newWidth * $el.attr('data-aspectRatio'));
});
// Kick off one resize to fix all videos on page load
}).resize();
});
//]]>
</script>
【问题讨论】:
标签: jquery iframe responsive-design xhtml