-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
517 lines (426 loc) · 16 KB
/
script.js
File metadata and controls
517 lines (426 loc) · 16 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
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
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
// Smooth scrolling for navigation links
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
const target = document.querySelector(this.getAttribute('href'));
if (target) {
target.scrollIntoView({
behavior: 'smooth',
block: 'start'
});
}
});
});
// Header scroll effect
const header = document.querySelector('.header');
let lastScroll = 0;
window.addEventListener('scroll', () => {
const currentScroll = window.pageYOffset;
if (currentScroll <= 0) {
header.style.boxShadow = 'none';
} else {
header.style.boxShadow = '0 2px 10px rgba(0, 0, 0, 0.1)';
}
lastScroll = currentScroll;
});
// Intersection Observer for fade-in animations
const observerOptions = {
root: null,
rootMargin: '0px',
threshold: 0.1
};
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.style.opacity = '1';
entry.target.style.transform = 'translateY(0)';
}
});
}, observerOptions);
// Observe all feature cards
document.querySelectorAll('.feature-card').forEach(card => {
card.style.opacity = '0';
card.style.transform = 'translateY(20px)';
card.style.transition = 'all 0.6s ease-out';
observer.observe(card);
});
// Detect touch device
const isTouch = 'ontouchstart' in window || navigator.maxTouchPoints > 0;
// Feature Pseudo Videos
document.querySelectorAll('.feature-box').forEach(feature => {
const pseudoVideo = feature.querySelector('.pseudo-video');
const playPauseBtn = feature.querySelector('.play-pause');
const playIcon = playPauseBtn.querySelector('.play-icon');
const pauseIcon = playPauseBtn.querySelector('.pause-icon');
const progressBar = feature.querySelector('.video-progress-bar');
const progressContainer = feature.querySelector('.video-progress');
let isPlaying = false;
let startTime = 0;
let animationFrame;
const videoDuration = 30; // 30 seconds
// Touch variables
let touchStartX = 0;
let touchStartY = 0;
let isSwiping = false;
// Prevent feature box link navigation when interacting with controls
feature.querySelector('.video-controls').addEventListener('click', (e) => {
e.preventDefault();
e.stopPropagation();
});
// Toggle play/pause with improved touch handling
function togglePlay(event) {
event.preventDefault();
event.stopPropagation();
if (isPlaying) {
pausePseudoVideo();
} else {
playPseudoVideo();
}
}
// Enhanced play function
function playPseudoVideo() {
isPlaying = true;
startTime = startTime || Date.now();
updatePlayButton();
animateProgress();
pseudoVideo.classList.add('playing');
// Start or resume animations with error handling
try {
pseudoVideo.getAnimations().forEach(animation => {
animation.playbackRate = 1;
});
pseudoVideo.querySelectorAll('.pseudo-video-element').forEach(element => {
element.getAnimations().forEach(animation => {
animation.playbackRate = 1;
});
});
} catch (error) {
console.warn('Animation API not fully supported:', error);
}
}
// Enhanced pause function
function pausePseudoVideo() {
isPlaying = false;
updatePlayButton();
cancelAnimationFrame(animationFrame);
pseudoVideo.classList.remove('playing');
try {
pseudoVideo.getAnimations().forEach(animation => {
animation.playbackRate = 0;
});
pseudoVideo.querySelectorAll('.pseudo-video-element').forEach(element => {
element.getAnimations().forEach(animation => {
animation.playbackRate = 0;
});
});
} catch (error) {
console.warn('Animation API not fully supported:', error);
}
}
// Update play button with transition
function updatePlayButton() {
playIcon.style.display = isPlaying ? 'none' : 'block';
pauseIcon.style.display = isPlaying ? 'block' : 'none';
// Add transition effect
playPauseBtn.style.transform = 'scale(0.95)';
setTimeout(() => {
playPauseBtn.style.transform = 'scale(1)';
}, 100);
}
// Improved progress animation
function animateProgress() {
if (!isPlaying) return;
const currentTime = (Date.now() - startTime) / 1000;
const progress = (currentTime % videoDuration) / videoDuration * 100;
if (progressBar) {
progressBar.style.width = `${progress}%`;
}
animationFrame = requestAnimationFrame(animateProgress);
}
// Enhanced progress bar interaction
if (progressContainer) {
progressContainer.addEventListener('click', (event) => {
event.preventDefault();
event.stopPropagation();
const rect = event.currentTarget.getBoundingClientRect();
const pos = (event.clientX - rect.left) / rect.width;
startTime = Date.now() - (pos * videoDuration * 1000);
if (!isPlaying) {
playPseudoVideo();
}
});
}
// Event Listeners with improved mobile handling
playPauseBtn.addEventListener('click', togglePlay);
playPauseBtn.addEventListener('touchend', (e) => {
e.preventDefault();
if (!isSwiping) {
togglePlay(e);
}
});
// Auto-play on hover (desktop only)
if (!isTouch) {
let hoverTimeout;
feature.addEventListener('mouseenter', () => {
// Clear any existing timeout
if (hoverTimeout) {
clearTimeout(hoverTimeout);
}
// Add a small delay before playing
hoverTimeout = setTimeout(() => {
if (!isPlaying) {
playPseudoVideo();
}
}, 100);
});
feature.addEventListener('mouseleave', () => {
// Clear the timeout if it hasn't triggered yet
if (hoverTimeout) {
clearTimeout(hoverTimeout);
}
if (isPlaying) {
pausePseudoVideo();
startTime = 0;
if (progressBar) {
progressBar.style.width = '0%';
}
}
});
}
// Cleanup function
function cleanup() {
cancelAnimationFrame(animationFrame);
if (isPlaying) {
pausePseudoVideo();
}
}
// Clean up animations when the element is removed
if (window.IntersectionObserver) {
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (!entry.isIntersecting && isPlaying) {
cleanup();
}
});
}, { threshold: 0.1 });
observer.observe(feature);
}
});
// Testimonials Auto-scroll
const testimonialsTrack = document.querySelector('.testimonials-track');
const testimonialCards = document.querySelectorAll('.testimonial-card');
const indicators = document.querySelectorAll('.indicator');
let currentIndex = 0;
const totalTestimonials = testimonialCards.length;
// Clone testimonials for infinite scroll
testimonialCards.forEach(card => {
const clone = card.cloneNode(true);
testimonialsTrack.appendChild(clone);
});
// Update indicators
function updateIndicators() {
indicators.forEach((indicator, index) => {
indicator.classList.toggle('active', index === currentIndex);
});
}
// Auto-scroll animation is handled by CSS, but we need to update indicators
setInterval(() => {
currentIndex = (currentIndex + 1) % totalTestimonials;
updateIndicators();
}, 5000); // Match this with the CSS animation duration divided by number of slides
// Pause animation on hover
testimonialsTrack.addEventListener('mouseenter', () => {
testimonialsTrack.style.animationPlayState = 'paused';
});
testimonialsTrack.addEventListener('mouseleave', () => {
testimonialsTrack.style.animationPlayState = 'running';
});
// Handle touch events
let touchStartX = 0;
let touchEndX = 0;
testimonialsTrack.addEventListener('touchstart', (e) => {
touchStartX = e.touches[0].clientX;
testimonialsTrack.style.animationPlayState = 'paused';
}, { passive: true });
testimonialsTrack.addEventListener('touchend', () => {
testimonialsTrack.style.animationPlayState = 'running';
}, { passive: true });
// FAQ Functionality
document.querySelectorAll('.faq-question').forEach(button => {
button.addEventListener('click', () => {
const faqItem = button.closest('.faq-item');
const isActive = faqItem.classList.contains('active');
// Close all other FAQ items
document.querySelectorAll('.faq-item').forEach(item => {
if (item !== faqItem) {
item.classList.remove('active');
}
});
// Toggle current FAQ item
faqItem.classList.toggle('active');
// Accessibility
button.setAttribute('aria-expanded', !isActive);
});
});
// Story Slider Functionality
const storyTrack = document.querySelector('.story-track');
const storySlides = document.querySelectorAll('.story-slide');
const prevButton = document.querySelector('.story-nav-button.prev');
const nextButton = document.querySelector('.story-nav-button.next');
const storyIndicators = document.querySelectorAll('.story-indicator');
let currentSlide = 0;
const slideCount = storySlides.length;
function updateSlider() {
// Update transform
storyTrack.style.transform = `translateX(-${currentSlide * 33.333}%)`;
// Update active states
storySlides.forEach((slide, index) => {
slide.classList.toggle('active', index === currentSlide);
});
// Update indicators
storyIndicators.forEach((indicator, index) => {
indicator.classList.toggle('active', index === currentSlide);
});
// Update button states
prevButton.style.opacity = currentSlide === 0 ? '0.5' : '1';
nextButton.style.opacity = currentSlide === slideCount - 1 ? '0.5' : '1';
}
function goToSlide(index) {
currentSlide = Math.max(0, Math.min(index, slideCount - 1));
updateSlider();
}
// Event Listeners
prevButton.addEventListener('click', () => {
if (currentSlide > 0) {
goToSlide(currentSlide - 1);
}
});
nextButton.addEventListener('click', () => {
if (currentSlide < slideCount - 1) {
goToSlide(currentSlide + 1);
}
});
storyIndicators.forEach((indicator, index) => {
indicator.addEventListener('click', () => {
goToSlide(index);
});
});
// Touch support
let storyTouchStartX = 0;
let storyTouchEndX = 0;
storyTrack.addEventListener('touchstart', (e) => {
storyTouchStartX = e.touches[0].clientX;
}, { passive: true });
storyTrack.addEventListener('touchmove', (e) => {
storyTouchEndX = e.touches[0].clientX;
}, { passive: true });
storyTrack.addEventListener('touchend', () => {
const touchDiff = storyTouchStartX - storyTouchEndX;
if (Math.abs(touchDiff) > 50) { // Minimum swipe distance
if (touchDiff > 0 && currentSlide < slideCount - 1) {
// Swipe left
goToSlide(currentSlide + 1);
} else if (touchDiff < 0 && currentSlide > 0) {
// Swipe right
goToSlide(currentSlide - 1);
}
}
});
// Initialize slider
updateSlider();
// Add scroll reveal animations
function reveal() {
const reveals = document.querySelectorAll('.reveal');
reveals.forEach(element => {
const windowHeight = window.innerHeight;
const elementTop = element.getBoundingClientRect().top;
const elementVisible = 150;
if (elementTop < windowHeight - elementVisible) {
element.classList.add('active');
}
});
}
// Add reveal class to elements
document.querySelectorAll('.benefit-item, .feature-box, .testimonial-card, .faq-item').forEach(element => {
element.classList.add('reveal');
});
// Listen for scroll
window.addEventListener('scroll', reveal);
reveal(); // Initial check
// Add loading animation to buttons
document.querySelectorAll('.waitlist-button, .primary-button').forEach(button => {
const originalText = button.textContent;
button.addEventListener('click', function() {
const dots = document.createElement('div');
dots.className = 'loading-dots';
dots.innerHTML = '<span></span><span></span><span></span>';
const textSpan = document.createElement('span');
textSpan.textContent = ' Loading ';
this.textContent = '';
this.appendChild(textSpan);
this.appendChild(dots);
setTimeout(() => {
this.textContent = originalText;
}, 2000);
});
});
// Add confetti effect on CTA clicks
function createConfetti(x, y) {
const colors = ['#4B7BF5', '#A947FF', '#00F076', '#FFBC00'];
for (let i = 0; i < 50; i++) {
const confetti = document.createElement('div');
confetti.className = 'confetti';
confetti.style.backgroundColor = colors[Math.floor(Math.random() * colors.length)];
confetti.style.left = x + 'px';
confetti.style.top = y + 'px';
confetti.style.transform = `rotate(${Math.random() * 360}deg)`;
document.body.appendChild(confetti);
const angle = Math.random() * Math.PI * 2;
const velocity = 5 + Math.random() * 5;
const dx = Math.cos(angle) * velocity;
const dy = Math.sin(angle) * velocity;
let opacity = 1;
let posX = x;
let posY = y;
function animate() {
if (opacity <= 0) {
confetti.remove();
return;
}
posX += dx;
posY += dy + 2; // Add gravity
opacity -= 0.02;
confetti.style.left = posX + 'px';
confetti.style.top = posY + 'px';
confetti.style.opacity = opacity;
requestAnimationFrame(animate);
}
animate();
}
}
document.querySelectorAll('.waitlist-button, .primary-button').forEach(button => {
button.addEventListener('click', function(e) {
createConfetti(e.clientX, e.clientY);
});
});
// Add hover sound effect (subtle)
const hoverSound = new Audio('data:audio/mp3;base64,SUQzBAAAAAAAI1RTU0UAAAAPAAADTGF2ZjU4LjI5LjEwMAAAAAAAAAAAAAAA//tQwAAAAAAAAAAAAAAAAAAAAAAASW5mbwAAAA8AAAADAAAGhgBVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVWqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqr///////////////////////////////////////////8AAAAATGF2YzU4LjU0AAAAAAAAAAAAAAAAJAAAAAAAAAAAAYZxhxzGAAAAAAAAAAAAAAAAAAAA//tQxAAB8AAAf4AAAAwAAA/wAAABAAABpAAAACAAADSAAAAETEFNRTMuMTAwVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV//tQxBmD8AAAf4AAAAwAAA/wAAABFVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV//tQxCmAAAANIAAAAQAAA0gAAABFVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVU=');
hoverSound.volume = 0.1;
document.querySelectorAll('.benefit-item, .feature-box, .testimonial-card').forEach(element => {
element.addEventListener('mouseenter', () => {
hoverSound.currentTime = 0;
hoverSound.play().catch(() => {}); // Ignore autoplay restrictions
});
});
// Add CSS for confetti
const style = document.createElement('style');
style.textContent = `
.confetti {
position: fixed;
width: 10px;
height: 10px;
pointer-events: none;
z-index: 9999;
}
`;
document.head.appendChild(style);