本文介紹了詳解HTML5將footer置于頁(yè)面最底部的方法(CSS+JS),分享給大家,具體如下:
JavaScript:
<script type="text/javascript"> $(function(){ function footerPosition(){ $("footer").removeClass("fixed-bottom"); //網(wǎng)頁(yè)正文全文高度 var contentHeight = document.body.scrollHeight, //可視窗口高度,不包括瀏覽器頂部工具欄 winHeight = window.innerHeight; if(!(contentHeight > winHeight)){ //當(dāng)網(wǎng)頁(yè)正文高度小于可視窗口高度時(shí),為footer添加類fixed-bottom $("footer").addClass("fixed-bottom"); } else { $("footer").removeClass("fixed-bottom"); } } footerPosition(); $(window).resize(footerPosition); });</script>
CSS:
.fixed-bottom { position: fixed; bottom: 0; width:100%;}
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持武林網(wǎng)。
新聞熱點(diǎn)
疑難解答
圖片精選