【问题标题】:Add static navbar bootstrap添加静态导航栏引导程序
【发布时间】:2018-02-04 13:42:32
【问题描述】:

我正在尝试学习一些前端开发,我发现了一件有趣的事情 [这里][1]。每当我向左或向右移动光标时,我想保持滑动效果,但导航栏是静态/固定的。

  [1]: https://codepen.io/bradtraversy/pen/dJzzdB

【问题讨论】:

  • 把JS中的事件监听去掉就不动了。
  • @shubham - 我想使用这些动画。
  • 你想要动画吗?事件侦听器使导航栏左右移动。你想让这些移动吗?请让您的问题更清楚。
  • 我想在向左或向右移动时保持滑动效果,但导航栏是静态的。
  • 您需要在您的问题中发布minimal reproducible example

标签: html css web


【解决方案1】:

这样的?

https://codepen.io/mikehavoc/pen/KQzgQG/

  <nav class="navbar fixed-top navbar-expand-lg navbar-light bg-light">
  <a class="navbar-brand" href="#">Navbar</a>
 <button class="navbar-toggler" type="button" data-toggle="collapse" 
data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" 
aria-label="Toggle navigation">
    <span class="navbar-toggler-icon"></span>
  </button>
  <div class="collapse navbar-collapse" id="navbarNav">
    <ul class="navbar-nav">
      <li class="nav-item active">
        <a class="nav-link" href="#">Home <span class="sr-only">(current)
</span></a>
      </li>
     <li class="nav-item">
        <a class="nav-link" href="#">Features</a>
      </li>
      <li class="nav-item">
         <a class="nav-link" href="#">Pricing</a>
       </li>
       <li class="nav-item">
         <a class="nav-link disabled" href="#">Disabled</a>
       </li>
     </ul>
   </div>
 </nav>


 <div class="container">
   <div class="split left">
      <h1>The Designer</h1>
     <a href="#" class="button">Read More</a>
    </div>
   <div class="split right">
     <h1>The Programmer</h1>
     <a href="#" class="button">Read More</a>
    </div>
  </div>

【讨论】:

    【解决方案2】:

    CSS 来制作固定的导航栏

    nav{
    position:fixed !important;
    width:100% !important
    }
    

    nav{
    position:fixed !important;
    width:100% !important
    }
    <!DOCTYPE html>
    <html lang="en">
    <head>
      <title>Bootstrap Example</title>
      <meta charset="utf-8">
      <meta name="viewport" content="width=device-width, initial-scale=1">
      <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
      <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    </head>
    <body>
    
    <nav class="navbar navbar-inverse">
      <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 class="navbar-brand" href="#">WebSiteName</a>
        </div>
        <div class="collapse navbar-collapse" id="myNavbar">
          <ul class="nav navbar-nav">
            <li class="active"><a href="#">Home</a></li>
            <li class="dropdown">
              <a class="dropdown-toggle" data-toggle="dropdown" href="#">Page 1 <span class="caret"></span></a>
              <ul class="dropdown-menu">
                <li><a href="#">Page 1-1</a></li>
                <li><a href="#">Page 1-2</a></li>
                <li><a href="#">Page 1-3</a></li>
              </ul>
            </li>
            <li><a href="#">Page 2</a></li>
            <li><a href="#">Page 3</a></li>
          </ul>
          <ul class="nav navbar-nav navbar-right">
            <li><a href="#"><span class="glyphicon glyphicon-user"></span> Sign Up</a></li>
            <li><a href="#"><span class="glyphicon glyphicon-log-in"></span> Login</a></li>
          </ul>
        </div>
      </div>
    </nav>
      
    <div class="container">
      <h3>Collapsible Navbar</h3>
      <p>In this example, the navigation bar is hidden on small screens and replaced by a button in the top right corner (try to re-size this window).
      <p>Only when the button is clicked, the navigation bar will be displayed.</p>
    </div>
    
    <div class="container" style="margin-top:50px">
      <h3>Fixed Navbar</h3>
      <div class="row">
        <div class="col-md-4">
          <p>A fixed navigation bar stays visible in a fixed position (top or bottom) independent of the page scroll.</p>
          <p>A fixed navigation bar stays visible in a fixed position (top or bottom) independent of the page scroll.</p>    
        </div>
        <div class="col-md-4"> 
          <p>A fixed navigation bar stays visible in a fixed position (top or bottom) independent of the page scroll.</p>
          <p>A fixed navigation bar stays visible in a fixed position (top or bottom) independent of the page scroll.</p>
        </div>
        <div class="col-md-4"> 
          <p>A fixed navigation bar stays visible in a fixed position (top or bottom) independent of the page scroll.</p>
          <p>A fixed navigation bar stays visible in a fixed position (top or bottom) independent of the page scroll.</p> 
        </div>
      </div>
    </div>
    
    <h1>Scroll this page to see the effect</h1>
    
    </body>
    </html>

    使用 bootstrap 可以轻松制作带有 navbar-fixed-top 类的固定导航栏 top 指定导航栏的位置

    example

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-04-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-20
      相关资源
      最近更新 更多