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%; }
作者:linwene
链接:https://www.jianshu.com/p/f730e275e2c1
點擊查看更多內容
為 TA 點贊
評論
評論
共同學習,寫下你的評論
評論加載中...
作者其他優質文章
正在加載中
感謝您的支持,我會繼續努力的~
掃碼打賞,你說多少就多少
贊賞金額會直接到老師賬戶
支付方式
打開微信掃一掃,即可進行掃碼打賞哦