Bootstrap affix not working

I am using Bootstrap assembler to fix my nav at the top when it was reached by scrolling down. I added affix properties to the div but it still doesn't work. I imported both bootstrap.min.css and bootstrap.min.js. Anything else I missed?

   <div id="nav-wrapper"><!--nav-wrapper-->
        <div class="container"><!--container-->
            <div class="row" id="navigation"><!--header-->
                <div class="col-md-12" data-spy="affix" data-offset-top="60" data-offset-bottom="200"><!--col-md-12-->

                     <div class="nav"><!--nav-->
                        <div class="menu-main-menu-container">
                         <ul>
                              <li></li>
                              <li></li>
                              <li></li>

                         </ul></div>                
                        </div><!--nav-->     
                   </div><!--col-md-12-->
                <div class="clearfix"></div>
            </div><!--header-->
        </div><!--container-->
    </div>

      

+3


source to share


1 answer


I found this to work:

JS:

$(function() {
    $('#nav-wrapper').height($("#nav").height());

    $('#nav').affix({
        offset: { top: $('#nav').offset().top }
    });
});

      



CSS

#nav.affix {
    position: fixed;
    top: 0;
    width: 100%
}

#nav > .navbar-inner {
    border-left: 0;
    border-right: 0;
    border-radius: 0;
    -webkit-border-radius: 0;
    -moz-border-radius: 0;
    -o-border-radius: 0;
}

      

+1


source







All Articles