I am trying to add a class .red to #box-1 on scroll down using following code at this demo.
$(window).scroll(function() {
var scroll = jQuery(window).scrollTop();
if (scroll >= 30) {
$("#box-1").addClass("red");
} else {
$("#box-1").removeClass("red");
}
});
the HTML:
<div id="box-1" class="row"></div>
<div id="box-2" class="row"></div>
<div id="box-3" class="row"></div>
and CSS:
.red{ background-color: red; }
#box-1{background-color: yellow; height:300px; width:100px;}
#box-2{background-color: green; height:300px; width:100px;}
#box-3{background-color: blue; height:300px; width:100px;}
But it is not working! What am I doing wrong?