-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
148 lines (119 loc) · 3.6 KB
/
main.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
//TO TOP BUTTON
toTopbutton = document.getElementById("toTopBtn");
window.onscroll = function () {
scrollFunction();
};
function scrollFunction() {
if (
document.body.scrollTop > 700 ||
document.documentElement.scrollTop > 700
) {
toTopbutton.style.display = "block";
} else {
toTopbutton.style.display = "none";
}
}
function toTopFunction() {
document.body.scrollTop = 0;
document.documentElement.scrollTop = 0;
}
// FORM VALIDATION
function main() {
var Form = document.getElementById("contactForm");
Form.addEventListener("submit", validateForm);
}
function validateForm(event) {
var formValid = true;
var contactForm = document.getElementById("contactForm");
if (contactForm.name.value == "") {
formValid = false;
document.getElementById("nameError").style.display = "block";
event.preventDefault();
} else {
document.getElementById("nameError").style.display = "none";
}
if (contactForm.email.value == "") {
formValid = false;
document.getElementById("emailError").style.display = "block";
event.preventDefault();
} else {
document.getElementById("emailError").style.display = "none";
}
if (contactForm.message.value == "") {
formValid = false;
//display error message
document.getElementById("messageError").style.display = "block";
//stop form from submitting
event.preventDefault();
} else {
document.getElementById("messageError").style.display = "none";
}
if (contactForm.email.value == "") {
formValid = false;
document.getElementById("tickError").style.display = "block";
event.preventDefault();
} else {
document.getElementById("tickError").style.display = "none";
}
}
//SEND BUTTON
const btn = document.querySelector(".btn");
const btnText = document.querySelector(".btn");
var contactForm = document.getElementById("contactForm");
btn.addEventListener("click", () => {
if (contactForm.name.value != "" && contactForm.email.value != "" && contactForm.message.value != "" && contactForm.agree.value == "yes") {
btn.classList.add("sending");
btnText.innerHTML = "Sending...";
setTimeout(() => {
btn.classList.remove("sending");
btnText.innerHTML = "Sent!";
}, 2000);
}
});
// TYPEWRITER
document.addEventListener("DOMContentLoaded", function (event) {
var text = ["software developer", "digital designer"];
function typeWriter(text, i, fnCallback) {
if (i < text.length) {
document.querySelector("h2").innerHTML =
text.substring(0, i + 1) + '<span class="typewritter" aria-hidden="true"></span>';
setTimeout(function () {
typeWriter(text, i + 1, fnCallback);
}, 100);
} else if (typeof fnCallback == "function") {
setTimeout(fnCallback, 900);
}
}
function StartTextAnimation(i) {
if (i >= text.length) {
i = 0;
}
if (i < text.length) {
typeWriter(text[i], 0, function () {
StartTextAnimation(i + 1);
});
}
}
StartTextAnimation(0);
});
// HAMBURGER MENU
function hamburgerMenu() {
var x = document.getElementById("links"),
z = document.getElementById("hamburger");
var z_states = [
'<img src="assets/icons8-menu-copy.svg" alt="menu">',
'<img src="assets/icons8-multiply-copy.svg" alt="close">',
];
if (z.innerHTML == z_states[0]) {
z.innerHTML = z_states[1];
x.classList.add("responsive");
} else {
z.innerHTML = z_states[0];
x.classList.remove("responsive");
}
}
// AUTOMATIC DATE UPDATE FOR FOOTER
const footerYear = document.getElementById("year");
const date = new Date();
const year = date.getFullYear();
footerYear.innerText = year;