div垂直居中(js)

 

 

window.onload = function(){
            var xx = document.documentElement.clientHeight;
            // 470为要垂直居中的div的高度
            he = (xx-470)/2;
            console.log(he);
            document.getElementsByClassName('weixin_public')[0].style.marginTop = he + 'px';
        
        }

 

通过以上的js控制即可达到垂直居中的效果

posted @ 2015-04-10 21:27  最是优雅少年时  阅读(1945)  评论(0编辑  收藏  举报