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
export function typingCli(element, text, callback = () => {}) {
let i = 0;
function type() {
if (i < text.length) {
const span = document.createElement('span');
span.textContent = text.charAt(i);
element.appendChild(span);
setTimeout(() => {
span.classList.add('active');
if (i > 0) {
element.children[i - 1].classList.remove('active');
}
}, 100);
i++;
setTimeout(type, 200); // adjust speed here
} else {
setTimeout(() => {
if (i > 0) {
element.children[i - 1].classList.remove('active');
}
callback();
}, 200);
}
}
type();
}