我有Blogger網站:http://ildesign-blogger-demo-1.blogspot.fr如何更改jQuery腳本爲響應IFRAME
我有兩個問題,一個腳本這將是非常有用的,但我似乎我不明白它的功能。我想要的是:它應該只在.post-body中調整youtube和vimeo iframe的大小。
的問題:
在文章頁面(項目類型頁)它會調整所有的視頻I幀這不僅在.POST體,但網頁上,例如在頁腳。頁:http://ildesign-blogger-demo-1.blogspot.fr/2014/04/1st-article.html
在存檔類型的網頁列表(按日期存檔),視頻不會在.POST體大小(但應該是),在頁腳沒有(這是確定)。頁:http://ildesign-blogger-demo-1.blogspot.fr/2014_04_01_archive.html
摘要: 所以,似乎我只是</body>
標籤之前插入腳本我的腳本只適用於一種類型的頁面(項目)的,儘管事實上並沒有如果條件。 此外,它似乎影響(這是valide)頁面上的所有視頻,而不是僅在.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>