Jquery - 如何动态调整iframe的高度? [英] Jquery - How do I dynamically adjust height of iframe?

查看:496
本文介绍了Jquery - 如何动态调整iframe的高度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用此代码将iframe的高度调整为浏览器窗口的高度。我看到 dochit 填充正确的值,但它不是传递给iframe。当我使用< div> 标签代替iframe时,它会调整大小。

I'm trying this code to adjust the height of an iframe to that of the browser window. I see dochit filling with the proper value, but it is not passing it to the iframe. When I use a <div> tag in place of the iframe, it resizes fine.

$(window).resize(function()  {
    var dochit = $(document).height();
    $("#pmividcon").css("height", dochit);
});


推荐答案

可以设置一个包装,成为100%,请检查 jsfiddle

You can set up a wrapper and then make the frame be 100% of it , check the jsfiddle

#wrapper {
    width:400px;
    height:400px;
}
#myFrame {
    height:100%;
    width:100%;
}

<div id="wrapper">
    <iframe src="http://www.jquery.com" id="myFrame" />
</div>

    var dochit = $(document).height();
$("#wrapper1 ").css({
     "height": dochit + "px
 });

这篇关于Jquery - 如何动态调整iframe的高度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆