-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathScript.js
97 lines (83 loc) · 2.63 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
const projectContainer = document.querySelector('.project-container');
function setProjectContainerClass() {
if (window.innerWidth >= 768) {
projectContainer.classList.remove('single-column');
} else {
projectContainer.classList.add('single-column');
}
}
setProjectContainerClass();
window.addEventListener('resize', setProjectContainerClass);
//adjustable sidebar
const toggleButton = document.getElementById('toggle-button');
const navLinks = document.querySelector('.nav-links');
const closeIcon = document.createElement('i');
closeIcon.className = 'fa fa-times';
toggleButton.addEventListener('click', function() {
if (toggleButton.classList.contains('fa-bars')) {
navLinks.classList.toggle('active');
toggleButton.classList.remove('fa-bars');
toggleButton.classList.add('fa-times');
} else {
navLinks.classList.remove('active');
toggleButton.classList.add('fa-bars');
toggleButton.classList.remove('fa-times');
}
});
navLinks.addEventListener('click', function(event) {
if (event.target.tagName === 'A') {
navLinks.classList.remove('show');
toggleButton.classList.add('fa-bars');
toggleButton.classList.remove('fa-times');
}
});
//greetings and
//validation
const form = document.getElementById('contact-form');
const nameInput = document.getElementById('name');
const emailInput = document.getElementById('email');
const messageInput = document.getElementById('message');
form.addEventListener('submit', function(event) {
event.preventDefault();
if (!validateForm()) {
return;
}
const name = nameInput.value;
const mail= emailInput.value;
const mess= messageInput.value;
const message = `Message sent successfully. Thank you, ${name}!`;
alert(message);
console.log(name+" "+"with e-mail as"+" "+mail+" "+"says"+" "+mess);
form.reset();
});
function validateForm() {
let valid = true;
if (nameInput.value.trim() === '') {
valid = false;
nameInput.classList.add('error');
} else {
nameInput.classList.remove('error');
}
if (emailInput.value.trim() === '') {
valid = false;
emailInput.classList.add('error');
} else {
emailInput.classList.remove('error');
}
if (messageInput.value.trim() === '') {
valid = false;
messageInput.classList.add('error');
} else {
messageInput.classList.remove('error');
}
return valid;
}
// Show loading effect
document.addEventListener("DOMContentLoaded", function() {
var overlay = document.getElementById("loading-overlay");
var spinner = document.getElementById("loading-spinner");
overlay.style.display = "flex";
setTimeout(function() {
overlay.style.display = "none";
}, 800);
});