-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
72 lines (61 loc) · 2.18 KB
/
script.js
File metadata and controls
72 lines (61 loc) · 2.18 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
document.addEventListener('DOMContentLoaded', () => {
initCounter();
initScrollEffects();
initNavSync();
});
function initCounter() {
const counterBtn = document.getElementById('counter-btn');
const display = counterBtn.querySelector('span');
let count = 0;
counterBtn.addEventListener('click', () => {
count++;
display.textContent = count;
display.style.transform = 'scale(1.4)';
setTimeout(() => {
display.style.transform = 'scale(1)';
}, 100);
console.log(`%c [Counter] New value: ${count} `, 'background: #6366f1; color: #fff; border-radius: 4px;');
});
}
function initScrollEffects() {
const cards = document.querySelectorAll('.card, .glass:not(nav)');
const observerOptions = {
threshold: 0.1,
rootMargin: '0px 0px -50px 0px'
};
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.style.opacity = '1';
entry.target.style.transform = 'translateY(0)';
observer.unobserve(entry.target);
}
});
}, observerOptions);
cards.forEach((card, index) => {
if (card.tagName.toLowerCase() === 'nav') return;
card.style.opacity = '0';
card.style.transform = 'translateY(40px)';
card.style.transition = `all 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275) ${index * 0.1}s`;
observer.observe(card);
});
}
function initNavSync() {
const sections = document.querySelectorAll('section');
const navLinks = document.querySelectorAll('.nav-links a');
window.addEventListener('scroll', () => {
let current = '';
sections.forEach(section => {
const sectionTop = section.offsetTop;
if (pageYOffset >= sectionTop - 150) {
current = section.getAttribute('id');
}
});
navLinks.forEach(link => {
link.classList.remove('active');
if (link.getAttribute('href').includes(current) && current !== '') {
link.classList.add('active');
}
});
});
}