-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtype.js
49 lines (41 loc) · 1.11 KB
/
type.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
45
46
47
48
49
const textDisplay = document.getElementById('text')
textDisplay.style.color = "#c40233"
const phrases = ['Work', 'Goal!','time!']
let i = 0
let j = 0
let currentPhrase = []
let isDeleting = false
let isEnd = false
function loop () {
isEnd = false
textDisplay.innerHTML = currentPhrase.join('')
if (i < phrases.length) {
if (!isDeleting && j <= phrases[i].length) {
currentPhrase.push(phrases[i][j])
j++
textDisplay.innerHTML = currentPhrase.join('')
}
if(isDeleting && j <= phrases[i].length) {
currentPhrase.pop(phrases[i][j])
j--
textDisplay.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 spedUp = Math.random() * (80 -50) + 50
const normalSpeed = Math.random() * (300 -200) + 200
const time = isEnd ? 2000 : isDeleting ? spedUp : normalSpeed
setTimeout(loop, time)
}
loop()