-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
100 lines (86 loc) · 3.02 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
document.addEventListener('DOMContentLoaded', () => {
// AOS
AOS.init({
duration: 1000,
once: true
});
// Burger menu
const burgerMenu = document.querySelector('.burger-menu');
const navLinks = document.querySelector('.nav-links');
const overlay = document.querySelector('.overlay');
burgerMenu.addEventListener('click', () => {
burgerMenu.classList.toggle('active');
navLinks.classList.toggle('active');
overlay.classList.toggle('active');
if (burgerMenu.classList.contains('active')) {
burgerMenu.innerHTML = '<i class="fas fa-times"></i>';
} else {
burgerMenu.innerHTML = '<i class="fas fa-bars"></i>';
}
});
// Smooth scrolling for nav links
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
document.querySelector(this.getAttribute('href')).scrollIntoView({
behavior: 'smooth'
});
if (navLinks.classList.contains('active')) {
burgerMenu.click();
}
});
});
// Accordion - FAQ section
const accordionItems = document.querySelectorAll('.accordion-item');
accordionItems.forEach(item => {
const header = item.querySelector('.accordion-header');
header.addEventListener('click',
() => {
const currentlyActiveItem = document.querySelector('.accordion-item.active');
if (currentlyActiveItem && currentlyActiveItem !== item) {
currentlyActiveItem.classList.remove('active');
currentlyActiveItem.querySelector('.accordion-content').style.maxHeight = null;
}
item.classList.toggle('active');
const content = item.querySelector('.accordion-content');
if (item.classList.contains('active')) {
content.style.maxHeight = content.scrollHeight + 'px';
} else {
content.style.maxHeight = null;
}
});
});
// Form submission
const contactForm = document.querySelector('.contact-form');
contactForm.addEventListener('submit', (e) => {
e.preventDefault();
const formData = new FormData(contactForm);
console.log('Form submitted with data:',
Object.fromEntries(formData));
alert('Thank you for your message. We will get back to you soon!');
contactForm.reset();
});
// Testimonial slider
const testimonialSlider = document.querySelector('.testimonial-slider');
let isDown = false;
let startX;
let scrollLeft;
testimonialSlider.addEventListener('mousedown', (e) => {
isDown = true;
startX = e.pageX - testimonialSlider.offsetLeft;
scrollLeft = testimonialSlider.scrollLeft;
});
testimonialSlider.addEventListener('mouseleave', () => {
isDown = false;
});
testimonialSlider.addEventListener('mouseup', () => {
isDown = false;
});
testimonialSlider.addEventListener('mousemove', (e) => {
if (!isDown) return;
e.preventDefault();
const x = e.pageX - testimonialSlider.offsetLeft;
const walk = (x - startX) * 3;
testimonialSlider.scrollLeft = scrollLeft - walk;
});
});