zoukankan      html  css  js  c++  java
  • 通过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>
  • 相关阅读:
    一些图形API函数收录
    VC6.0常见编译错误及解决方法
    Google Test Primer(入门)(六) 结束部分
    转帖:C++程序内存泄露检测
    Google Test Primer(四)——简单测试
    Android Snippet
    DCAApp 和 DXPApp 类的探索
    WEB(Javascript)远程调用方案清单
    做一个treeview dropdownlist 最近会放上来
    DotLucene:37行代码全文搜索
  • 原文地址:https://www.cnblogs.com/wangqian888/p/12611930.html
Copyright © 2011-2022 走看看