-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
96 lines (79 loc) · 3.46 KB
/
script.js
File metadata and controls
96 lines (79 loc) · 3.46 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// ────────────── Mobile Menu ──────────────
const ham = document.getElementById('ham');
const mobMenu = document.getElementById('mob-menu');
const icoOpen = document.getElementById('ico-open');
const icoClose = document.getElementById('ico-close');
ham?.addEventListener('click', () => {
const hidden = mobMenu.classList.toggle('hidden');
icoOpen.classList.toggle('hidden', !hidden);
icoClose.classList.toggle('hidden', hidden);
});
function closeMenu() {
mobMenu.classList.add('hidden');
icoOpen.classList.remove('hidden');
icoClose.classList.add('hidden');
}
// ────────────── Scroll Reveal ──────────────
const observer = new IntersectionObserver((entries) => {
entries.forEach(e => {
if (e.isIntersecting) {
e.target.classList.add('visible');
observer.unobserve(e.target);
}
});
}, { threshold: 0.12 });
document.querySelectorAll('.reveal').forEach(el => observer.observe(el));
// ────────────── Skill Bars ──────────────
const skillObs = new IntersectionObserver((entries) => {
entries.forEach(e => {
if (e.isIntersecting) {
e.target.querySelectorAll('.skill-bar').forEach(b => {
b.style.width = b.dataset.w;
});
skillObs.unobserve(e.target);
}
});
}, { threshold: 0.2 });
const skillSection = document.getElementById('skill-section');
if (skillSection) skillObs.observe(skillSection);
// ────────────── Nav Shadow on Scroll ──────────────
const nav = document.getElementById('navbar');
const scrollTopBtn = document.getElementById('scroll-top');
window.addEventListener('scroll', () => {
const scrollY = window.scrollY;
if (nav) nav.style.boxShadow = scrollY > 60 ? '0 4px 24px rgba(0,0,0,0.5)' : 'none';
if (scrollTopBtn) scrollTopBtn.classList.toggle('hidden', scrollY <= 300);
});
// ────────────── Smooth Scroll for Anchor Links ──────────────
document.querySelectorAll('a[href^="#"]').forEach(link => {
link.addEventListener('click', e => {
e.preventDefault();
const target = document.querySelector(link.getAttribute('href'));
if (target) {
target.scrollIntoView({ behavior: 'smooth', block: 'start' });
if (!mobMenu.classList.contains('hidden')) closeMenu();
}
});
});
// ────────────── Scroll to Top Button ──────────────
scrollTopBtn?.addEventListener('click', () => {
window.scrollTo({ top: 0, behavior: 'smooth' });
});
// ────────────── Skill Bar Animation ──────────────
const bars = document.querySelectorAll('.skill-bar');
const animateBars = () => {
bars.forEach(bar => {
const rect = bar.getBoundingClientRect();
if (rect.top < window.innerHeight) bar.style.width = bar.dataset.w;
});
};
window.addEventListener('scroll', animateBars);
window.addEventListener('load', animateBars);
// ────────────── Contact Form Toggle ──────────────
const sayHelloBtn = document.getElementById('sayHelloBtn');
const contactForm = document.getElementById('contactForm');
sayHelloBtn?.addEventListener('click', e => {
e.preventDefault();
contactForm?.classList.toggle('hidden');
contactForm?.scrollIntoView({ behavior: 'smooth' });
});