-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
62 lines (37 loc) · 1.62 KB
/
script.js
File metadata and controls
62 lines (37 loc) · 1.62 KB
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
const deleteH1 = phrase => { //Funcao para deletar frase do dom
let h1 = document.querySelector('h1').innerHTML;
let lenghtTitle = h1.length;
let newh1 = '';
const interval = setInterval(() => {
for (let i = 0; i < h1.length-1; i++) { //Criando nova frase com o h1 exceto a ultima letra
newh1 += h1[i];
}
document.querySelector('h1').innerHTML = newh1; //Substituindo o texto
newh1 = '';
lenghtTitle--;
if (lenghtTitle == 0) { //Se a frase ja foi deletada por completo, inicia a digitacao da proxima frase
clearInterval(interval);
typeH1(phrase + 1);
}
h1 = document.querySelector('h1').innerHTML;
}, 25);
}
const typeH1 = (phrase = 0) => { //Funcao para digitar frase no dom
const titles = ['Lorem ipsum', 'is simply dummy text', 'of the printing and typesetting industry.']; //Frases a serem digitadas
if (phrase >= titles.length) {
phrase = 0;
}
let h1 = document.querySelector('h1');
let j = 0; //Contador para verificar se a frase ja chegou no final
const title = titles[phrase];
const lenghtTitle = title.length;
const interval = setInterval(() => {
h1.innerHTML += title[j]; //Adicionando letra no dom
j++;
if (j >= lenghtTitle) { //Se a frase chegou no final o intervalo e interrompido para o h1 ser deletado na funcao deleteH1
clearInterval(interval);
setTimeout(deleteH1.bind(null, phrase), 2000);
}
}, 50);
}
typeH1();