I'd like to dynamically change text color (as a linear gradient) based on page scroll position from top.
window.onscroll=function(){getPosition()}
function getPosition()
{
var scrollPos = $(window).scrollTop();
loggy(""+scrollPos,3);
}
the code above gives me the position from the top of the page. What I would like to do is to have a function that gives me back a color, and such color is based on a linear gradient that depends on the scrollPos value.
the linear gradient should start from rgb(201,69,109)
to rgb(18,23,28)
, and it has to "span" it from scrollPos=0
to scrollPos=1400
Is there a way to do this ?
function(scrollPos){
var color = f_color(scrollPos);
return color;
}
EDIT : here How to get color value from gradient by percentage with javascript? I found this example that changes color from red to green. But I haven't succeeded in setting custom colors as mine
$('#elm').css({color: 'rgb(' + ((100 - percent) *2.56) +',' + (percent *2.56) +',0)'})
(100*scrollPos)/1400
with this as the percentage