• 通过JS获取屏幕高度,借助屏幕高度设置div的高度


    HTML:

    <div class="content" style="background: #e07f7f;"></div>

    JS:

    <script>
      // 获取屏幕高度
      autoDivSize();
          function  autoDivSize(){ //函数:获取尺寸
            // 获取窗口宽度
            if (window.innerWidth){
                winWidth = window.innerWidth;
                console.log(winWidth+','+"oneW");
            }
            else if ((document.body) && (document.body.clientWidth)){
                winWidth = document.body.clientWidth;
                console.log(winWidth+','+"twoW");
            }
            // 获取窗口高度
            if (window.innerHeight){
                winHeight = window.innerHeight;
                console.log(winHeight+','+"oneH");
            }
            else if ((document.body) && (document.body.clientHeight)){
                winHeight = document.body.clientHeight;
                console.log(winHeight+','+"oneH");
            }
             // 通过深入 Document 内部对 body 进行检测,获取窗口大小
            if (document.documentElement && document.documentElement.clientHeight &&       document.documentElement.clientWidth)
            {
                winHeight = document.documentElement.clientHeight;
                winWidth = document.documentElement.clientWidth;
                console.log(winHeight+','+winWidth);
            }
            //DIV高度为浏览器窗口高度 的60%
            document.getElementById("content").style.height= winHeight * 1 +"px";
            console.log(document.getElementById("content").style.height);
        }
        window.οnresize=autoDivSize; //浏览器窗口发生变化时同时变化DIV高度
    </script>
  • 相关阅读:
    HTTP协议
    Python学习--装饰器、列表生成式、生成器、map filter、json处理
    Python学习--多线程&多进程
    Python学习--发送邮件
    Python学习--异常处理
    【第五节】【Python学习】【configparser模块】
    【第一节】【shell脚本】【文件里的内容与变量中的内容大小写替换】
    【Python】【多线程多进程】
    【Selenium学习】【拖动滚动条】
    【Python】【异常的获取与处理】
  • 原文地址:https://www.cnblogs.com/wangqian888/p/12611930.html
Copyright © 2020-2023  润新知