website/static/index.js

44 lines
969 B
JavaScript
Raw Normal View History

2023-11-11 06:48:55 -05:00
function simulateCommandPrompt(element, texts, speed, wait) {
const outputElement = document.getElementById(element);
const cursor = document.createElement('span');
cursor.classList.add('cursor');
cursor.textContent = '█';
2022-03-28 15:24:48 -04:00
2023-11-11 06:48:55 -05:00
let currentIndex = 0;
2022-03-28 15:24:48 -04:00
2023-11-11 06:48:55 -05:00
function typeText() {
const text = texts[currentIndex];
let i = 0;
2022-03-28 15:24:48 -04:00
2023-11-11 06:48:55 -05:00
function typeCharacter() {
if (i <= text.length) {
outputElement.textContent = text.slice(0, i);
outputElement.appendChild(cursor);
i++;
setTimeout(typeCharacter, speed);
} else {
setTimeout(() => {
currentIndex = (currentIndex + 1) % texts.length;
outputElement.textContent = '';
outputElement.appendChild(cursor);
typeText();
}, wait);
}
}
2022-03-28 15:24:48 -04:00
2023-11-11 06:48:55 -05:00
typeCharacter();
}
2022-03-28 15:24:48 -04:00
2023-11-11 06:48:55 -05:00
typeText();
2022-03-28 15:24:48 -04:00
}
2023-11-11 06:48:55 -05:00
const texts = [
'software',
'reality',
2023-11-11 06:58:07 -05:00
'profit',
'results',
'tech'
2023-11-11 06:48:55 -05:00
];
simulateCommandPrompt('typing', texts, 100, 3000);