-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
234 lines (208 loc) · 9.21 KB
/
app.js
File metadata and controls
234 lines (208 loc) · 9.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
document.addEventListener('DOMContentLoaded', () => {
// 1. Mobile Menu Toggle
const navToggle = document.getElementById('nav-toggle');
const navLinks = document.getElementById('nav-links');
const navbar = document.getElementById('navbar');
if (navToggle && navLinks) {
navToggle.addEventListener('click', () => {
navLinks.classList.toggle('mobile-active');
navbar.classList.toggle('mobile-active');
const icon = navToggle.querySelector('i');
if (icon) {
icon.classList.toggle('fa-bars');
icon.classList.toggle('fa-xmark');
}
});
// Close mobile menu when clicking a link
document.querySelectorAll('.nav-link').forEach(link => {
link.addEventListener('click', () => {
navLinks.classList.remove('mobile-active');
navbar.classList.remove('mobile-active');
const icon = navToggle.querySelector('i');
if (icon) {
icon.classList.add('fa-bars');
icon.classList.remove('fa-xmark');
}
});
});
}
// 2. Navbar Scroll Effect & Scroll Spy
window.addEventListener('scroll', () => {
if (window.scrollY > 50) {
navbar.classList.add('scrolled');
} else {
navbar.classList.remove('scrolled');
}
highlightNavLink();
});
const sections = document.querySelectorAll('section, header');
const navItems = document.querySelectorAll('.nav-link');
function highlightNavLink() {
let scrollPosition = window.scrollY + 100;
sections.forEach(section => {
const top = section.offsetTop;
const height = section.offsetHeight;
const id = section.getAttribute('id');
if (scrollPosition >= top && scrollPosition < top + height) {
navItems.forEach(item => {
item.classList.remove('active');
if (item.getAttribute('href') === `#${id}`) {
item.classList.add('active');
}
});
}
});
}
// 3. Scroll Reveal Animations (Intersection Observer)
const revealTargetSection = (hash) => {
if (!hash || !hash.startsWith('#') || hash === '#') return;
try {
const targetSection = document.querySelector(hash);
if (targetSection) {
targetSection.querySelectorAll('.reveal').forEach(el => {
el.classList.add('active');
});
}
} catch (e) {
console.error("Error revealing target section:", e);
}
};
const revealElements = document.querySelectorAll('.reveal');
const revealObserver = new IntersectionObserver((entries, observer) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('active');
observer.unobserve(entry.target); // Animates once
}
});
}, {
threshold: 0.05,
rootMargin: '0px 0px -20px 0px'
});
revealElements.forEach(element => {
revealObserver.observe(element);
});
// Immediately reveal elements if arriving via hash link or hash changes
revealTargetSection(window.location.hash);
window.addEventListener('hashchange', () => {
revealTargetSection(window.location.hash);
});
// Also trigger on local hash link clicks
document.querySelectorAll('a[href^="#"]').forEach(link => {
link.addEventListener('click', () => {
revealTargetSection(link.getAttribute('href'));
});
});
// 4. Statistics Counter Animation
const statNumbers = document.querySelectorAll('.stat-counter');
const animateCounters = (element) => {
const target = parseInt(element.getAttribute('data-target'), 10);
const prefix = element.getAttribute('data-prefix') || '';
const suffix = element.getAttribute('data-suffix') || '';
const duration = 1500; // 1.5 seconds
const startTime = performance.now();
const updateCounter = (now) => {
const progress = Math.min((now - startTime) / duration, 1);
const current = Math.floor(progress * target);
element.textContent = prefix + current + suffix;
if (progress < 1) {
requestAnimationFrame(updateCounter);
} else {
element.textContent = prefix + target + suffix;
}
};
requestAnimationFrame(updateCounter);
};
const manifestoSection = document.getElementById('manifesto');
if (manifestoSection) {
const statsObserver = new IntersectionObserver((entries, observer) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
statNumbers.forEach(num => animateCounters(num));
observer.unobserve(entry.target);
}
});
}, { threshold: 0.15 });
statsObserver.observe(manifestoSection);
}
// 5. Dynamic Collaboration Form Submission
const colForm = document.getElementById('collaboration-form');
if (colForm) {
colForm.addEventListener('submit', (e) => {
e.preventDefault();
const name = document.getElementById('name').value;
const email = document.getElementById('email').value;
const field = document.getElementById('field').value;
// Dynamic card replacement for a premium feedback loop
const card = colForm.closest('.contact-form-card');
if (card) {
card.style.opacity = '0';
card.style.transform = 'translateY(10px)';
setTimeout(() => {
card.innerHTML = `
<div style="text-align: center; padding: 2rem 0;">
<div style="width: 80px; height: 80px; background: rgba(var(--primary-rgb), 0.1); border: 2px solid var(--primary); border-radius: 50%; display: flex; align-items: center; justify-content: center; margin: 0 auto 2rem; color: var(--primary); font-size: 2.5rem; animation: pulse-glow 2s infinite;">
<i class="fa-solid fa-check"></i>
</div>
<h3 style="font-size: 1.8rem; margin-bottom: 1rem; color: var(--text-primary);">Đăng Ký Thành Công!</h3>
<p style="color: var(--text-secondary); margin-bottom: 1.5rem; font-size: 1rem; line-height: 1.6;">
Chào <strong>${name}</strong>, chúng tôi đã nhận được thông tin đăng ký đồng hành trong lĩnh vực <strong>${field}</strong>.
</p>
<p style="color: var(--text-muted); font-size: 0.9rem; margin-bottom: 2rem;">
Hệ thống đã lưu trữ email <strong>${email}</strong>. CEO Thiên Phong và đội ngũ quản lý CRF sẽ liên hệ trực tiếp với bạn qua email trong vòng 24-48 giờ làm việc.
</p>
<button id="btn-back-form" class="btn btn-secondary">Quay lại</button>
</div>
`;
card.style.opacity = '1';
card.style.transform = 'translateY(0)';
// Allow re-submitting if needed
const backBtn = document.getElementById('btn-back-form');
if (backBtn) {
backBtn.addEventListener('click', () => {
window.location.reload();
});
}
}, 300);
}
});
}
// 6. Course Tabs Filter Logic
const courseTabs = document.querySelectorAll('.course-tab');
const courseCards = document.querySelectorAll('.course-card');
if (courseTabs.length > 0 && courseCards.length > 0) {
courseTabs.forEach(tab => {
tab.addEventListener('click', () => {
// Toggle active state
courseTabs.forEach(t => t.classList.remove('active'));
tab.classList.add('active');
// Filter logic
const filter = tab.getAttribute('data-filter');
courseCards.forEach(card => {
const category = card.getAttribute('data-category');
if (filter === 'all' || category === filter) {
card.classList.remove('hide');
} else {
card.classList.add('hide');
}
});
});
});
}
});
// Extra style animation definition
const styleSheet = document.createElement("style");
styleSheet.textContent = `
@keyframes pulse-glow {
0% {
box-shadow: 0 0 0 0 rgba(var(--primary-rgb), 0.4);
}
70% {
box-shadow: 0 0 0 15px rgba(var(--primary-rgb), 0);
}
100% {
box-shadow: 0 0 0 0 rgba(var(--primary-rgb), 0);
}
}
`;
document.head.appendChild(styleSheet);