-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
87 lines (78 loc) · 2.21 KB
/
Copy pathscript.js
File metadata and controls
87 lines (78 loc) · 2.21 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
// Mobile navigation toggle
const toggle = document.querySelector('.nav-toggle');
const navLinks = document.querySelector('.nav-links');
if (toggle) {
toggle.addEventListener('click', () => {
navLinks.classList.toggle('open');
toggle.classList.toggle('active');
});
// Close mobile nav on link click
navLinks.querySelectorAll('a').forEach(link => {
link.addEventListener('click', () => {
navLinks.classList.remove('open');
toggle.classList.remove('active');
});
});
}
// Navbar background on scroll
const nav = document.querySelector('nav');
window.addEventListener('scroll', () => {
if (window.scrollY > 20) {
nav.style.background = 'rgba(0, 0, 0, 0.95)';
} else {
nav.style.background = 'rgba(0, 0, 0, 0.8)';
}
});
// Fade-in on scroll
const observerOptions = {
threshold: 0.1,
rootMargin: '0px 0px -50px 0px'
};
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('visible');
observer.unobserve(entry.target);
}
});
}, observerOptions);
document.querySelectorAll('.fade-in').forEach(el => {
observer.observe(el);
});
// Form handlers (Contact & Join)
const handleForm = (formId) => {
const form = document.querySelector(formId);
if (form) {
form.addEventListener('submit', (e) => {
e.preventDefault();
const btn = form.querySelector('.btn');
const originalText = btn.textContent;
btn.textContent = 'Sending...';
btn.disabled = true;
fetch(form.action, {
method: 'POST',
body: new FormData(form),
headers: { 'Accept': 'application/json' }
}).then(res => {
if (res.ok) {
btn.textContent = 'Submitted';
form.reset();
} else {
btn.textContent = 'Error — Try Again';
}
setTimeout(() => {
btn.textContent = originalText;
btn.disabled = false;
}, 3000);
}).catch(() => {
btn.textContent = 'Error — Try Again';
setTimeout(() => {
btn.textContent = originalText;
btn.disabled = false;
}, 3000);
});
});
}
};
handleForm('#contact-form');
handleForm('#join-form');