Skip to content

Instantly share code, notes, and snippets.

@sadmansh
Created February 25, 2019 07:12
Show Gist options
  • Save sadmansh/de57218debfa08910aa960cf9426cee7 to your computer and use it in GitHub Desktop.
Save sadmansh/de57218debfa08910aa960cf9426cee7 to your computer and use it in GitHub Desktop.
Scroll indicator using jQuery
<header>
<div id="scroll-indicator"></div>
</header>
<script>
$(window).scroll(function() {
let $scrollHeight = $(window).scrollTop();
let $docHeight = $(document).height() - $(window).height();
let $percentage = ($scrollHeight / $docHeight) * 100;
$('#scroll-indicator').css('width', $percentage + '%');
});
</script>
<style>
#progress-bar {
position: fixed;
top: 0;
left: 0;
right: 0;
width: 0;
height: 6px;
background-color: black;
}
</style>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment