Horje Website
Bs Scrollspy Affix Stacked – Bootstrap Affix – Bootstrap Affix – Bootstrap Code

Bs Scrollspy Affix Stacked – Bootstrap Affix

Bs Scrollspy Affix Stacked - Bootstrap Affix - Bootstrap Affix - Bootstrap Code


 
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>Bootstrap Example</title>
  5. <meta charset="utf-8">
  6. <meta name="viewport" content="width=device-width, initial-scale=1">
  7. <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
  8. <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
  9. <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
  10. <style>
  11. body {
  12. position: relative;
  13. }
  14. .affix {
  15. top:0;
  16. width: 100%;
  17. z-index: 9999 !important;
  18. }
  19. .navbar {
  20. margin-bottom: 0px;
  21. }
  22. .affix ~ .container-fluid {
  23. position: relative;
  24. top: 50px;
  25. }
  26. #section1 {padding-top:50px;height:500px;color: #fff; background-color: #1E88E5;}
  27. #section2 {padding-top:50px;height:500px;color: #fff; background-color: #673ab7;}
  28. #section3 {padding-top:50px;height:500px;color: #fff; background-color: #ff9800;}
  29. #section41 {padding-top:50px;height:500px;color: #fff; background-color: #00bcd4;}
  30. #section42 {padding-top:50px;height:500px;color: #fff; background-color: #009688;}
  31. </style>
  32. </head>
  33. <body data-spy="scroll" data-target=".navbar" data-offset="50">
  34. <div class="container-fluid" style="background-color:#F44336;color:#fff;height:200px;">
  35. <h1>Scrollspy & Affix Example</h1>
  36. <h3>Fixed navbar on scroll</h3>
  37. <p>Scroll this page to see how the navbar behaves with data-spy="affix" and data-spy="scrollspy".</p>
  38. <p>The navbar is attached to the top of the page after you have scrolled a specified amount of pixels, and the links in the navbar are automatically updated based on scroll position.</p>
  39. </div>
  40. <nav class="navbar navbar-inverse" data-spy="affix" data-offset-top="197">
  41. <div class="container-fluid">
  42. <div class="navbar-header">
  43. <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
  44. <span class="icon-bar"></span>
  45. <span class="icon-bar"></span>
  46. <span class="icon-bar"></span>
  47. </button>
  48. <a class="navbar-brand" href="#">WebSiteName</a>
  49. </div>
  50. <div>
  51. <div class="collapse navbar-collapse" id="myNavbar">
  52. <ul class="nav navbar-nav">
  53. <li><a href="#section1">Section 1</a></li>
  54. <li><a href="#section2">Section 2</a></li>
  55. <li><a href="#section3">Section 3</a></li>
  56. <li class="dropdown"><a class="dropdown-toggle" data-toggle="dropdown" href="#">Section 4 <span class="caret"></span></a>
  57. <ul class="dropdown-menu">
  58. <li><a href="#section41">Section 4-1</a></li>
  59. <li><a href="#section42">Section 4-2</a></li>
  60. </ul>
  61. </li>
  62. </ul>
  63. </div>
  64. </div>
  65. </div>
  66. </nav>
  67. <div id="section1" class="container-fluid">
  68. <h1>Section 1</h1>
  69. <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>
  70. <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>
  71. </div>
  72. <div id="section2" class="container-fluid">
  73. <h1>Section 2</h1>
  74. <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>
  75. <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>
  76. </div>
  77. <div id="section3" class="container-fluid">
  78. <h1>Section 3</h1>
  79. <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>
  80. <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>
  81. </div>
  82. <div id="section41" class="container-fluid">
  83. <h1>Section 4 Submenu 1</h1>
  84. <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>
  85. <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>
  86. </div>
  87. <div id="section42" class="container-fluid">
  88. <h1>Section 4 Submenu 2</h1>
  89. <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>
  90. <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>
  91. </div>
  92. </body>
  93. </html>



Try Your Self ->



Published:
October 4, 2020
Author:
admin
Category:
Bootstrap 3, Bootstrap Source Code
Views:
14

This article was posted in Bootstrap 3, Bootstrap Source Code and tagged , , . Bookmark the permalink. Follow comments with the RSS feed for this post.Post a Comment or leave a trackback: Trackback URL.

Leave a Reply

Your email address will not be published. Required fields are marked *

 

Horje © 2011 - 2022