zoukankan      html  css  js  c++  java
  • 获取窗口大小 并自适应大小变化

    首先获取窗口的大小  一般只需获取高度即可

    if (window.innerHeight) 
            winHeight = window.innerHeight; 
            else if ((document.body) && (document.body.clientHeight)) 
            winHeight = document.body.clientHeight; 
            // 通过深入 Document 内部对 body 进行检测,获取窗口大小 
            if (document.documentElement && document.documentElement.clientHeight && document.documentElement.clientWidth) 
            { 
            winHeight = document.documentElement.clientHeight;  
            } 

    以后就需要window.onresize= function(){} 来自动添加内容高度了
    function  countHeight(){
        if (window.innerHeight) 
            winHeight = window.innerHeight; 
            else if ((document.body) && (document.body.clientHeight)) 
            winHeight = document.body.clientHeight; 
            // 通过深入 Document 内部对 body 进行检测,获取窗口大小 
            if (document.documentElement && document.documentElement.clientHeight && document.documentElement.clientWidth) 
            { 
            winHeight = document.documentElement.clientHeight;  
            } 
            var aaa = winHeight - 80;
            $(".container").css("height",aaa);
            $(".beforeOnLoadDiv").css("height",winHeight - 100)
    }
    
    function show (){
        countHeight();
        window.onresize = function(){
            countHeight();
        }
    }
    show();
    
    
    
     
  • 相关阅读:
    面向对象
    Vue + webpack 项目实践
    配置webstorm监听less时时转换
    delegate事件代理
    JS for 循环
    JS while 循环
    JS switch 分支语句
    JS if 判断
    JS 运算符
    JS typeof() parseInt() parseFloat()
  • 原文地址:https://www.cnblogs.com/wanglaowu/p/6543695.html
Copyright © 2011-2022 走看看