-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
233 lines (163 loc) · 5.65 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
var slideIndex = 1;
showSlides(slideIndex);
function plusSlides(n) {
showSlides(slideIndex += n);
}
function currentSlide(n) {
showSlides(slideIndex = n);
}
function showSlides(n) {
var i;
var slides = document.getElementsByClassName("mySlides");
if (n > slides.length) { slideIndex = 1 }
if (n < 1) { slideIndex = slides.length }
for (i = 0; i < slides.length; i++) {
slides[i].style.display = "none";
}
slides[slideIndex - 1].style.display = "block";
}
var slideIndex1 = 0;
showSlide();
function showSlide() {
var i;
var slides = document.getElementsByClassName("mySlides");
for (i = 0; i < slides.length; i++) {
slides[i].style.display = "none";
}
slideIndex1++;
if (slideIndex1 > slides.length) { slideIndex1 = 1 }
slides[slideIndex1 - 1].style.display = "block";
setTimeout(showSlide, 3500);
}
document.getElementById("scrollButton").addEventListener("click", function() {
const targetDiv = document.getElementById("video-section");
targetDiv.scrollIntoView({
behavior: "smooth"
});
});
const image = document.getElementById("resizableImage");
let currentSize = 80;
let isZoomed = false;
function toggleZoom() {
isZoomed = !isZoomed;
resizeImage();
}
function resizeImage() {
if (isZoomed) {
currentSize += 10;
} else {
currentSize -= 10;
}
if (currentSize < 80) {
currentSize = 80;
isZoomed = false;
}
image.style.width = currentSize + "%";
}
var menuItems = document.querySelectorAll('.menu a');
menuItems.forEach(item => {
item.addEventListener('click', () => {
var navi = document.querySelector('.navi');
navi.classList.remove('active');
});
});
document.getElementById('contactForm').addEventListener('submit', function (event) {
event.preventDefault();
var nameInput = this.elements['name'];
var emailInput = this.elements['email'];
var phoneInput = this.elements['phone'];
var messageInput = this.elements['message'];
if (!nameInput.value.trim()) {
showAlert('Please enter your name.');
nameInput.focus();
return;
}
if (!emailInput.value.trim()) {
showAlert('Please enter your email address.');
emailInput.focus();
return;
} else if (!isValidEmail(emailInput.value)) {
showAlert('Please enter a valid email address.');
emailInput.focus();
return;
}
if (!phoneInput.value.trim()) {
showAlert('Please enter your phone number.');
phoneInput.focus();
return;
} else if (!isValidPhone(phoneInput.value)) {
showAlert('Please enter a valid phone number.');
phoneInput.focus();
return;
}
if (!messageInput.value.trim()) {
showAlert('Please enter your message.');
messageInput.focus();
return;
}
this.submit();
});
function isValidEmail(email) {
var emailRegex = /^\S+@\S+\.\S+$/;
return emailRegex.test(email);
}
function isValidPhone(phone) {
var phoneRegex = /^\d{10}$/;
return phoneRegex.test(phone);
}
function showAlert(message) {
var alertDiv = document.createElement('div');
alertDiv.classList.add('alert');
alertDiv.textContent = message;
var form = document.getElementById('contactForm');
form.appendChild(alertDiv);
setTimeout(function () {
alertDiv.remove();
}, 3000);
}
const carImage = document.querySelector('.car');
const carContainer = document.querySelector('.car-container');
let isMovingRight = false;
carImage.addEventListener('click', () => {
isMovingRight = !isMovingRight;
moveCar();
});
function moveCar() {
const carWidth = carImage.clientWidth;
const containerWidth = carContainer.clientWidth;
if (isMovingRight) {
carImage.style.transform = `translateX(${containerWidth - carWidth}px)`;
} else {
carImage.style.transform = 'translateX(0)';
}
}
const scrollToTopBtn = document.getElementById('scrollToTopBtn');
window.onscroll = function () {
if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) {
scrollToTopBtn.style.display = 'block';
} else {
scrollToTopBtn.style.display = 'none';
}
};
function scrollToTop() {
document.body.scrollTop = 0;
document.documentElement.scrollTop = 0;
}
const animateOnScroll = (element, animation) => {
const elementPosition = element.getBoundingClientRect().top;
const screenPosition = window.innerHeight / 1.2;
if (elementPosition < screenPosition) {
element.classList.add(animation);
}
};
const animatedElements = document.querySelectorAll('.mid-section, .mid-section2, .post');
const handleScroll = () => {
animatedElements.forEach((element) => {
if (!element.classList.contains('animated')) {
animateOnScroll(element, 'fadeInUp');
element.classList.add('animated');
}
});
};
window.addEventListener('load', handleScroll);
window.addEventListener('scroll', handleScroll);