-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
86 lines (70 loc) · 2.5 KB
/
Copy pathscript.js
File metadata and controls
86 lines (70 loc) · 2.5 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
document.addEventListener('DOMContentLoaded', () =>{
const isMobile = window = window.innerWidth <= 1025;
//Function to create and obser Intersection Observers
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 diferent sections
createObserver('#about .phrase', { root: null, threshold: isMobile ? 0.5 : 1}, 'active');
createObserver('#gallery .image-box', { root: null, threshold: isMobile ? 0 : 0.3}, 'active');
createObserver('#blog .featured-article, #blog .article', { root: null, threshold: isMobile ? 0 : 0.3}, 'fadeInUp');
createObserver('#contact > div', { root: null, threshold: isMobile ? 0.3 : 0.7}, 'fadeInUp');
});
/*----------Navigation---------*/
const nav = document.getElementById('nav');
const menuIcon = document.getElementsByClassName('menu')[0];
const listItems = document.querySelectorAll('#nav ul li a');
function toggleMenu() {
nav.classList.toggle("active")
menuIcon.classList.toggle("active");
listItems.forEach((listItems) => {
listItems.classList.toggle('active');
});
}
function hideMenu() {
nav.classList.remove("active");
menuIcon.classList.remove("active");
for (item of listItems) {
item.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(() => { toast.classList.remove('show');},10000);
} else {
// Handle error here
alert('Form submission failed');
}
})
.catch(error => {
console.error('Error', error);
})
})