码迷,mamicode.com
首页 > Web开发 > 详细

footer高度任意+js实现footer在底部

时间:2017-12-13 14:28:07      阅读:432      评论:0      收藏:0      [点我收藏+]

标签:rem   实现   动态   erp   height   add   bottom   post   res   

<body> <header>header</header>
    <main>main content</main>
    <footer>footer</footer>
</body>

/* 动态为footer添加类fixed-bottom */
.fixed-bottom {position: fixed;bottom: 0;width:100%;}

 

$(function(){
    function footerPosition(){
        $("footer").removeClass("fixed-bottom");
        var contentHeight = document.body.scrollHeight,//网页正文全文高度
            winHeight = window.innerHeight;//可视窗口高度,不包括浏览器顶部工具栏
        if(!(contentHeight > winHeight)){
            //当网页正文高度小于可视窗口高度时,为footer添加类fixed-bottom
            $("footer").addClass("fixed-bottom");
        } else {
            $("footer").removeClass("fixed-bottom");
        }
    }
    footerPosition();
    $(window).resize(footerPosition);
});

 

footer高度任意+js实现footer在底部

标签:rem   实现   动态   erp   height   add   bottom   post   res   

原文地址:http://www.cnblogs.com/libo199374/p/8032023.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!