To achieve a color animation effect, you will first need to include jQuery UI or the jQuery Color plugin as mentioned in another response.
For a simple fade-in effect as you scroll down the page, you can try the following code snippet:
$(function(){
$(window).scroll(function(){
var $scrollPercent = ($(document).scrollTop() / 100);
if($scrollPercent <= 1){
$('header').css({backgroundColor:'rgba(0,0,0,'+$scrollPercent+')'});
}
});
});
This script gradually increases the background color opacity based on your scrolling position. For example, scrolling 50 pixels down would set the background color opacity to 50%. You can easily customize the height threshold for full opacity by adjusting the calculations.
UPDATE: If you prefer a simpler approach that just fades in the color after scrolling past 100 pixels, here's an alternative solution:
Instead of using CSS transitions, you can add an additional HTML element inside your header section:
<div class="header">
<div class="headerBackground"></div>
<!-- other header content -->
</div>
Define the CSS styles for this new element:
.header {
position:relative;
}
.headerBackground {
position:absolute;
top:0;
left:0;
right:0;
bottom:0;
background-color:rgb(0,0,0);
opacity:0;
filter:alpha(opacity=0); // for IE8 and below
}
Then use the following jQuery script to animate the color change:
$(function(){
$(window).scroll(function(){
var $bg = $('.headerBackground');
if($(document).scrollTop() >= 100){
$bg.animate({opacity:1},500); // adjust speed as needed
} else {
$bg.animate({opacity:0},500);
}
});
});
This method achieves the desired effect without relying on external libraries like jQuery UI. However, keep in mind that it involves adding non-semantic HTML elements for styling purposes. It's just another option to consider.