Edit This Code:
<!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="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
  <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
  <style>
  .affix {
      top: 20px;
  }

  
</style>
</head>
<body>

<div class="container-fluid" style="background-color:#2196F3;color:#fff;height:200px;">
  <h1>Bootstrap affix-top.bs.affix</h1>
  <p>Scroll this page downwards and then scroll to the top.</p>
  <p><strong>The affix-top.bs.affix event occurs when the .affix class is about to be replaced with the .affix-top class.</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="tryit.asp-filename=trybs_ref_js_affix_event_affixtop&stacked=h.html#section1">Section 1</a></li>
        <li><a href="tryit.asp-filename=trybs_ref_js_affix_event_affixtop&stacked=h.html#section2">Section 2</a></li>
        <li><a href="tryit.asp-filename=trybs_ref_js_affix_event_affixtop&stacked=h.html#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>
      <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>
      <h1>Some text to enable scrolling</h1>
      <h1>Some text to enable scrolling</h1>
    </div>
  </div>
</div>

<script>
$(document).ready(function(){
    $('.nav').affix({offset: {top: 150} });
    $('.nav').on('affix-top.bs.affix', function(){
        alert('The navigation menu is about to return to its original top position - The .affix class is about to be replaced with .affix-top');
    });
});
</script>

</body>
</html>                                                


Result:
Try it Yourself - © w3schools.com
Privacy Policy