js设置元素垂直居中

/**
     * 设置垂直居中
     */
    function fVericalAlignBody(){
        var nBodyHeight = 730;
        var nClientHeight = document.documentElement.clientHeight;
        if(nClientHeight >= nBodyHeight + 2){
            var nDis = (nClientHeight - nBodyHeight)/2;
            document.getElementById("box").style.paddingTop = (nDis-10) + 'px';
        }else{
            document.getElementById("box").style.paddingTop = '0px';
        }
    }
    window.onresize=function(){
        fVericalAlignBody();
    };

你可能感兴趣的:(开发小笔记)