-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
442 lines (388 loc) · 15.1 KB
/
Copy pathscript.js
File metadata and controls
442 lines (388 loc) · 15.1 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
// Mobile Navigation Toggle
const hamburger = document.querySelector('.hamburger');
const navMenu = document.querySelector('.nav-menu');
hamburger.addEventListener('click', () => {
hamburger.classList.toggle('active');
navMenu.classList.toggle('active');
});
// Close mobile menu when clicking on nav links
document.querySelectorAll('.nav-menu a').forEach(link => {
link.addEventListener('click', () => {
hamburger.classList.remove('active');
navMenu.classList.remove('active');
});
});
// 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
window.addEventListener('scroll', () => {
const header = document.querySelector('.header');
if (window.scrollY > 100) {
header.style.background = 'rgba(255, 255, 255, 0.98)';
header.style.boxShadow = '0 2px 20px rgba(0, 0, 0, 0.15)';
} else {
header.style.background = 'rgba(255, 255, 255, 0.95)';
header.style.boxShadow = '0 2px 20px rgba(0, 0, 0, 0.1)';
}
});
// Set minimum date to today for date inputs
const today = new Date().toISOString().split('T')[0];
const pickupDate = document.getElementById('pickup-date');
const returnDate = document.getElementById('return-date');
if (pickupDate) pickupDate.min = today;
if (returnDate) returnDate.min = today;
// Update return date minimum when pickup date changes
if (pickupDate) {
pickupDate.addEventListener('change', () => {
if (returnDate) {
returnDate.min = pickupDate.value;
if (returnDate.value && returnDate.value < pickupDate.value) {
returnDate.value = '';
}
}
});
}
// Booking form submission
const bookingForm = document.getElementById('bookingForm');
if (bookingForm) {
bookingForm.addEventListener('submit', (e) => {
e.preventDefault();
const pickupLocation = document.getElementById('pickup-location').value;
const pickupDateValue = document.getElementById('pickup-date').value;
const returnDateValue = document.getElementById('return-date').value;
const carType = document.getElementById('car-type').value;
// Validate dates
if (new Date(returnDateValue) <= new Date(pickupDateValue)) {
showNotification('Return date must be after pickup date!', 'error');
return;
}
// Calculate days
const days = Math.ceil((new Date(returnDateValue) - new Date(pickupDateValue)) / (1000 * 60 * 60 * 24));
showNotification(`Searching for ${carType} cars from ${pickupLocation} for ${days} days...`, 'success');
// Scroll to cars section
setTimeout(() => {
document.getElementById('cars').scrollIntoView({ behavior: 'smooth' });
}, 1000);
});
}
// Contact form submission
const contactForm = document.getElementById('contactForm');
if (contactForm) {
contactForm.addEventListener('submit', (e) => {
e.preventDefault();
const formData = new FormData(contactForm);
const name = contactForm.querySelector('input[type="text"]').value;
const email = contactForm.querySelector('input[type="email"]').value;
const message = contactForm.querySelector('textarea').value;
if (name && email && message) {
showNotification('Thank you for your message! We will get back to you soon.', 'success');
contactForm.reset();
} else {
showNotification('Please fill in all fields.', 'error');
}
});
}
// Car rental function
function rentCar(carName, price) {
const pickupDate = document.getElementById('pickup-date')?.value;
const returnDate = document.getElementById('return-date')?.value;
if (!pickupDate || !returnDate) {
showNotification('Please select pickup and return dates first!', 'error');
document.getElementById('pickup-date')?.focus();
return;
}
if (new Date(returnDate) <= new Date(pickupDate)) {
showNotification('Return date must be after pickup date!', 'error');
return;
}
const days = Math.ceil((new Date(returnDate) - new Date(pickupDate)) / (1000 * 60 * 60 * 24));
const totalPrice = days * price;
const confirmation = confirm(
`Car: ${carName}\n` +
`Rental Period: ${days} days\n` +
`Daily Rate: RS${price}\n` +
`Total Cost: RS${totalPrice}\n\n` +
`Would you like to proceed with this rental?`
);
if (confirmation) {
showNotification(`Booking confirmed for ${carName}! Total: RS${totalPrice}`, 'success');
// Simulate booking process
setTimeout(() => {
alert(`Booking Reference: DR${Math.random().toString(36).substr(2, 9).toUpperCase()}\n\nThank you for choosing DriveEasy!`);
}, 1500);
}
}
// Notification system
function showNotification(message, type = 'info') {
// Remove existing notifications
const existingNotification = document.querySelector('.notification');
if (existingNotification) {
existingNotification.remove();
}
// Create notification element
const notification = document.createElement('div');
notification.className = `notification notification-${type}`;
notification.innerHTML = `
<div class="notification-content">
<span class="notification-message">${message}</span>
<button class="notification-close">×</button>
</div>
`;
// Add styles
notification.style.cssText = `
position: fixed;
top: 90px;
right: 20px;
z-index: 10000;
padding: 15px 20px;
border-radius: 8px;
color: white;
font-weight: 500;
max-width: 400px;
box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
transform: translateX(100%);
transition: transform 0.3s ease;
background: ${type === 'success' ? '#2ecc71' : type === 'error' ? '#e74c3c' : '#3498db'};
`;
const content = notification.querySelector('.notification-content');
content.style.cssText = `
display: flex;
justify-content: space-between;
align-items: center;
gap: 15px;
`;
const closeBtn = notification.querySelector('.notification-close');
closeBtn.style.cssText = `
background: none;
border: none;
color: white;
font-size: 20px;
cursor: pointer;
padding: 0;
line-height: 1;
`;
// Add to page
document.body.appendChild(notification);
// Animate in
setTimeout(() => {
notification.style.transform = 'translateX(0)';
}, 100);
// Close button functionality
closeBtn.addEventListener('click', () => {
notification.style.transform = 'translateX(100%)';
setTimeout(() => notification.remove(), 300);
});
// Auto remove after 5 seconds
setTimeout(() => {
if (notification.parentNode) {
notification.style.transform = 'translateX(100%)';
setTimeout(() => notification.remove(), 300);
}
}, 5000);
}
// Animate elements on scroll
const observerOptions = {
threshold: 0.1,
rootMargin: '0px 0px -50px 0px'
};
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.style.opacity = '1';
entry.target.style.transform = 'translateY(0)';
}
});
}, observerOptions);
// Observe elements for animation
document.addEventListener('DOMContentLoaded', () => {
const animateElements = document.querySelectorAll('.car-card, .service-card');
animateElements.forEach(el => {
el.style.opacity = '0';
el.style.transform = 'translateY(30px)';
el.style.transition = 'opacity 0.6s ease, transform 0.6s ease';
observer.observe(el);
});
});
// Car image hover effect
document.addEventListener('DOMContentLoaded', () => {
const carCards = document.querySelectorAll('.car-card');
carCards.forEach(card => {
const img = card.querySelector('img');
card.addEventListener('mouseenter', () => {
img.style.transform = 'scale(1.05)';
img.style.transition = 'transform 0.3s ease';
});
card.addEventListener('mouseleave', () => {
img.style.transform = 'scale(1)';
});
});
});
// Counter animation for stats
function animateCounter(element, target, duration = 2000) {
let start = 0;
const increment = target / (duration / 16);
const timer = setInterval(() => {
start += increment;
if (start >= target) {
element.textContent = target.toLocaleString() + '+';
clearInterval(timer);
} else {
element.textContent = Math.floor(start).toLocaleString() + '+';
}
}, 16);
}
// Animate counters when in view
const statsObserver = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
const statElements = entry.target.querySelectorAll('.stat h3');
statElements.forEach((stat, index) => {
const targets = [10000, 500, 50];
setTimeout(() => {
animateCounter(stat, targets[index]);
}, index * 200);
});
statsObserver.unobserve(entry.target);
}
});
});
document.addEventListener('DOMContentLoaded', () => {
const statsSection = document.querySelector('.stats');
if (statsSection) {
statsObserver.observe(statsSection);
}
});
// Add loading effect to buttons
document.addEventListener('DOMContentLoaded', () => {
const buttons = document.querySelectorAll('button, .cta-button, .rent-btn');
buttons.forEach(btn => {
btn.addEventListener('click', function() {
if (!this.classList.contains('loading')) {
this.classList.add('loading');
const originalText = this.textContent;
// Add loading styles
this.style.position = 'relative';
this.style.color = 'transparent';
// Create spinner
const spinner = document.createElement('div');
spinner.style.cssText = `
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 20px;
height: 20px;
border: 2px solid rgba(255,255,255,0.3);
border-top: 2px solid white;
border-radius: 50%;
animation: spin 1s linear infinite;
`;
this.appendChild(spinner);
// Add spin animation
const style = document.createElement('style');
style.textContent = `
@keyframes spin {
0% { transform: translate(-50%, -50%) rotate(0deg); }
100% { transform: translate(-50%, -50%) rotate(360deg); }
}
`;
document.head.appendChild(style);
// Remove loading after delay
setTimeout(() => {
this.classList.remove('loading');
this.style.color = '';
if (spinner.parentNode) spinner.remove();
if (style.parentNode) style.remove();
}, 1000);
}
});
});
});
// Parallax effect for hero section
window.addEventListener('scroll', () => {
const scrolled = window.pageYOffset;
const heroImage = document.getElementById('hero-car');
if (heroImage) {
heroImage.style.transform = `translateY(${scrolled * 0.5}px)`;
}
});
// Search functionality (basic filter)
function filterCars(searchTerm) {
const carCards = document.querySelectorAll('.car-card');
carCards.forEach(card => {
const carName = card.querySelector('h3').textContent.toLowerCase();
if (carName.includes(searchTerm.toLowerCase())) {
card.style.display = 'block';
} else {
card.style.display = 'none';
}
});
}
// Price range filter
function filterByPrice(maxPrice) {
const carCards = document.querySelectorAll('.car-card');
carCards.forEach(card => {
const priceText = card.querySelector('.price').textContent;
const price = parseInt(priceText.replace(/[^0-9]/g, ''));
if (price <= maxPrice) {
card.style.display = 'block';
} else {
card.style.display = 'none';
}
});
}
// Initialize tooltips and interactive elements
document.addEventListener('DOMContentLoaded', () => {
// Add ripple effect to buttons
const rippleButtons = document.querySelectorAll('.rent-btn, .search-btn, .cta-button');
rippleButtons.forEach(btn => {
btn.addEventListener('click', function(e) {
const ripple = document.createElement('span');
const rect = this.getBoundingClientRect();
const size = Math.max(rect.width, rect.height);
const x = e.clientX - rect.left - size / 2;
const y = e.clientY - rect.top - size / 2;
ripple.style.cssText = `
position: absolute;
width: ${size}px;
height: ${size}px;
left: ${x}px;
top: ${y}px;
background: rgba(255, 255, 255, 0.6);
border-radius: 50%;
transform: scale(0);
animation: ripple 0.6s linear;
pointer-events: none;
`;
this.style.position = 'relative';
this.style.overflow = 'hidden';
this.appendChild(ripple);
// Add ripple animation
const style = document.createElement('style');
style.textContent = `
@keyframes ripple {
to {
transform: scale(4);
opacity: 0;
}
}
`;
document.head.appendChild(style);
setTimeout(() => {
ripple.remove();
style.remove();
}, 600);
});
});
});