JSFiddle - React, Tailwind, and code Playground
by LyndseyB
HTML
<div id="bar"></div>
CSS
body{
height:4000px;
}
#bar{
position:fixed;
background-color:red;
width:100%;
height:10px;
}
JavaScript
var bar = $('#bar'),
$window = $(window),
docHeight = $(document).height(),
baseX = $window.height() / docHeight * 100;
bar.css('background', '-webkit-linear-gradient(left, red '+ baseX +'%, green '+ baseX +'%)');
$window.scroll(function(e) {
var x = $window.scrollTop() / docHeight * 100 + baseX;
bar.css('background', '-webkit-linear-gradient(left, red '+ x +'%, green '+ x +'%)');
});