【发布时间】:2011-02-06 02:02:32
【问题描述】:
我有一个带有类嵌入和唯一 ID 的 div 容器。在容器 div 内,我有一个使用 iframe 或对象的嵌入式播放器代码。例如:
<div class="embed" id"id21" style="width:480px; height:390px;">
<iframe width="480" height="390" src="http://www.youtube.com/embed/Oe_3KgfcCXs" frameborder="0" allowfullscreen></iframe>
</div>
当我调整 div 容器的大小时,我希望其中的播放器也调整大小。嵌入代码具有宽度和高度的属性。我做了以下但无法让它工作。我需要通过它的 id 来引用容器,所以如果我有另一个具有不同 id 的容器,调整大小应该只对正在调整大小的容器生效,而不是对其他容器生效。
$('.embed').live({
resize: function(event, ui) {
var id = this.id;
var height = $(id).height();
var width = $(id).width();
$(id).contents().attr({'width':width,'height':height});
}
});
【问题讨论】: