-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscripts.js
More file actions
77 lines (68 loc) · 2.48 KB
/
Copy pathscripts.js
File metadata and controls
77 lines (68 loc) · 2.48 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
// Preloader
document.addEventListener("DOMContentLoaded", function() {
setTimeout(function() {
document.getElementById('preloader').style.display = 'none';
}, 1500); // Adjust timeout as needed
});
// Mobile Menu Toggle
document.getElementById('menu-toggle').addEventListener('click', function() {
const navLinks = document.querySelector('.nav-links');
navLinks.classList.toggle('active');
this.classList.toggle('active');
// ARIA attributes for accessibility
const isActive = navLinks.classList.contains('active');
this.setAttribute('aria-expanded', isActive);
navLinks.setAttribute('aria-hidden', !isActive);
});
// Smooth Scroll for Navigation Links
document.querySelectorAll('.nav-links a').forEach(anchor => {
anchor.addEventListener('click', function(e) {
e.preventDefault();
document.querySelector(this.getAttribute('href')).scrollIntoView({
behavior: 'smooth',
block: 'start' // Scroll to the top of the section
});
});
});
// Contact Form Submission with Formspree
document.addEventListener('DOMContentLoaded', function() {
const form = document.querySelector('#contact-form');
form.addEventListener('submit', function(event) {
event.preventDefault();
const formData = new FormData(form);
fetch('https://formspree.io/f/xgvwdloj', {
method: 'POST',
body: formData,
headers: {
'Accept': 'application/json'
}
}).then(response => {
if (response.ok) {
alert('Thank you for your message! We will get back to you soon.');
form.reset();
} else {
alert('Oops! Something went wrong.');
}
}).catch(error => {
console.error('Error:', error);
alert('Oops! Something went wrong.');
});
});
});
// Smooth Scroll to Top Button (Optional)
const scrollToTopButton = document.getElementById('scroll-to-top');
if (scrollToTopButton) {
scrollToTopButton.addEventListener('click', function() {
window.scrollTo({
top: 0,
behavior: 'smooth'
});
});
window.addEventListener('scroll', function() {
if (window.scrollY > 300) {
scrollToTopButton.classList.add('visible');
} else {
scrollToTopButton.classList.remove('visible');
}
});
}