bootstrap 固定底部导航自适应

时间:2023-03-09 18:33:34
bootstrap 固定底部导航自适应

在使用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>