-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
30 lines (27 loc) · 1.17 KB
/
script.js
File metadata and controls
30 lines (27 loc) · 1.17 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
window.addEventListener('scroll', () => {
// 1. Main Overall Progress Bar
const winScroll = document.body.scrollTop || document.documentElement.scrollTop;
const height = document.documentElement.scrollHeight - document.documentElement.clientHeight;
const scrolled = (winScroll / height) * 100;
document.getElementById('main-bar').style.width = scrolled + '%';
// 2. Individual Section Progress
const sections = document.querySelectorAll('.scroll-section');
sections.forEach((section, index) => {
const rect = section.getBoundingClientRect();
const sectionHeight = section.offsetHeight;
// Calculate progress within the current section
let sectionProgress = 0;
if (rect.top <= 0 && rect.bottom >= 0) {
sectionProgress = Math.abs(rect.top) / sectionHeight * 100;
} else if (rect.top > 0) {
sectionProgress = 0;
} else if (rect.bottom < 0) {
sectionProgress = 100;
}
const barId = `bar-${index + 1}`;
const bar = document.getElementById(barId);
if (bar) {
bar.style.width = sectionProgress + '%';
}
});
});