I would like the background-color of my header to change to background-color of the div it scrolls past. So, when scrolled to the div #about (green), the background-color of my header will also change to green. I have this so far, but it's not working. Any help is greatly appreciated.
var t = $('#about').offset().top - 100;
$(document).scroll(function(){
if($(this).scrollTop() > t)
{
$('header').css({"background-color":"green"});
}
});
Check out my fiddle.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…