我花了很多年試圖使用CSS將頁腳粘到頁面底部,並且剛剛放棄。jQuery將頁腳粘貼到頁面底部
我想要的是,如果視口的高度小於HTML文檔的高度,頁腳就不會分配額外的CSS屬性。
如果原稿的高度小於窗口的高度,我想分配到DIV#thefooter以下CSS:
position: fixed;
bottom: 0px;
margin-left: -5px;
因此,這裏是我的JS代碼。它什麼都不做,控制檯日誌什麼也沒有顯示。
$(document).ready(function(){
$(window).bind("load", function(){ putFooter(); });
$(window).resize(function(){ putFooter(); });
function putFooter(){
var wh = $(window).height();
var dh = $(document).height();
if(dh < wh) {
$("#thefooter").css({"position": "fixed", "bottom": "0px", "margin-left": "-5px"});
}
}
});
編輯:這是我的HTML是什麼樣子:
<div id="allexceptfooter">
<div id="themenu">...</div>
<div id="actualcontent">...</div>
</div>
<div id="thefooter">...</div>
如果你想看到整個事情我的網站是duncannz .COM
你可以通過使用一個對象'.css({「position」:「fixed」,「bottom」:「0px」,「 margin-left「:」-5px「})' – Andreas
@安德烈亞斯感謝編輯 – stackunderflow
這只是意味着對未來的暗示:D – Andreas