Skip to content

Instantly share code, notes, and snippets.

@mcky
Created December 11, 2013 03:53
Show Gist options
  • Save mcky/7904851 to your computer and use it in GitHub Desktop.
Save mcky/7904851 to your computer and use it in GitHub Desktop.
Scroll progress
<div class="bar"></div>​
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 +'%)');
});
body{
height:4000px;
}
.bar{
position:fixed;
background-color:red;
width:100%;
height:10px;
}​
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment