<nav class="navbar navbar-default navbar-fixed-top navbar-inverse"role="navigation"id="title">
<script type="text/javascript">
window.onscroll = function(){
var t = document.documentElement.scrollTop || document.body.scrollTop;
var title = document.getElementById("title");
if( t >=300 ) {
title.style.background-color=rgba(0,0,0,1);
}
else {
title.style.background-color=rgba(0,0,0,0);
}
}
<script type="text/javascript"> $(function(){ $(window).scroll(function(){ //var winH=$(this).height(); var scrH=$(this).scrollTop(); if (scrH>=300) { $('nav').css("opacity",".1"); }else{ $('nav').css("opacity","1"); } }); }); </script>
对照着看一下,jq很方便的,但是不建议这样去改,最好去自定义你的bootstrap框架。简单的多