blob: e171f4f7d371005845856106f926aa8d2eae9f6c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
/**
* progress-bar.js
* Reading progress indicator for articles
*/
(function() {
'use strict';
const progressBar = document.getElementById('progress-bar');
if (!progressBar) return;
window.addEventListener('scroll', () => {
const windowHeight = document.documentElement.scrollHeight - window.innerHeight;
const scrolled = window.scrollY;
const progress = windowHeight > 0 ? (scrolled / windowHeight) * 100 : 0;
progressBar.style.width = progress + '%';
progressBar.setAttribute('aria-valuenow', Math.round(progress));
}, { passive: true });
})();
|