-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
207 lines (174 loc) · 5.57 KB
/
script.js
File metadata and controls
207 lines (174 loc) · 5.57 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
// Scroll to section function
function scrollToSection(sectionId) {
const element = document.getElementById(sectionId);
if (element) {
element.scrollIntoView({ behavior: 'smooth' });
closeMobileMenu();
}
}
// Header scroll effect
const header = document.getElementById('header');
let lastScrollY = window.scrollY;
window.addEventListener('scroll', () => {
if (window.scrollY > 50) {
header.classList.add('scrolled');
} else {
header.classList.remove('scrolled');
}
lastScrollY = window.scrollY;
});
// Mobile menu
const mobileMenuBtn = document.getElementById('mobile-menu-btn');
const mobileMenu = document.getElementById('mobile-menu');
const menuIcon = mobileMenuBtn.querySelector('.menu-icon');
const closeIcon = mobileMenuBtn.querySelector('.close-icon');
function closeMobileMenu() {
mobileMenu.classList.remove('open');
menuIcon.classList.remove('hidden');
closeIcon.classList.add('hidden');
}
mobileMenuBtn.addEventListener('click', () => {
const isOpen = mobileMenu.classList.toggle('open');
menuIcon.classList.toggle('hidden', isOpen);
closeIcon.classList.toggle('hidden', !isOpen);
});
// Close mobile menu when clicking outside
document.addEventListener('click', (e) => {
if (!mobileMenu.contains(e.target) && !mobileMenuBtn.contains(e.target)) {
closeMobileMenu();
}
});
// Testimonials carousel
const testimonials = document.querySelectorAll('.testimonial');
const dots = document.querySelectorAll('.dot');
const prevArrow = document.querySelector('.arrow-prev');
const nextArrow = document.querySelector('.arrow-next');
let activeIndex = 0;
let autoPlayInterval;
const AUTOPLAY_DELAY = 5000;
function showTestimonial(index) {
testimonials.forEach((testimonial, i) => {
testimonial.classList.toggle('active', i === index);
});
dots.forEach((dot, i) => {
dot.classList.toggle('active', i === index);
});
activeIndex = index;
}
function nextTestimonial() {
const newIndex = (activeIndex + 1) % testimonials.length;
showTestimonial(newIndex);
}
function prevTestimonial() {
const newIndex = (activeIndex - 1 + testimonials.length) % testimonials.length;
showTestimonial(newIndex);
}
function startAutoPlay() {
autoPlayInterval = setInterval(nextTestimonial, AUTOPLAY_DELAY);
}
function resetAutoPlay() {
clearInterval(autoPlayInterval);
startAutoPlay();
}
// Dot navigation
dots.forEach((dot, index) => {
dot.addEventListener('click', () => {
showTestimonial(index);
resetAutoPlay();
});
});
function toggleFaq(button) {
const item = button.parentElement;
const isActive = item.classList.contains('active');
// Toggle current item
if (isActive) {
item.classList.remove('active');
} else {
item.classList.add('active');
}
}
// Arrow navigation
if (prevArrow) {
prevArrow.addEventListener('click', () => {
prevTestimonial();
resetAutoPlay();
});
}
if (nextArrow) {
nextArrow.addEventListener('click', () => {
nextTestimonial();
resetAutoPlay();
});
}
// Start autoplay
startAutoPlay();
// Pause autoplay on hover
const testimonialsSection = document.querySelector('.testimonials');
testimonialsSection.addEventListener('mouseenter', () => {
clearInterval(autoPlayInterval);
});
testimonialsSection.addEventListener('mouseleave', () => {
startAutoPlay();
});
// Contact form
const contactForm = document.getElementById('contact-form');
const toast = document.getElementById('toast');
const submitBtn = contactForm.querySelector('.btn-submit');
contactForm.addEventListener('submit', async (e) => {
e.preventDefault();
// Show loading state
submitBtn.classList.add('loading');
const originalContent = submitBtn.innerHTML;
submitBtn.innerHTML = '<span class="spinner"></span> Sending...';
submitBtn.disabled = true;
// Simulate form submission
await new Promise(resolve => setTimeout(resolve, 1500));
// Reset form
contactForm.reset();
// Restore button
submitBtn.classList.remove('loading');
submitBtn.innerHTML = originalContent;
submitBtn.disabled = false;
// Show toast
toast.classList.add('show');
setTimeout(() => {
toast.classList.remove('show');
}, 3000);
});
// Current year
document.getElementById('current-year').textContent = new Date().getFullYear();
// Scroll reveal animation
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 sections
document.querySelectorAll('section').forEach(section => {
section.style.opacity = '0';
section.style.transform = 'translateY(20px)';
section.style.transition = 'opacity 0.6s ease, transform 0.6s ease';
observer.observe(section);
});
// Make hero visible immediately
const hero = document.querySelector('.hero');
if (hero) {
hero.style.opacity = '1';
hero.style.transform = 'translateY(0)';
}
function toggleChatPopup(show) {
const popup = document.getElementById('chat-popup');
if (show) {
popup.classList.remove('hidden');
} else {
popup.classList.add('hidden');
}
}