-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
40 lines (34 loc) · 1.03 KB
/
app.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
import { DynamicTexts } from "./constants.js";
let dynamicTextIndex = 0;
let dynamicTextElement = document.getElementById("dynamic-text");
function toggleThemeIcon() {
themeIcon.classList.toggle("fa-sun");
themeIcon.classList.toggle("fa-moon");
}
function typeDynamicText() {
let currentText = DynamicTexts[dynamicTextIndex];
let currentIndex = 0;
function typeCharacter() {
if (currentIndex < currentText.length) {
dynamicTextElement.textContent += currentText.charAt(currentIndex);
currentIndex++;
setTimeout(typeCharacter, 100);
} else {
setTimeout(eraseDynamicText, 300);
}
}
function eraseDynamicText() {
if (dynamicTextElement.textContent.length > 0) {
dynamicTextElement.textContent = dynamicTextElement.textContent.slice(
0,
-1
);
setTimeout(eraseDynamicText, 50);
} else {
dynamicTextIndex = (dynamicTextIndex + 1) % DynamicTexts.length;
setTimeout(typeDynamicText, 200);
}
}
typeCharacter();
}
window.onload = typeDynamicText;