Updated, more general version:
var tStart = 100
, tEnd = 500
, cStart = [250, 195, 56]
, cEnd = [179, 217, 112]
, cDiff = [cEnd[0] - cStart[0], cEnd[1] - cStart[1], cEnd[2] - cStart[2]];
$(document).ready(function(){
$(document).scroll(function() {
var p = ($(this).scrollTop() - tStart) / (tEnd - tStart);
p = Math.min(1, Math.max(0, p));
var cBg = [Math.round(cStart[0] + cDiff[0] * p), Math.round(cStart[1] + cDiff[1] * p), Math.round(cStart[2] + cDiff[2] * p)];
$("body").css('background-color', 'rgb(' + cBg.join(',') +')');
});
});
In action
If you want to smooth the smooth change while scrolling, try
$(document).ready(function(){
$(document).scroll(function() {
var alpha = Math.min(0.5 + 0.4 * $(this).scrollTop() / 210, 0.9);
var channel = Math.round(alpha * 255);
$("body").css('background-color', 'rgb(' + channel + ',' + channel + ',' + channel + ')');
});
});
Jsfiddle
source
share