您的位置:首页 > Web前端 > JavaScript

js让一行页脚保持在底部

2018-10-12 13:51 302 查看
测了一下,还可以,在IE6、IE7、FIREOFX等都没有问题! 窗口缩小时也没有问题!


<script language="JavaScript" type="text/javascript">
function test(){
 var infoHeight = document.getElementById("info").scrollHeight;
 var bottomHeight = document.getElementById("bottom").scrollHeight;
 var allHeight = document.documentElement.clientHeight;

 var bottom = document.getElementById("bottom");
 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>

www.jb51.net 脚本之家

*{ margin:0; padding:0}
#info{background:#33CCFF}
#bottom{background:#FFCC00;width:100%;}

2
2
2

2
2
2
2
2
2
2
2

2
2
2
2
2

2
2
2
2
2

2
2
2
2
2

2
20000
bottom

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: