"addClass When Visible"
Bootstrap 3.3.0 Snippet by intransitorio

<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 ----------> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <button id="testElement" class="btn btn-default"> Hello </button> <div style="height:400px">Some content</div> <button id="testElement1" class="btn btn-default"> Hi </button>
.red{ background: red; margin-top: -150px; display: block; }
$(window).on('scroll', function() { var $elem = $('#testElement1'); var $window = $(window); var docViewTop = $window.scrollTop(); var docViewBottom = docViewTop + $window.height(); var elemTop = $elem.offset().top; var elemBottom = elemTop + $elem.height(); if (elemBottom < docViewBottom) { $('#testElement1').addClass('red'); } });

Related: See More


Questions / Comments: