-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
34 lines (30 loc) · 765 Bytes
/
script.js
File metadata and controls
34 lines (30 loc) · 765 Bytes
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
const divElem = document.querySelector('#text')
const text = "Everything you can type...!"
let i = 0
let isDeleting = false
const typeWriter = () => {
if (!isDeleting && i < text.length) {
divElem.textContent += text[i]
i++
setTimeout(() => {
requestAnimationFrame(typeWriter)
}, 100);
} else if (isDeleting && i >= 0) {
divElem.textContent = text.substring(0, i-1)
i--
setTimeout(() => {
requestAnimationFrame(typeWriter)
}, 100);
}
if (i === text.length) {
setTimeout(() => {
isDeleting = true
}, 1000);
} else if (i === 0) {
isDeleting = false
}
}
setInterval(() => {
typeWriter()
}, 4000);
typeWriter()