"Fix a header on scroll "
Bootstrap 4.0.0 Snippet by akshayptdr4

<link href="//maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css"> <script src="//maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script> <script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <!------ Include the above in your HEAD tag ----------> <div class="container"> <div class="row"> <section> <div class="sticky">This div will stick to the top</div> </section> </div> </div>
body { margin: 0; } section { height: 2000px; padding-top: 100px; } .sticky { background: orange; } .fixed { position: fixed; top:0; left:0; width: 100%; }
$(window).scroll(function(){ var sticky = $('.sticky'), scroll = $(window).scrollTop(); if (scroll >= 100) sticky.addClass('fixed'); else sticky.removeClass('fixed'); });

Related: See More


Questions / Comments: