Open ajmeese7 opened 2 years ago
You could do something like this for a typing animation effect:
function type(words, delay, callback) {
for(let i = 0; i <= words.length; i++) {
let timeoutDelay = delay * (i + 1);
setTimeout(() => callback(words.slice(0, i)), timeoutDelay);
}
}
Callback is a function that takes a string as an argument. It'll be called with the progress of the typing. You can use this callback to update your UI.
Idea inspired by the awesome suggestion from @Pirijan here.