Created
January 28, 2020 11:54
-
-
Save martinjinda/05fbd4a6aa898413fc0ed5ebe6bd47ca to your computer and use it in GitHub Desktop.
Reading progress bar
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
if ($('.post').length) { | |
let winHeight = $(window).height(), | |
docHeight = $('.post').height(), | |
postOffset = $('.post').offset().top, | |
progressBar = $('.progress-container'), | |
max, value; | |
max = docHeight - winHeight; | |
progressBar.attr('max', max); | |
$(document).on('scroll', function() { | |
value = $(window).scrollTop() - postOffset; | |
if (value >= 0) { | |
progressBar.show(); | |
let width = (value / max) * 100; | |
width = width + '%'; | |
$('.progress-bar').css({'width': width}); | |
} else { | |
progressBar.hide(); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment