bootstrap 固定底部導航自適應
阿新 • • 發佈:2019-02-19
在使用bootstrap 底部導航的時候遇到了一個問題 —— 當我的內容超過一屏的時候,底部的部分內容會被固定的導航內容遮蓋
自己寫了一個JS指令碼,解決自適應的問題
<nav class="navbar navbar-default navbar-fixed-bottom"> <div class="container-fluid margin_bottom_5 margin_top_5 clear_padding text-center"> <button class="btn btn-e4005a" type="button" style="padding: 6px 30px;">提交</button> </div> </nav> <script> $(function(){ autoNav(); }); //解決底部自動導航的問題 function autoNav(){ //獲取內容的高度 var bodyHeight = $("body").height(); //獲取底部導航的高度 var navHeight = $(".navbar").height(); //獲取顯示屏的高度 var iHeight = document.documentElement.clientHeight||document.body.clientHeight; //如果內容的高度大於(視窗的高度 - 導航的高度),z則需要新增一個div,設定其高度 if(bodyHeight > (iHeight - navHeight)){ $("body").append('<div style="height: '+navHeight+'px"></div>'); } } </script>