Bootstrap向下滚动标题背景

时间:2016-05-07 07:33:32

标签: html css twitter-bootstrap twitter-bootstrap-3

你好我试过寻求其他编码网站和教程的帮助,但我找不到我想要的那个。基本上我唯一需要的是,一旦我向下滚过我的旋转木马,我的导航栏将获得背景标题颜色。感谢。

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="../css/bootstrap.css">
<link rel="stylesheet" href="../css/home.css">
<title>SWA{PRO}SE</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>

</head>

<body> 
    <nav class="navbar navbar-default navbar-fixed-top" role="navigation">
    <div class="container">
      <div class="navbar-header">
        <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#collapse">
          <span class="icon-bar"></span>
          <span class="icon-bar"></span>
          <span class="icon-bar"></span>
        </button>
        <a class="navbar-brand" href="#featured"></a>
      </div>
      <div class="collapse navbar-collapse" id="collapse" style="min-width:1100px">
        <ul class="nav navbar-nav navbar-right links">
          <li><a href="#featured">ABOUT</a></li>
          <li><a href="#mission">SOFTWARE & WEB DEVELOPMENT</a></li>
          <li><a href="#services">GAME DEVELOPEMENT</a></li>
          <li><a href="#staff">ARTS & DESIGNS</a></li>
          <li><a href="#testimonials">CONTACT US</a></li>
        </ul>        
      </div>
    </div>
  </nav>

    <div id="carousel" class="carousel slide" data-ride="carousel">
        <ol class="carousel-indicators">
            <li data-target="#carousel" data-slide-to="0" class="active"></li>
            <li data-target="#carousel" data-slide-to="1"></li>
            <li data-target="#carousel" data-slide-to="2"></li>
        </ol>
        <div class="carousel-inner" align="center" role="listbox">
            <div class="item active">
                <img src="../images/background1.jpg" class="img-responsive" alt="first photo">
            </div>
            <div class="item">
                <img src="../images/background2.jpg" class="img-responsive" alt="second photo">
            </div>
            <div class="item">
                <img src="../images/background3.jpg" class="img-responsive" alt="third photo">
            </div>
            <a class="left carousel-control" href="#carousel" role="button" data-slide="prev"></a>
            <a class="right carousel-control" href="#carousel" role="button" data-slide="next"></a>
        </div>
    </div>

Homepage

1 个答案:

答案 0 :(得分:1)

你需要使用JS。但是,Bootstrap已经有一个用于执行此操作的内置组件affix

只需将data-spydata-offset-top添加到您的导航栏中,如下所示:

<nav class="navbar navbar-default navbar-fixed-top" role="navigation" data-spy="affix" data-offset-top="195">
    <!-- content here -->
</nav>

然后像这样设置导航栏的样式:

.navbar-default.affix {
    background-color: #000;
}

P.S。将195中的data-offset-top替换为横幅的高度。