-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
58 lines (58 loc) · 1.77 KB
/
index.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
var form = document.getElementById("my-form");
async function handleSubmit(event) {
event.preventDefault();
var status = document.getElementById("my-form-status");
var data = new FormData(event.target);
fetch(event.target.action, {
method: form.method,
body: data,
headers: {
'Accept': 'application/json'
}
}).then(response => {
if (response.ok) {
status.innerHTML = "Thanks for your submission!";
status.classList.add("recive");
form.reset()
} else {
response.json().then(data => {
if (Object.hasOwn(data, 'errors')) {
status.innerHTML = data["errors"].map(error => error["message"]).join(", ")
status.classList.add("error");
} else {
status.innerHTML = "Oops! There was a problem submitting your form"
status.classList.add("error");
}
})
}
}).catch(error => {
status.innerHTML = "Oops! There was a problem submitting your form"
status.classList.add("error");
});
}
form.addEventListener("submit", handleSubmit);
const navLinks = document.querySelectorAll('nav a');
navLinks.forEach(link => {
link.addEventListener('click', scrollToSection);
});
function scrollToSection(event) {
event.preventDefault();
const targetId = event.target.getAttribute('href');
const targetSection = document.querySelector(targetId);
if (targetSection) {
window.scrollTo({
top: targetSection.offsetTop,
behavior: 'smooth'
});
}
}
const button=document.querySelectorAll(".Contect_me_button");
button.forEach(btn=> {
btn.addEventListener("click",()=>{
const targetArea = document.getElementById("Contact")
window.scrollTo({
top: targetArea.offsetTop,
behavior: "smooth"
});
})
})