【发布时间】:2011-12-05 04:56:45
【问题描述】:
搜索了很多,但没有找到我正在寻找的东西。 我想根据容器的宽度动态调整 iframe 的大小。
HTML:
<div class="row hidden" id="audio">
<div class="twelvecol last">
<iframe id="deezer" scrolling="no" frameborder="0" allowTransparency="true" src="http://www.deezer.com/fr/plugins/player?autoplay=false&playlist=true&width=710&height=308&scover=true&type=album&id=42808&title=" width="710" height="308"></iframe>
</div>
</div>
感谢 jQuery,我尝试将 div#content 的宽度和高度注入 iframe 的 src 属性的参数中:
<script>
$(document).ready(function(){
var contentwidth = $('#content').width();
var contentheight = $('#content').height();
var iframeUrl = 'http://www.deezer.com/fr/plugins/player?autoplay=false&playlist=true&width=' + contentwidth + '&height=' + contentheight + '&scover=true&type=album&id=42808&title=';
$('#deezer').attr('src', iframeUrl).attr('width', contentwidth).attr('height', contentheight);
});
</script>
感谢您的帮助!
【问题讨论】:
-
你问题中的代码有什么问题?
-
此代码不会影响 iframe 的宽度。还是 710px
-
检查 contentwidth 和 contentheight 的值是否正确
-
thx amilia 这是正确的值,因为我使用它们来适应 facebook 的宽度,如框 ;-)
标签: jquery iframe parameters attributes src