-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscript.js
78 lines (69 loc) · 2.39 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
document.addEventListener('DOMContentLoaded', () => {
const isMobile = window.innerWidth <= 1025;
// Function to create and observe IntersectionObservers
function createObserver(selector, observerOptions, toggleClass) {
const items = document.querySelectorAll(selector);
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add(toggleClass);
} else {
entry.target.classList.remove(toggleClass);
}
});
}, observerOptions);
items.forEach(item => {
observer.observe(item);
});
}
// Create observers for different sections
createObserver('#about .phrase', { root: null, threshold: isMobile ? 0.5 : 1 }, 'active');
createObserver('#gallery .image-box', { root: null, threshold: isMobile ? 0.5 : 1 }, 'active');
createObserver('#blog .featured-article, #blog .article', { root: null, threshold: isMobile ? 0.01 : 0.3 }, 'fadeInUp');
createObserver('#contact > div', { root: null, threshold: isMobile ? 0.01 : 0.7 }, 'fadeInUp');
});
// Navigation ----------------------------------------
const nav = document.getElementById('nav');
const menuIcon = document.querySelector('.menu-icon');
const listItems = document.querySelectorAll('nav ul li a');
function toggleMenu() {
nav.classList.toggle('active');
menuIcon.classList.toggle('active');
listItems.forEach((listItem) => {
listItem.classList.toggle('active');
});
}
function hideMenu() {
nav.classList.remove('active');
menuIcon.classList.remove('active');
listItems.forEach((listItem) => {
listItem.classList.remove('active');
});
}
// Form Submission ---------------------------------
document.getElementById('myForm').addEventListener('submit', function(event) {
event.preventDefault();
const form = this;
const formData = new FormData(form);
fetch(form.action, {
method: 'POST',
body: formData,
headers: {
'Accept': 'application/json'
}
})
.then(response => {
if (response.ok) {
form.reset();
const toast = document.getElementById("toast");
toast.classList.add("show");
setTimeout(function(){ toast.classList.remove("show"); }, 10000);
} else {
// Handle errors here
alert('Form submission failed!');
}
})
.catch(error => {
console.error('Error:', error);
});
});