Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions source/js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) + '%';
}
}
});

Expand Down