首页 > 其他 > 详细

不管页面内容是不是占满一屏,footer都保持在最底部

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

直接上代码:

<style>
*{ margin:0; padding:0}
#container{background:#33CCFF}
#footer{background:#FFCC00;width:100%;}
</style>
<div id="container"> 5416416410</div>
<div id="footer">bottom</div>
<script language="JavaScript" type="text/javascript">
function test(){
var infoHeight = document.getElementById("container").scrollHeight;
var bottomHeight = document.getElementById("footer").scrollHeight;
var allHeight = document.documentElement.clientHeight;

var bottom = document.getElementById("footer");
if((infoHeight + bottomHeight) < allHeight){
bottom.style.position = "absolute";
bottom.style.bottom = "0";
}else{
bottom.style.position = "";
bottom.style.bottom = "";
}

setTimeout(function(){test();},10);
}
test();
</script>

不管页面内容是不是占满一屏,footer都保持在最底部

原文:http://www.cnblogs.com/oldZhangFeng/p/7251642.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!