-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
42 lines (35 loc) · 847 Bytes
/
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
const target = document.getElementById('target')
let array = ['simple', 'clear', 'smart', 'strong']
let wordIndex = 0
let letterIndex = 0
const createLetter = () => {
const letter = document.createElement('span')
target.appendChild(letter)
letter.classList.add('letter')
letter.style.opacity = '0'
letter.style.animation = 'anim 5s ease forwards'
letter.textContent = array[wordIndex][letterIndex]
setTimeout(() => {
letter.remove()
}, 2000)
}
const loop = () => {
setTimeout(() => {
if (wordIndex >= array.length) {
wordIndex = 0
letterIndex = 0
loop()
} else if (letterIndex < array[wordIndex].length) {
createLetter()
letterIndex++
loop()
} else {
letterIndex = 0
wordIndex++
setTimeout(() => {
loop()
}, 2000)
}
}, 80)
}
loop()