控制页面页脚置于底部

function toBottom() {
    var hh = document.documentElement.clientHeight;
    var bh = document.getElementsByTagName('body')[0].clientHeight;
    if(hh > bh) {
        var footer = document.getElementsByClassName('footer')[0];
        footer.style.marginTop = Math.floor(hh - bh -1) + 'px';
    };
}

注意此方法必须放在页面代码数据加载完成之后 否则计算的页面高度数据可能不准确

猜你喜欢

转载自blog.csdn.net/hss0123456789/article/details/88074212