-
-
Notifications
You must be signed in to change notification settings - Fork 93
Expand file tree
/
Copy pathReadingIndicator.razor.js
More file actions
52 lines (41 loc) · 1.53 KB
/
Copy pathReadingIndicator.razor.js
File metadata and controls
52 lines (41 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
let progressTimeout;
let rafId;
function getContentHeight(className) {
const content = document.querySelector(className);
if (!content) {
return 0;
}
const contentRect = content.getBoundingClientRect();
return contentRect.height;
}
function showProgressIndicator(progressContainer) {
progressContainer.classList.add("visible");
progressContainer.style.animation = 'none';
}
function hideProgressIndicator(progressContainer) {
progressContainer.style.animation = 'fadeOut 0.5s forwards';
setTimeout(() => {
progressContainer.classList.remove('visible');
}, 500);
}
window.initCircularReadingProgress = (parentContainer, progressContainer) => {
if (window.circularProgressScrollListenerAdded) {
return;
}
const progressBar = document.getElementById('progressBar');
const onScroll = () => {
clearTimeout(progressTimeout);
const contentHeight = getContentHeight(parentContainer);
const windowHeight = document.documentElement.clientHeight;
const scrollAmount = document.documentElement.scrollTop;
const maxScrollAmount = contentHeight - windowHeight;
const progress = Math.max(0, Math.min(100, (scrollAmount / maxScrollAmount) * 100));
progressBar.style.strokeDashoffset = 100 - progress;
showProgressIndicator(progressContainer);
progressTimeout = setTimeout(() => {
hideProgressIndicator(progressContainer);
}, 2000);
rafId = null;
};
window.addEventListener('scroll', onScroll);
};