-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
352 lines (297 loc) · 8.84 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
var tl = gsap.timeline();
var ma = gsap.matchMedia();
ma.add("(min-width: 801px)", () => {
// Desktop animation
tl.from(".page1", {
opacity: 0,
duration: 0.6,
// delay: 0.5,
});
tl.from("#elems", {
y: -20,
opacity: 0,
duration: 0.2,
delay: 0.2,
stagger: 0.3,
});
tl.from(".page1 h3", {
y: -20,
opacity: 0,
duration: 0.7,
stagger: 0.3,
});
tl.from(".page1 h1", {
y: -80,
opacity: 0,
duration: 0.7,
delay: 0.2,
});
});
ma.add("(max-width: 800px)", () => {
// Mobile animation
tl.from(".page1 h3", {
y: -20,
opacity: 0,
duration: 0.2,
stagger: 0,
});
tl.from(".page1 h1", {
y: -80,
opacity: 0,
duration: 0.5,
delay: 0.1,
// stagger: 0.15,
});
});
gsap.from(".services",{
opacity: 0,
y: 100,
duration: 1,
delay: 1,
stagger: 1,
scrollTrigger: {
trigger: ".services",
scroller: "body",
start: "top 90%",
end: "top 30%",
// markers: true,
scrub: 2
},
});
gsap.from(".about-section",{
opacity: 0,
y: 100,
duration: 1,
delay: 1,
stagger: 1,
scrollTrigger: {
trigger: ".about-container",
scroller: "body",
start: "top 90%",
end: "top 30%",
// markers: true,
scrub: 2
},
});
gsap.from(".contact-section",{
opacity: 0,
y: 100,
duration: 1,
delay: 1,
stagger: 1,
scrollTrigger: {
trigger: ".contact-container",
scroller: "body",
start: "top 90%",
end: "top 30%",
// markers: true,
scrub: 2
},
});
// about section
gsap.from(".about-text", {
x: -100,
opacity: 0,
duration: 1,
delay: 1.5,
scrollTrigger: {
trigger: ".about-section",
scroller: "body",
start: "top 60%",
end: "top -10%",
scrub: 1
},
});
gsap.from(".about-image", {
x: 100,
opacity: 0,
duration: 1,
delay: 1.5,
scrollTrigger: {
trigger: ".about-section",
scroller: "body",
start: "top 60%",
end: "top -10%",
scrub: 1
},
});
// gsap.from(".page2 h4", {
// // y: 60,
// // opacity: 0,
// x: 150,
// duration: 0.7,
// delay: 0.5,
// scrollTrigger: {
// trigger: ".page2 ",
// scroller: "body",
// start: "top 70%",
// end: "top -10%",
// // markers: true,
// scrub: 2,
// },
// });
// let mm = gsap.matchMedia();
// mm.add("(min-width: 801px)", () => {
// // Desktop animation
// gsap.to(".page3 h4", {
// transform: "translateX(-200%)",
// scrollTrigger: {
// trigger: ".page3",
// scroller: "body",
// start: "top 0%",
// end: "top -170%",
// scrub: 3,
// pin: true,
// pinSpacing: true,
// onLeave: self => {
// gsap.set(".page3 h4", { clearProps: "all" });
// },
// onEnterBack: self => {
// gsap.set(".page3 h4", { clearProps: "all" });
// }
// },
// });
// });
// mm.add("(max-width: 800px)", () => {
// // Mobile animation
// gsap.to(".page3 h4", {
// transform: "translateX(-200%)",
// scrollTrigger: {
// trigger: ".page3",
// scroller: "body",
// start: "top 0%",
// end: "top -100%", // Reduced scroll distance for mobile
// scrub: 2, // Faster scrub for mobile
// pin: true,
// pinSpacing: true,
// onLeave: self => {
// gsap.set(".page3 h4", { clearProps: "all" });
// },
// onEnterBack: self => {
// gsap.set(".page3 h4", { clearProps: "all" });
// }
// },
// });
// });
function showToast(message, type = 'success') {
const toastContainer = document.querySelector('.toast-container');
const toast = document.createElement('div');
toast.className = `toast ${type}`;
const icon = type === 'success' ? 'check-circle' : 'exclamation-circle';
toast.innerHTML = `
<i class="fas fa-${icon}"></i>
<span class="toast-message">${message}</span>
<button class="toast-close">×</button>
`;
toastContainer.appendChild(toast);
// Add click event to close button
const closeButton = toast.querySelector('.toast-close');
closeButton.addEventListener('click', () => {
toast.style.animation = 'slideOut 0.3s ease-out forwards';
setTimeout(() => toast.remove(), 300);
});
// Auto remove after 5 seconds
setTimeout(() => {
if (toast.parentElement) {
toast.style.animation = 'slideOut 0.3s ease-out forwards';
setTimeout(() => toast.remove(), 300);
}
}, 5000);
}
const API_URL = window.location.hostname === 'localhost'
? 'http://localhost:3000'
: 'https://dadhichevents.onrender.com';
// Contact form handling
document.getElementById('contactForm').addEventListener('submit', async (e) => {
e.preventDefault();
// Disable submit button to prevent double submission
// const submitButton = e.target.querySelector('button[type="submit"]');
const submitButton = document.getElementById('submitButton');
submitButton.disabled = true;
const buttonText = submitButton.querySelector('.button-text');
const loadingSpinner = submitButton.querySelector('.loading-spinner');
buttonText.style.display = 'none';
loadingSpinner.style.display = 'block';
submitButton.disabled = true;
try {
const formData = {
name: document.getElementById('name').value.trim(),
email: document.getElementById('email').value.trim(),
phone: document.getElementById('phone').value.trim(),
message: document.getElementById('message').value.trim()
};
// Validate form data
if (!formData.name || !formData.email || !formData.phone || !formData.message) {
showToast('Please fill in all fields', 'error');
return;
}
// Email validation
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
if (!emailRegex.test(formData.email)) {
showToast('Please enter a valid email address', 'error');
return;
}
// Phone validation
const phoneRegex = /^\+?[\d\s-]{10,}$/;
if (!phoneRegex.test(formData.phone)) {
showToast('Please enter a valid 10-digit phone number', 'error');
return;
}
const response = await fetch(`${API_URL}/api/contact`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(formData)
});
const data = await response.json();
if (response.ok) {
showToast('Message sent successfully! We\'ll get back to you soon.', 'success');
document.getElementById('contactForm').reset();
} else {
showToast(data.message || 'Something went wrong. Please try again.', 'error');
}
document.getElementById('contactForm').reset();
} catch (error) {
// Show error message
showToast('Network error. Please try again later.', 'error');
console.error('Error:', error);
} finally {
// Re-enable submit button
buttonText.style.display = 'block';
loadingSpinner.style.display = 'none';
submitButton.disabled = false;
}
});
// Hamburger menu functionality
const hamburger = document.querySelector('.hamburger');
const navMenu = document.querySelector('#elems');
hamburger.addEventListener('click', () => {
hamburger.classList.toggle('active');
navMenu.classList.toggle('active');
});
// Close menu when clicking a link
document.querySelectorAll('#elems a').forEach(link => {
link.addEventListener('click', () => {
hamburger.classList.remove('active');
navMenu.classList.remove('active');
});
});
// back button
// Back to Top Button
const backToTopButton = document.getElementById('back-to-top');
// Show button when scrolling down
window.addEventListener('scroll', () => {
if (window.scrollY > 300) {
backToTopButton.classList.add('visible');
} else {
backToTopButton.classList.remove('visible');
}
});
// Smooth scroll to top when clicked
backToTopButton.addEventListener('click', () => {
window.scrollTo({
top: 0,
behavior: 'smooth'
});
});