-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjava.js
More file actions
253 lines (208 loc) · 7.79 KB
/
java.js
File metadata and controls
253 lines (208 loc) · 7.79 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
document.addEventListener('DOMContentLoaded', () => {
// Toggle the menu icon and navbar on click
let menuIcon = document.querySelector('#menu-icon');
let navbar = document.querySelector('.navbar');
menuIcon.onclick = () => {
menuIcon.classList.toggle('bx-x');
navbar.classList.toggle('active');
};
// Handle the Read More button functionality
const readMoreBtn = document.getElementById('read-more-btn');
const moreDetails = document.getElementById('more-details');
readMoreBtn.addEventListener('click', () => {
if (moreDetails.style.display === 'none' || moreDetails.style.display === '') {
moreDetails.style.display = 'block';
readMoreBtn.textContent = 'Read Less';
} else {
moreDetails.style.display = 'none';
readMoreBtn.textContent = 'Read More';
}
});
// Handle zoom effect on service boxes
let serviceBoxes = document.querySelectorAll('.service-box');
let lastClickedBox = null;
serviceBoxes.forEach(box => {
box.addEventListener('click', function() {
if (lastClickedBox && lastClickedBox !== this) {
lastClickedBox.classList.remove('zoomed');
}
this.classList.toggle('zoomed');
lastClickedBox = this;
});
});
// Use Intersection Observer to remove zoom effect when out of view
const observerOptions = {
root: null,
threshold: 0
};
const observerCallback = (entries) => {
entries.forEach(entry => {
if (!entry.isIntersecting) {
entry.target.classList.remove('zoomed');
}
});
};
const observer = new IntersectionObserver(observerCallback, observerOptions);
serviceBoxes.forEach(box => {
observer.observe(box);
});
// Handle the Hire Me modal functionality
const hireBtn = document.getElementById('hire-btn');
const hireModal = document.getElementById('hire-modal');
const closeModal = document.querySelector('.modal .close');
hireBtn.addEventListener('click', () => {
hireModal.style.display = 'block';
document.body.style.overflow = 'hidden'; // Prevent scrolling when the modal is open
});
closeModal.addEventListener('click', () => {
hireModal.style.display = 'none';
document.body.style.overflow = 'auto'; // Restore scrolling when the modal is closed
});
window.addEventListener('click', (event) => {
if (event.target === hireModal) {
hireModal.style.display = 'none';
document.body.style.overflow = 'auto'; // Restore scrolling when the modal is closed
}
});
// Handle form submission
document.getElementById('hire-form').addEventListener('submit', function(event) {
event.preventDefault();
const formData = new FormData(this);
const data = {
name: formData.get('name'),
email: formData.get('email'),
service: formData.get('service'),
date: formData.get('appointment-date'),
time: formData.get('appointment-time')
};
fetch(this.action, {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify(data)
})
.then(response => {
if (response.ok) {
alert('Your request has been sent!');
document.getElementById('hire-form').reset();
hireModal.style.display = 'none';
document.body.style.overflow = 'auto'; // Restore scrolling when the modal is closed
} else {
throw new Error('Network response was not ok.');
}
})
.catch(error => {
console.error('Error:', error);
alert('There was a problem with your request.');
});
});
// Prevent default dragging behavior for images
const track = document.getElementById("image-track");
const images = track.getElementsByClassName("image");
for (let img of images) {
img.addEventListener('dragstart', (e) => e.preventDefault());
}
// Prevent text selection during dragging
window.onmousedown = e => {
if (e.target.matches('input, textarea, select')) return; // Allow interaction with input fields
e.preventDefault();
track.dataset.mouseDownAt = e.clientX;
};
window.onmouseup = () => {
track.dataset.mouseDownAt = "0";
track.dataset.prevPercentage = track.dataset.percentage || "0";
};
window.onmousemove = e => {
if (track.dataset.mouseDownAt === "0") return;
const mouseDelta = parseFloat(track.dataset.mouseDownAt) - e.clientX;
const maxDelta = window.innerWidth / 2;
let percentage = (mouseDelta / maxDelta) * -40;
let nextPercentage = parseFloat(track.dataset.prevPercentage) + percentage;
nextPercentage = Math.min(nextPercentage, 0);
nextPercentage = Math.max(nextPercentage, -100);
track.dataset.percentage = nextPercentage;
track.animate({
transform: `translate(${nextPercentage}%, -0%)`
}, { duration: 1200, fill: "forwards" });
for (const image of track.getElementsByClassName("image")) {
image.animate({
objectPosition: `${100 + nextPercentage}% center`
}, { duration: 1200, fill: "forwards" });
}
};
// Handle touch events for dragging
function handleTouchMove(event) {
event.preventDefault();
const touch = event.touches[0];
const touchX = touch.clientX;
const mouseDelta = parseFloat(track.dataset.mouseDownAt) - touchX;
const maxDelta = window.innerWidth / 2;
let percentage = (mouseDelta / maxDelta) * -20;
let nextPercentage = parseFloat(track.dataset.prevPercentage) + percentage;
nextPercentage = Math.min(nextPercentage, 0);
nextPercentage = Math.max(nextPercentage, -100);
track.dataset.percentage = nextPercentage;
track.animate({
transform: `translate(${nextPercentage}%, -0%)`
}, { duration: 1200, fill: "forwards" });
for (const image of track.getElementsByClassName("image")) {
image.animate({
objectPosition: `${100 + nextPercentage}% center`
}, { duration: 1200, fill: "forwards" });
}
}
function handleTouchStart(event) {
const touch = event.touches[0];
const touchX = touch.clientX;
track.dataset.mouseDownAt = touchX;
}
function handleTouchEnd() {
track.dataset.mouseDownAt = "0";
track.dataset.prevPercentage = track.dataset.percentage || "0";
}
track.addEventListener('touchstart', handleTouchStart);
track.addEventListener('touchmove', handleTouchMove);
track.addEventListener('touchend', handleTouchEnd);
// Add Intersection Observer for animations
const animationOptions = {
root: null,
threshold: 0.1
};
const animationObserver = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
const direction = entry.target.getAttribute('data-animation');
entry.target.classList.add(`fade-in-${direction}`);
animationObserver.unobserve(entry.target);
}
});
}, animationOptions);
const elementsToAnimate = document.querySelectorAll('[data-animation]');
elementsToAnimate.forEach(element => {
animationObserver.observe(element);
});
});
//contact form
document.getElementById('contact-form').addEventListener('submit', function(event) {
event.preventDefault();
const formData = new FormData(this);
fetch(this.action, {
method: this.method,
body: formData,
headers: {
'Accept': 'application/json'
}
}).then(response => {
if (response.ok) {
this.reset();
alert('Thank you for your message!');
} else {
alert('There was a problem with your submission. Please try again.');
}
}).catch(error => {
console.error('Error:', error);
alert('There was a problem with your submission. Please try again.');
});
});