-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
94 lines (74 loc) · 2.7 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
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
function typeMessage(id, message, i, speed) {
if (i < message.length) {
document.getElementById(id).innerHTML += message.charAt(i);
i++;
}
// the last 3 arguments are arguments that will be passed in to the function, that is, typeMessage
setTimeout(typeMessage, speed, id, message, i, speed);
}
typeMessage('welcome', 'Welcome!', 0, 200);
typeMessage('technologies', 'Technologies I currently work with:', 0, 200);
const aboutPage = document.getElementById('about');
const contactPage = document.getElementById('contact');
const noise = document.getElementById('noise');
const semapp = document.getElementById('semapp');
const trainingMode = document.getElementById('trainingMode');
const whoolsoWebApp = document.getElementById('whoolsoWebApp');
const whoolsoAPI = document.getElementById('whoolsoAPI');
let viewingPage = aboutPage;
const aboutButton = document.getElementById('aboutButton');
const projectsButton = document.getElementById('projectsButton');
const contactButton = document.getElementById('contactButton');
const previousButton = document.getElementById('previousButton');
const nextButton = document.getElementById('nextButton');
let transitioning = false;
function switchPage(pageToSwitchTo) {
if (transitioning) {
return;
}
viewingPage.classList.add('hidden');
noise.classList.remove('opacity-0');
transitioning = true;
setTimeout(function () {
noise.classList.add('opacity-0');
pageToSwitchTo.classList.remove('hidden');
viewingPage = pageToSwitchTo;
if (pageToSwitchTo === aboutPage) {
document.getElementById('welcome').innerHTML = '';
typeMessage('welcome', 'Welcome!', 0, 200);
}
transitioning = false;
}, 1000);
}
// LISTENERS
contactButton.addEventListener('click', function () {
switchPage(contactPage);
});
aboutButton.addEventListener('click', function () {
switchPage(aboutPage);
});
projectsButton.addEventListener('click', function () {
switchPage(trainingMode);
});
let projects = [trainingMode, semapp, whoolsoAPI, whoolsoWebApp];
let viewingProject = 0;
nextButton.addEventListener('click', function () {
if (viewingPage === aboutPage || viewingPage === contactPage) {
return;
}
viewingProject = viewingProject + 1;
if (viewingProject > projects.length - 1) {
viewingProject = 0;
}
switchPage(projects[viewingProject]);
});
previousButton.addEventListener('click', function () {
if (viewingPage === aboutPage || viewingPage === contactPage) {
return;
}
viewingProject = viewingProject - 1;
if (viewingProject < 0) {
viewingProject = projects.length - 1;
}
switchPage(projects[viewingProject]);
});