dimanche 10 janvier 2021

Delete each letter before passing on the next array index?

I've been writing this little script in order to make a "self writing text" animation. The thing is, everytime a word is finished, it jumps straight up to the next one. I can't work my head around it to make so each letter deletes before passing on the next word in the array.

const text = ['design', 'make', 'develop', 'code', 'create']
let count = 0;
let index = 0;
let currentText = "";
let letter = "";

(function type() {
    if (count === text.length) {
        count = 0;
    }
    currentText = text[count];
    letter = currentText.slice(0, ++index);
    
    document.querySelector(".main__animation").textContent = letter;
    if (letter.length === currentText.length) {
        count++
        index = 0;
    }
    setTimeout(type, 500);
}())

Thanks beforehand!

Aucun commentaire:

Enregistrer un commentaire