Created
February 25, 2019 07:12
-
-
Save sadmansh/de57218debfa08910aa960cf9426cee7 to your computer and use it in GitHub Desktop.
Scroll indicator using jQuery
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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