Repository navigation
Expand file tree
/
Copy pathapp.js
More file actions
81 lines (68 loc) · 2.82 KB
/
Copy pathapp.js
File metadata and controls
81 lines (68 loc) · 2.82 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// const texts = ["Front-end Developer", "Web Designer", "Product Designer"]; // Texts to display
// const typingElement = document.getElementById("typing");
// let currentTextIndex = 0; // Index of the current text in the array
// let index = 0; // Index of the current character in the text
// let isErasing = false; // Flag to determine if we are typing or erasing
// function typeText() {
// const currentText = texts[currentTextIndex]; // Get the current text
// if (!isErasing) {
// // Typing mode
// typingElement.textContent += currentText[index];
// index++;
// if (index === currentText.length) {
// // If the entire text is typed, start erasing after a delay
// isErasing = true;
// setTimeout(typeText, 1000); // Wait for 1 second before erasing
// } else {
// setTimeout(typeText, 150); // Adjust typing speed here
// }
// } else {
// // Erasing mode
// typingElement.textContent = currentText.substring(0, index - 1);
// index--;
// if (index === 0) {
// // If the entire text is erased, move to the next text
// isErasing = false;
// currentTextIndex = (currentTextIndex + 1) % texts.length; // Loop to the next text
// setTimeout(typeText, 500); // Wait for 0.5 seconds before typing new text
// } else {
// setTimeout(typeText, 100); // Adjust erasing speed here
// }
// }
// }
// // Start the animation
// typeText();
const texts = ["Front-end Developer", "Web Designer", "Product Designer","Open-Source"]; // Texts to display
const typingElement = document.getElementById("typing");
let currentTextIndex = 0; // Index of the current text in the array
let index = 0; // Index of the current character in the text
let isErasing = false; // Flag to determine if we are typing or erasing
function typeText() {
const currentText = texts[currentTextIndex]; // Get the current text
if (!isErasing) {
// Typing mode
typingElement.textContent += currentText[index];
index++;
if (index === currentText.length) {
// If the entire text is typed, start erasing after a delay
isErasing = true;
setTimeout(typeText, 1000); // Wait for 1 second before erasing
} else {
setTimeout(typeText, 150); // Adjust typing speed here
}
} else {
// Erasing mode
typingElement.textContent = currentText.substring(0, index - 1);
index--;
if (index === 0) {
// If the entire text is erased, move to the next text
isErasing = false;
currentTextIndex = (currentTextIndex + 1) % texts.length; // Loop to the next text
setTimeout(typeText, 500); // Wait for 0.5 seconds before typing new text
} else {
setTimeout(typeText, 100); // Adjust erasing speed here
}
}
}
// Start the animation
typeText();