-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
394 lines (332 loc) · 11.6 KB
/
script.js
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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
// Utility functions
const $ = (selector) => document.querySelector(selector);
const $$ = (selector) => document.querySelectorAll(selector);
// Scroll animation configuration
const observerOptions = {
root: null,
threshold: 0.1,
rootMargin: '0px'
};
// Mobile menu functionality
const initMobileMenu = () => {
const menuButton = $('.mobile-menu-button');
const mobileMenu = $('.mobile-menu');
if (menuButton && mobileMenu) {
menuButton.addEventListener('click', () => {
const isExpanded = menuButton.getAttribute('aria-expanded') === 'true';
menuButton.setAttribute('aria-expanded', !isExpanded);
mobileMenu.classList.toggle('hidden');
});
}
};
// Smooth scroll functionality
const initSmoothScroll = () => {
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
const targetId = this.getAttribute('href');
const targetElement = document.querySelector(targetId);
if (targetElement) {
targetElement.scrollIntoView({
behavior: 'smooth',
block: 'start'
});
}
});
});
};
// Intersection Observer for animations
const initScrollAnimations = () => {
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('animate-in');
observer.unobserve(entry.target);
}
});
}, observerOptions);
$$('.animate-on-scroll').forEach(el => observer.observe(el));
};
// Dark mode toggle
const initDarkMode = () => {
const darkModeToggle = $('#dark-mode-toggle');
if (darkModeToggle) {
darkModeToggle.addEventListener('click', () => {
document.documentElement.classList.toggle('dark');
const isDark = document.documentElement.classList.contains('dark');
localStorage.setItem('darkMode', isDark ? 'dark' : 'light');
});
}
// Check for saved dark mode preference
const savedTheme = localStorage.getItem('darkMode');
if (savedTheme === 'dark') {
document.documentElement.classList.add('dark');
}
};
// Initialize all functionality
const init = () => {
initMobileMenu();
initSmoothScroll();
initScrollAnimations();
initDarkMode();
};
// Run initialization when DOM is ready
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', init);
} else {
init();
}
// Smooth scrolling for navigation links
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
try {
e.preventDefault();
const target = document.querySelector(this.getAttribute('href'));
if (!target) throw new Error('Target element not found');
target.scrollIntoView({
behavior: 'smooth',
block: 'start'
});
} catch (error) {
console.error('An error occurred:', error);
}
});
});
// Performance optimization
const debounce = (func, wait) => {
let timeout;
return function executedFunction(...args) {
const later = () => {
clearTimeout(timeout);
func(...args);
};
clearTimeout(timeout);
timeout = setTimeout(later, wait);
};
};
// Error handling
const handleError = (error) => {
console.error('An error occurred:', error);
};
// Navbar scroll effect
const navbar = document.querySelector('.navbar');
let lastScroll = 0;
window.addEventListener('scroll', () => {
const currentScroll = window.pageYOffset;
if (currentScroll <= 0) {
navbar.style.boxShadow = 'var(--shadow)';
return;
}
if (currentScroll > lastScroll) {
// Scrolling down
navbar.style.transform = 'translateY(-100%)';
} else {
// Scrolling up
navbar.style.transform = 'translateY(0)';
navbar.style.boxShadow = 'var(--shadow-lg)';
}
lastScroll = currentScroll;
});
// Intersection Observer for animations
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('animate');
observer.unobserve(entry.target);
}
});
}, observerOptions);
// Observe all sections for animation
document.querySelectorAll('section').forEach(section => {
observer.observe(section);
});
// Add animation classes to elements
document.querySelectorAll('.feature-card, .audience-card, .testimonial-card, .pricing-card').forEach(card => {
card.classList.add('fade-up');
});
// Add smooth reveal animations
const fadeUpObserver = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('fade-up-show');
fadeUpObserver.unobserve(entry.target);
}
});
}, {
threshold: 0.2,
rootMargin: '50px'
});
document.querySelectorAll('.fade-up').forEach(el => {
el.style.opacity = '0';
el.style.transform = 'translateY(20px)';
fadeUpObserver.observe(el);
});
// Add hover effects to cards
document.querySelectorAll('.feature-card, .pricing-card').forEach(card => {
card.addEventListener('mousemove', (e) => {
const rect = card.getBoundingClientRect();
const x = e.clientX - rect.left;
const y = e.clientY - rect.top;
card.style.setProperty('--mouse-x', `${x}px`);
card.style.setProperty('--mouse-y', `${y}px`);
});
});
// Add parallax effect to hero section
const hero = document.querySelector('.hero');
window.addEventListener('scroll', () => {
const scrolled = window.pageYOffset;
hero.style.backgroundPositionY = scrolled * 0.5 + 'px';
});
// Enhance scroll animations
document.querySelectorAll('section').forEach(section => {
section.style.opacity = '0';
section.style.transform = 'translateY(30px)';
const sectionObserver = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.style.opacity = '1';
entry.target.style.transform = 'translateY(0)';
entry.target.style.transition = 'all 0.8s cubic-bezier(0.4, 0, 0.2, 1)';
sectionObserver.unobserve(entry.target);
}
});
}, {
threshold: 0.2
});
sectionObserver.observe(section);
});
// Add magnetic effect to CTA buttons
document.querySelectorAll('.cta-button').forEach(button => {
button.addEventListener('mousemove', (e) => {
const rect = button.getBoundingClientRect();
const x = e.clientX - rect.left;
const y = e.clientY - rect.top;
const centerX = rect.width / 2;
const centerY = rect.height / 2;
const deltaX = (x - centerX) / centerX;
const deltaY = (y - centerY) / centerY;
button.style.transform = `translate(${deltaX * 5}px, ${deltaY * 5}px)`;
});
button.addEventListener('mouseleave', () => {
button.style.transform = 'translate(0, 0)';
});
});
// Advanced Mouse Tracking
document.addEventListener('DOMContentLoaded', () => {
const cards = document.querySelectorAll('.feature-card, .pricing-card');
const handleMouseMove = (e) => {
const card = e.currentTarget;
const rect = card.getBoundingClientRect();
const x = e.clientX - rect.left;
const y = e.clientY - rect.top;
// Update CSS Variables for gradient effect
card.style.setProperty('--mouse-x', `${x}px`);
card.style.setProperty('--mouse-y', `${y}px`);
// 3D rotation effect
const centerX = rect.width / 2;
const centerY = rect.height / 2;
const rotateX = (y - centerY) / 20;
const rotateY = (centerX - x) / 20;
card.style.transform = `
perspective(1000px)
rotateX(${rotateX}deg)
rotateY(${rotateY}deg)
scale3d(1.02, 1.02, 1.02)
`;
};
const handleMouseLeave = (card) => {
card.style.transform = '';
};
cards.forEach(card => {
card.addEventListener('mousemove', handleMouseMove);
card.addEventListener('mouseleave', () => handleMouseLeave(card));
});
});
// Smooth Parallax Scrolling
const parallaxElements = document.querySelectorAll('.hero-image, .feature-icon');
const optimizedScroll = debounce(() => {
try {
parallaxElements.forEach(element => {
const speed = element.dataset.speed || 0.5;
const rect = element.getBoundingClientRect();
const scrolled = window.pageYOffset;
if (rect.top < window.innerHeight && rect.bottom > 0) {
const yPos = -(scrolled * speed);
element.style.transform = `translate3d(0, ${yPos}px, 0)`;
}
});
} catch (error) {
console.error('An error occurred:', error);
}
}, 10);
window.addEventListener('scroll', optimizedScroll);
window.addEventListener('beforeunload', () => {
window.removeEventListener('scroll', optimizedScroll);
});
// Feature detection
const supportsBackdropFilter = CSS.supports('backdrop-filter', 'blur(20px)');
if (!supportsBackdropFilter) {
document.documentElement.classList.add('no-backdrop-filter');
}
// Mobile menu improvements
const mobileMenu = document.querySelector('.nav-links');
const menuButton = document.querySelector('.menu-button');
if (menuButton && mobileMenu) {
let isMenuOpen = false;
const toggleMenu = () => {
isMenuOpen = !isMenuOpen;
mobileMenu.classList.toggle('active');
menuButton.setAttribute('aria-expanded', isMenuOpen);
if (isMenuOpen) {
document.body.style.overflow = 'hidden';
} else {
document.body.style.overflow = '';
}
};
menuButton.addEventListener('click', toggleMenu);
// Close menu on escape key
document.addEventListener('keydown', (e) => {
if (e.key === 'Escape' && isMenuOpen) {
toggleMenu();
}
});
// Close menu when clicking outside
document.addEventListener('click', (e) => {
if (isMenuOpen && !mobileMenu.contains(e.target) && !menuButton.contains(e.target)) {
toggleMenu();
}
});
}
// Intersection Observer for Advanced Animations
const observerOptionsAdvanced = {
threshold: 0.1,
rootMargin: '20px'
};
const observerAdvanced = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('animate-in');
if (entry.target.dataset.delay) {
entry.target.style.animationDelay = entry.target.dataset.delay;
}
}
});
}, observerOptionsAdvanced);
document.querySelectorAll('.feature-card, .pricing-card, .testimonial-card').forEach(element => {
observerAdvanced.observe(element);
});
// Handle loading screen
document.addEventListener('DOMContentLoaded', () => {
const loading = document.querySelector('.loading');
// Ensure all content is loaded
window.addEventListener('load', () => {
setTimeout(() => {
loading.classList.add('hidden');
document.body.style.overflow = 'visible';
}, 800);
});
});
// Initialize AOS (Animate on Scroll) if needed
document.addEventListener('DOMContentLoaded', () => {
// Add any initialization code here
});