获取窗口大小 并自适应大小变化

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

 

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();

 

 
posted @ 2017-03-13 16:51  王老五Plus  阅读(1149)  评论(0编辑  收藏  举报