-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
45 lines (37 loc) · 1009 Bytes
/
Copy pathscript.js
File metadata and controls
45 lines (37 loc) · 1009 Bytes
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
const roles = [
"Industrial Engineering",
"Systems and Computing Engineering",
"Full-Stack Developer",
"Optimization",
"Privacy & Digital Autonomy",
];
let currentRole = 0;
let charIndex = 0;
let isDeleting = false;
const speed = 100; // typing speed in ms
const pause = 1500; // pause after finishing a word
const target = document.getElementById("typewriter");
function type() {
const text = roles[currentRole];
if (isDeleting) {
charIndex--;
target.textContent = text.substring(0, charIndex);
} else {
charIndex++;
target.textContent = text.substring(0, charIndex);
}
// Am I done writing?
if (!isDeleting && charIndex === text.length) {
isDeleting = true;
setTimeout(type, pause);
}
// Am I done deleting?
else if (isDeleting && charIndex === 0) {
isDeleting = false;
currentRole = (currentRole + 1) % roles.length; // Loop through roles
setTimeout(type, 300);
} else {
setTimeout(type, isDeleting ? 50 : speed);
}
}
type();