diff --git a/source/js/utils.js b/source/js/utils.js index 9b363069eb..4305f5e32d 100644 --- a/source/js/utils.js +++ b/source/js/utils.js @@ -135,20 +135,18 @@ NexT.utils = { var readingProgressBar = document.querySelector('.reading-progress-bar'); // For init back to top in sidebar if page was scrolled after page refresh. window.addEventListener('scroll', () => { - var scrollPercent; if (backToTop || readingProgressBar) { var docHeight = document.querySelector('.container').offsetHeight; var winHeight = window.innerHeight; var contentVisibilityHeight = docHeight > winHeight ? docHeight - winHeight : document.body.scrollHeight - winHeight; - var scrollPercentRounded = Math.round(100 * window.scrollY / contentVisibilityHeight); - scrollPercent = Math.min(scrollPercentRounded, 100) + '%'; - } - if (backToTop) { - backToTop.classList.toggle('back-to-top-on', window.scrollY > THRESHOLD); - backToTop.querySelector('span').innerText = scrollPercent; - } - if (readingProgressBar) { - readingProgressBar.style.width = scrollPercent; + var scrollPercent = Math.min(100 * window.scrollY / contentVisibilityHeight, 100); + if (backToTop) { + backToTop.classList.toggle('back-to-top-on', window.scrollY > THRESHOLD); + backToTop.querySelector('span').innerText = Math.round(scrollPercent) + '%'; + } + if (readingProgressBar) { + readingProgressBar.style.width = scrollPercent.toFixed(2) + '%'; + } } });