本文介紹了詳解HTML5將footer置於頁面最底部的方法(CSS+JS),分享給大家,具體如下:
JavaScript:
<script type=text/javascript> $(function(){ function footerPosition(){ $(footer).removeClass(fixed-bottom); //網頁正文全文高度var contentHeight = document.body.scrollHeight, //可視視窗高度,不含瀏覽器頂部工具列winHeight = window.innerHeight; if(!(contentHeight > winHeight)){ //當網頁正文高度小於可視視窗高度時,為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%;}以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持VeVb武林網。