-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
58 lines (56 loc) · 2.24 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
startTyping = async (element_name, time, iterations) => {
const upper_divs = document.getElementById(element_name).children;
const lower_divs = [];
for (let i = 0; i < upper_divs.length; i++) {
for (let j = 0; j < upper_divs[i].children.length; j++) {
if (iterations === 2) {
lower_divs.push(upper_divs[i].children[j]);
} else {
for (let k = 0; k < upper_divs[i].children[j].children.length; k++) {
lower_divs.push(upper_divs[i].children[j].children[k]);
}
}
}
}
let current_chars = 0;
for (let i = 0; i < lower_divs.length; i++) {
const current_obj = lower_divs[i];
setTimeout(function() {
if (current_obj.classList.contains('no-type')) {
current_obj.classList.add('show');
} else {
const body = current_obj.textContent;
current_obj.style.height = current_obj.offsetHeight;
current_obj.style.width = current_obj.offsetWidth;
current_obj.textContent = '';
current_obj.classList.add('show');
current_obj.classList.add('typing');
for (let j = 0; j < body.length; j++) {
setTimeout(function() {
if (j === body.length - 1 && i !== lower_divs.length - 1) {
current_obj.textContent = body.slice(0, j + 1);
} else {
current_obj.textContent = body.slice(0, j + 1);
current_obj.innerHTML += '<span class="cursor">█</span>';
}
}, j * time + time);
}
}
}, current_chars * time)
if (current_obj.classList.contains('no-type')) {
current_chars += 30;
} else {
current_chars += current_obj.textContent.length;
}
current_obj.classList.remove('typing');
}
}
loadPortfolio = async () => {
const r = await axios({
method: 'get',
url: 'projects.json',
}).catch(function(error) {
alert(error + '\nThere was an error loading the portfolio.')
});
return r.data;
}