-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
44 lines (37 loc) · 1.21 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
const phrases = ["Web Developer", "Computer Engineer", "Tech Enthusiast", "Problem Solver", "Technology Enthusiast"];
let i = 0;
let j = 0;
let currentPhrase = [];
let isDeleting = false;
let isEnd = false;
function loop() {
isEnd = false;
document.getElementById('typing-text').innerHTML = currentPhrase.join('');
if (i < phrases.length) {
if (!isDeleting && j <= phrases[i].length) {
currentPhrase.push(phrases[i][j]);
j++;
document.getElementById('typing-text').innerHTML = currentPhrase.join('');
}
if (isDeleting && j <= phrases[i].length) {
currentPhrase.pop(phrases[i][j]);
j--;
document.getElementById('typing-text').innerHTML = currentPhrase.join('');
}
if (j == phrases[i].length) {
isEnd = true;
isDeleting = true;
}
if (isDeleting && j === 0) {
currentPhrase = [];
isDeleting = false;
i++;
if (i == phrases.length) {
i = 0;
}
}
}
const speed = isEnd ? 2000 : isDeleting ? 50 : 150;
setTimeout(loop, speed);
}
loop();