javascript - iframe css问题
怪我咯
怪我咯 2017-04-11 11:47:11
[JavaScript讨论组]
  1. 如果所示,本意是在红色主体区域放一个iframe。代码就是下面注释的iframe

     <#--
      

    <#---->

现在注释了

现在右边是没有滚动条的。
现在去掉iframe的注释,右侧滚动条出现。看最下面还有红色的背景,大概10px左右。

实在搞不懂这里为什么出现,我js算的没问题啊。
我本意是iframe里的高度如果不足外面红色主体部分,就撑满。
代码:

 function setIframeHeight(iframe) {
        if (iframe) {
            var iframeWin = iframe.contentWindow || iframe.contentDocument.parentWindow;
            if (iframeWin.document.body) {
               // iframe.height = iframeWin.document.documentElement.scrollHeight || iframeWin.document.body.scrollHeight;
                var minHeight= document.documentElement.clientHeight - 50;//50是上面头部高度
                iframe.height = Math.max(iframe.height, minHeight);
            }
        }
    };

    window.onload = function () {
        setIframeHeight(document.getElementById('content-frame'));
    };

请大神帮忙看看

怪我咯
怪我咯

走同样的路,发现不同的人生

全部回复(2)
巴扎黑

问题解决,其实只要给iframe加一个display:block;即可。

高洛峰
iframe.height = Math.max(iframe.height, minHeight);
//你试试改成
iframe.style.height = Math.max(iframe.height, minHeight)+"px";
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号