Skip to content

Instantly share code, notes, and snippets.

@PaulGwamanda
Created October 6, 2017 11:05
Show Gist options
  • Select an option

  • Save PaulGwamanda/cb0245029733f97b5be06d9d0f7ec6b0 to your computer and use it in GitHub Desktop.

Select an option

Save PaulGwamanda/cb0245029733f97b5be06d9d0f7ec6b0 to your computer and use it in GitHub Desktop.
Scroll progress bar on top of page
//Scroll progress bar
$(document).ready(function() {
$(window).on('scroll', function() {
var docHeight = $(document).height(),
winHeight = $(window).height();
var viewport = docHeight - winHeight,
positionY = $(window).scrollTop();
var indicator = ( positionY / (viewport)) * 100;
$('.scroll-bar').css('width', indicator + '%');
});
});
//css
.scroll-bar {
height: 5px;
width: 10px;
background-color: #08498F;
position: fixed;
z-index: 2;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment