我正在制作一个响应式页面,其中有一个嵌入式视频内容。基于父容器大小的响应式iframe src参数
如何根据父容器的宽度更新iframe src中的参数宽度/高度以及iframe属性宽度/高度,以及在窗口/方向更改时更改?
我加价:
<div class="content">
<div class="video">
<iframe src="http://www.foo.com/embeddedPlayer?id=4062930&width=672&height=377&autoPlay=false" width="672" height="377" border="0" frameborder="0" scrolling="no"></iframe>
</div>
</div>
继承人我JS:
var articleBodyWidth = $('.content').width(),
videoUrl = $('.video'),
videoSrc = videoUrl.find('iframe').attr('src'),
iframeWidth = videoUrl.find('iframe').attr('width'),
iframeHeight = videoUrl.find('iframe').attr('height');
// function to get param in url
function getParam(name) {
name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
var regexS = "[\\?&]"+name+"=([^&#]*)";
var regex = new RegExp(regexS);
var results = regex.exec(videoSrc);
if(results == null) {
return "";
} else {
return results[1];
}
}
var newWidth = articleBodyWidth,
newHeight = Math.round((iframeHeight/iframeWidth) * articleBodyWidth);
// update iframe width and height
videoUrl.find('iframe').attr({
width: newWidth,
height: newHeight
});
更新了我的代码的问题:关于嵌入式闪存对象这里 http://tinyurl.com/a2cxfe6
更多信息。 – calebo 2013-02-26 02:53:40
@calebo找到我更新的答案,是否解决问题 – 2013-02-26 03:41:07