CSS を使用してフッターをページの下部に貼り付けようとして何年も費やしてきましたが、ほとんどあきらめていました。
私が望むのは、ビューポートの高さが HTML ドキュメントの高さよりも小さい場合、フッターに追加の CSS プロパティが割り当てられないようにすることです。
ドキュメントの高さがウィンドウの高さよりも小さい場合、次の CSS を div#thefooter に割り当てます。
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 をご覧ください。