$(document).scroll(function() { var scroll_pos=$(document).scrollTop(); var docHeight=$(document).height(); var percent=(scroll_pos/docHeight); var red=Math.round(255*percent); $("body").css('background-color', 'rgba('+red+',0,0,1)'); } );
An example of how to make a document more red than the lower you scroll. You can also implement a function that maps percentages to the hex value you want to display :)
Or if you want to change depending on the percentage:
$(document).scroll(function() { var scroll_pos=$(document).scrollTop(); var docHeight=$(document).height(); var percent=Math.round((scroll_pos/docHeight)*100); if (percent>33) $("#menu").css('background-color', '#ff0000'); } );
source share