MCPcopy Create free account
hub / github.com/NCUSCC/cs4ncu / updateProgress

Function updateProgress

docs/javascripts/readingProgress.js:97–123  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

95
96 // 更新进度
97 function updateProgress() {
98 if (!progressElement || !progressText || !progressCircle) return;
99
100 const scrollTop = window.pageYOffset || document.documentElement.scrollTop;
101 const documentHeight = Math.max(document.body.scrollHeight, document.documentElement.scrollHeight);
102 const windowHeight = window.innerHeight;
103 const scrollableHeight = documentHeight - windowHeight;
104
105 let progress = 0;
106 if (scrollableHeight > 0) {
107 progress = Math.round((scrollTop / scrollableHeight) * 100);
108 progress = Math.max(0, Math.min(100, progress));
109 }
110
111 progressText.textContent = progress + '%';
112
113 const params = getCircleParams();
114 const offset = params.circumference - (progress / 100) * params.circumference;
115 progressCircle.style.strokeDashoffset = offset;
116
117 progressElement.classList.add('visible');
118
119 if (hideTimer) clearTimeout(hideTimer);
120 hideTimer = setTimeout(() => {
121 if (progressElement) progressElement.classList.remove('visible');
122 }, 2000);
123 }
124
125 // 节流函数
126 function throttle(func, limit) {

Callers 1

initFunction · 0.85

Calls 1

getCircleParamsFunction · 0.85

Tested by

no test coverage detected