"Add/remove class with jquery based on vertical scroll?"
Bootstrap 3.3.0 Snippet by xrozix

<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css"> <script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/js/bootstrap.min.js"></script> <script src="//code.jquery.com/jquery-1.11.1.min.js"></script> <!------ Include the above in your HEAD tag ----------> <div class="container"> <div class="row"> <header class="clearHeader"> </header> <div class="wrapper"> </div> </div> </div>
.clearHeader{ height: 200px; background-color: rgba(107,107,107,0.66); position: fixed; top:200; width: 100%; } .darkHeader {height: 100px;background:red;} .wrapper { height:2000px; }
$(window).scroll(function() { var scroll = $(window).scrollTop(); if (scroll >= 500) { $(".clearHeader").addClass("darkHeader"); } else { $(".clearHeader").removeClass("darkHeader"); } });

Related: See More


Questions / Comments: