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%;
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM