footer定位頁面底部(代碼分享)
更新時間:2017年03月07日 17:24:25 作者:yonghuming
本文主要分享了footer定位頁面底部的實例代碼,具有很好的參考價值。下面跟著小編一起來看下吧
話不多說,請看代碼:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>footer定位</title> <style> *{ margin:0; padding: 0; } .box{ width: 100%; height:300px; background: pink; margin-bottom: 30px; } .footer{ background: red; width: 100%; height:30px; } </style> </head> <body> <div class="main"> <!--頭部開始--> <div class="box"> </div> </div> <!--底部--> <div class="footer"> </div> <script type="text/javascript" src='http://libs.baidu.com/jquery/2.0.0/jquery.js'></script> </body> </html> <script> $(document).ready(function () { var theWindow = $(window); function resized() { var windowSize=window.devicePixelRatio; if(windowSize==1){ var hg2 = $(window).height(); var main = $('.main').outerHeight(); var hg4 = $('.footer').outerHeight(); var hg=hg2-hg4 if( hg > main){ $('.footer').css({"position":'fixed','bottom':0,'left':0,"z-index":999,"width":"100%"}); }else{ $('.footer').css({"position":'static'}); } }else{ $('.footer').css({"position":'static'}); } } theWindow.resize(function () { resized(); }).trigger('resize'); }); </script>
以上就是本文的全部內容,希望本文的內容對大家的學習或者工作能帶來一定的幫助,同時也希望多多支持腳本之家!
相關文章
es6數組的flat(),flatMap()函數用法實例分析
這篇文章主要介紹了es6數組的flat(),flatMap()函數用法,結合實例形式分析了es6數組的flat(),flatMap()函數基本功能、使用方法及操作注意事項,需要的朋友可以參考下2020-04-04Javascript中的var_dump函數實現(xiàn)代碼
發(fā)現(xiàn)了一個非常好的JavaScript調試方法,目前看到的是可以打印Object/Array/Function/String四種類型,使用方法和PHP中的var_dump()一樣,只要直接dump(變量名)即可。2009-09-09有趣的script標簽用getAttribute方法來自腳本吧
有趣的script標簽用getAttribute方法來自腳本吧...2007-03-03