Advertisement
kobial8

Sticky Navbar Using sticky.js

Mar 24th, 2015
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 2.39 KB | None | 0 0
  1. Step 01: Keep jquery.sticky.js file in the js folder and call it in index.html file
  2. Step 02: Activate the above plugin in init.js/main.js as follows:
  3.  
  4. $(document).ready(function () {
  5.     $(".header").sticky({topSpacing:0});
  6. });
  7.  
  8. Step 03: Within <header class="header"> tag, after container and row tag, put bootstrap nav menu. Delete nav & immediate next div tag for proper styling. You HTML Code should look like this:
  9.  
  10. <header class="header">
  11.    <div class="container">
  12.        <div class="row">
  13.  
  14.                    <!-- Brand and toggle get grouped for better mobile display -->
  15.                    <div class="navbar-header">
  16.                      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
  17.                        <span class="sr-only">Toggle navigation</span>
  18.                        <span class="icon-bar"></span>
  19.                        <span class="icon-bar"></span>
  20.                        <span class="icon-bar"></span>
  21.                      </button>
  22.                      <a class="navbar-brand" href="#">unicorn</a>
  23.                    </div>
  24.  
  25.                    <!-- Collect the nav links, forms, and other content for toggling -->
  26.                    <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
  27.                      <ul class="nav navbar-nav navbar-right text-uppercase">
  28.                        <li><a href="#">Home</a></li>
  29.                        <li><a href="#">Portfolio</a></li>
  30.                        <li><a href="#">BLog</a></li>
  31.                        <li><a href="#">Contact</a></li>
  32.                      </ul>
  33.                    </div><!-- /.navbar-collapse -->
  34.  
  35.        </div>
  36.    </div>
  37. </header> <!-- End header -->
  38.  
  39. Step: 04: You CSS should look like this:
  40.  
  41. header.header,
  42. .sticky-wrapper {
  43.    position: absolute;
  44.     left: 0;
  45.     top: 0;
  46.     width: 100%;
  47.     z-index: 999;
  48.     text-transform: uppercase;
  49.     font-size: 16px;
  50.     font-weight: 700;
  51.     padding: 40px 0;
  52.     transition: .4s;
  53. }
  54.  
  55. .navbar-default {background: none;border: none;}
  56. .nav > li > a:hover,
  57. .nav > li > a:focus { background-color: transparent; }
  58. .is-sticky .header .nav > li.active a,
  59. .header a:hover { color: #DF451B }
  60. .is-sticky .header {
  61.     padding: 10px 0 ;
  62.     background: #212121;
  63. }
  64. .is-sticky .header a { color: #fff }
  65. .is-sticky .header a:hover { color: red }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement