-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
50 lines (44 loc) · 1.78 KB
/
Copy pathscript.js
File metadata and controls
50 lines (44 loc) · 1.78 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
document.addEventListener('DOMContentLoaded', function () {
const navLinks = document.querySelectorAll('.nav-link');
const sections = document.querySelectorAll('.section');
function handleScroll() {
let current = '';
const scrollPosition = window.scrollY + 120;
sections.forEach(function (section) {
const sectionTop = section.offsetTop;
const sectionHeight = section.offsetHeight;
if (scrollPosition >= sectionTop && scrollPosition < sectionTop + sectionHeight) {
current = section.getAttribute('id');
}
});
navLinks.forEach(function (link) {
link.classList.remove('active');
if (link.getAttribute('href') === '#' + current) {
link.classList.add('active');
}
});
}
window.addEventListener('scroll', handleScroll, { passive: true });
handleScroll();
const projectCards = document.querySelectorAll('.project-card');
if ('IntersectionObserver' in window) {
const observer = new IntersectionObserver(function (entries) {
entries.forEach(function (entry) {
if (entry.isIntersecting) {
entry.target.style.opacity = '1';
entry.target.style.transform = 'translateY(0)';
}
});
}, { threshold: 0.1, rootMargin: '0px 0px -40px 0px' });
projectCards.forEach(function (card) {
card.style.opacity = '0';
card.style.transform = 'translateY(16px)';
card.style.transition = 'opacity 0.6s ease, transform 0.6s ease';
observer.observe(card);
});
} else {
projectCards.forEach(function (card) {
card.style.opacity = '1';
});
}
});