DivCSS實例:讓頁腳保持在未滿屏頁面的底部

  在內(nèi)容不超過一屏的情況下,當(dāng)瀏覽器窗口變小那行頁腳文字會跟著向上浮動但還是保持在底部。
  當(dāng)內(nèi)容多出一屏?xí)r,他顯示在網(wǎng)頁的最下邊,而不是窗口的最下邊;測試了一下,還可以,在IE6、IE7、FF等都沒有問題!窗口縮小時也沒有問題!

  首先是JS腳本:

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();

  查看運行效果:


    [ 可先修改部分代碼 再運行查看效果 ]
標(biāo)簽:

相關(guān)文章

隨機推薦