zoukankan      html  css  js  c++  java
  • 根据contentDocument内容的高度调整iframe的高度

    版本一

    <script>
            $(function () {
    
                //根据contentDocument的高度调整menuFrame的高度
                var menuFrame = document.getElementById('menuFrame');
                menuFrame.addEventListener('load', function () {
                    menuFrame.height = 0;
                });
                setInterval(function () {
                    menuFrame.height = getHeight(menuFrame.contentDocument);
                }, 200);
                window.addEventListener('resize', function () {
                    menuFrame.height = 0;
                    menuFrame.height = getHeight(menuFrame.contentDocument);
                });
    
    
            });
    
            function getHeight(doc) {
                if (doc == null) {
                    //menuFrame.height = 1000;
                    return 2000;
                }
    
                var body = doc.body,
                    html = doc.documentElement;
    
                var height = parseInt($('#contentWrapper').css('min-height')) - 15;
                if (body.scrollHeight && body.offsetHeight && html.clientHeight && html.offsetHeight) {
                    height = Math.max(body.scrollHeight, body.offsetHeight, html.clientHeight, html.scrollHeight, html.offsetHeight);
                }
                return height;
            }
        </script>
    

    版本二

    <iframe id="menuFrame" name="menuFrame" frameborder="0" style=" 100%; height: 100%; position: absolute;"></iframe>
    
  • 相关阅读:
    Django系列6:Model简介,ORM,字段类型,约束
    Django系列4:数据常规操作级联数据
    Django系列5:脑图总结
    Sorted Adjacent Differences
    C
    E. Sleeping Schedule
    D. Ehab the Xorcist
    C. Game with Chips
    D. Walk on Matrixv
    Circle of Monsters
  • 原文地址:https://www.cnblogs.com/vvull/p/14768457.html
Copyright © 2011-2022 走看看