-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
33 lines (28 loc) · 1.19 KB
/
script.js
File metadata and controls
33 lines (28 loc) · 1.19 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
document.addEventListener('DOMContentLoaded', () => {
const expertiseItems = document.querySelectorAll('.expertise-item');
const expertiseDetails = document.querySelectorAll('.expertise-detail');
const observerOptions = {
root: null,
rootMargin: '-10% 0px -10% 0px',
threshold: 0.5
};
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
const id = entry.target.getAttribute('data-id');
// Remove active class from all items and details
expertiseItems.forEach(item => item.classList.remove('active'));
expertiseDetails.forEach(detail => detail.classList.remove('active'));
// Add active class to current item and corresponding detail
entry.target.classList.add('active');
const activeDetail = document.getElementById(`detail-${id}`);
if (activeDetail) {
activeDetail.classList.add('active');
}
}
});
}, observerOptions);
expertiseItems.forEach(item => {
observer.observe(item);
});
});