bootstrap Navbar不使用bootstrap 4.0.0-alpha.2

时间:2016-08-19 13:58:16

标签: javascript html css twitter-bootstrap twitter-bootstrap-4

bootstrap Navbar不使用bootstrap 4.0.0-alpha.2并且还滚动spy。我试图用bootstrap 3.3.7替换脚本和css文件哪个工作正常但是这个版本的导航栏样式和间谍滚动不工作

<!DOCTYPE html>
<html lang="en">
  <head>

    <meta charset="utf-8">

    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <meta http-equiv="x-ua-compatible" content="ie=edge"> 
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.2/css/bootstrap.min.css" integrity="sha384-y3tfxAZXuh4HwSYylfB+J125MxIs6mR5FOHamPBG064zB+AFeWH94NdvaCBm8qnd" crossorigin="anonymous">

    <style type="text/css">

      body{

        position:relative;

      }

      #home{

        margin-top:50px;

      }

      #home {padding-top:50px;height:500px;color: #fff; background-color: green;}
      #one {padding-top:50px;height:500px;color: #fff; background-color: #1E88E5;}
      #two {padding-top:50px;height:500px;color: #fff; background-color: #673ab7;}
      #three {padding-top:50px;height:500px;color: #fff; background-color: #ff9800;}
      #two1 {padding-top:50px;height:500px;color: #fff; background-color: #00bcd4;}
      #two2 {padding-top:50px;height:500px;color: #fff; background-color: #009688;}

    </style>



  </head>
  <body data-scroll="spy" data-target="#myNavbar" data-offset="10">

    <nav  class="navbar navbar-inverse navbar-fixed-top" id="myNavbar">

      <div class="container-fluid">

        <div class="navbar-header">

          <button type="button" class="navbar-toggle"	data-toggle="collapse" data-target="#myNavbar">

            <span class="icon-bar"></span>

            <span class="icon-bar"></span>

            <span class="icon-bar"></span>

          </button>


          <a href="#" class="navbar-brand">WebSiteName</a>

        </div>

        <div class="collapse navbar-collapse" id="myNavbar">	

          <ul class=" nav navbar-nav" >

            <li class="active"><a href="#home">Home</a></li>

            <li><a href="#one">Section 1</a></li>

            <li class="dropdown"><a  class="dropdown-toggle" data-toggle="dropdown" href="#">Section 2<span class="caret"></span></a>

              <ul class="dropdown-menu" >

                <li><a href="two1">Section 2-1</a></li>

                <li><a href="two2">Section 2-2</a></li>

                <li><a href="two3">Section 2-3</a></li>

              </ul>

            </li>

            <li><a href="#three">Section 3</a></li>

          </ul>
        </div>
      </div>

    </nav>




    <div id="home" class="container-fluid">

      <h1>Home</h1>

      <p>Try to scroll this section and look at the navigation bar while scrolling! Try to scroll this section and look at the navigation bar while scrolling!</p>
      <p>Try to scroll this section and look at the navigation bar while scrolling! Try to scroll this section and look at the navigation bar while scrolling!</p>

    </div>


    <div id="one" class="container-fluid">

      <h1>One</h1>

      <p>Try to scroll this section and look at the navigation bar while scrolling! Try to scroll this section and look at the navigation bar while scrolling!</p>
      <p>Try to scroll this section and look at the navigation bar while scrolling! Try to scroll this section and look at the navigation bar while scrolling!</p>

    </div>                                                             



    <div id="two" class="container-fluid">

      <h1>two</h1>

      <p>Try to scroll this section and look at the navigation bar while scrolling! Try to scroll this section and look at the navigation bar while scrolling!</p>
      <p>Try to scroll this section and look at the navigation bar while scrolling! Try to scroll this section and look at the navigation bar while scrolling!</p>


    </div>



    <div id="three" class="container-fluid">

      <h1>Three</h1>

      <p>Try to scroll this section and look at the navigation bar while scrolling! Try to scroll this section and look at the navigation bar while scrolling!</p>
      <p>Try to scroll this section and look at the navigation bar while scrolling! Try to scroll this section and look at the navigation bar while scrolling!</p>


    </div>

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>

    <script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.3.4/js/tether.min.js" ></script>

    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.2/js/bootstrap.min.js" integrity="sha384-vZ2WRJMwsjRMW/8U7i6PWi6AlO1L79snBrmgiDpgIWJ82z8eA5lenwvxbMV1PAh7" crossorigin="anonymous"></script>	

    <script type="text/javascript">

      $("body").scrollspy({target:"#myNavbar"});

    </script>

  </body>
</html>

1 个答案:

答案 0 :(得分:2)

更新HTML accordingly for the new Bootstrap 4 navbar ..

http://codeply.com/go/yPEQsECngS

我通过此Bootstrap 4 upgrade tool运行了您的3.x代码,并且scrollspy按预期工作。另外请记住,Bootstrap 4目前在ALPHA中,因此它会改变。