实例 Bootstrap Affix实例

x
 
<!DOCTYPE html>
<html>
<head>
  <title>Bootstrap实例</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://apps.bdimg.com/libs/bootstrap/3.3.0/css/bootstrap.min.css">
  <script src="https://libs.baidu.com/jquery/2.1.4/jquery.min.js"></script>
  <script src="https://apps.bdimg.com/libs/bootstrap/3.3.0/js/bootstrap.min.js"></script>
  <style>
  /* Note: Try to remove the following lines to see the effect of CSS positioning */
  .affix {
    top: 20px;
  }
  </style>
</head>
<body>
<div class="container-fluid" style="background-color:#2196F3;color:#fff;height:200px;">
  <h1>Bootstrap Affix实例</h1>
  <h3>Fixed (sticky) vertical sidenav on scroll</h3>
  <p>Scroll this page to see how the left navigation menu behaves with data-spy="affix".</p>
  <p><strong>The left menu sticks to the page when you have scrolled a specified amount of pixels.</strong></p>
</div>
<br>
<div class="container">
  <div class="row">
    <nav class="col-sm-3">
      <ul class="nav nav-pills nav-stacked">
        <li class="active"><a href="#section1">Section 1</a></li>
        <li><a href="#section2">Section 2</a></li>
        <li><a href="#section3">Section 3</a></li>
      </ul>
    </nav>
    <div class="col-sm-9">   
      <h1>Some text to enable scrolling</h1>
      <h1>Some text to enable scrolling</h1>
      <h1>Some text to enable scrolling</h1>
      <h1>Some text to enable scrolling</h1>
      <h1>Some text to enable scrolling</h1>
      <h1>Some text to enable scrolling</h1>

输出结果