So I have a thing to show when a user is typing in my website but I want the typing... to show the dots slower rather than instantly right now I have my current code which works perfectly which is great just it sends the .. and turns it into ... instantly but I'd like to add a like timeout somehow.
var countTyping = 0;
function typingAnimation() {
let items = ['.', '..', '...'];
//return items[Math.floor(Math.random() * items.length)];
//return items[countTyping]; dont use
if (countTyping < 2) {//if the count is less than 2
countTyping++
return items[countTyping]
}
else {
countTyping = 0
return items[countTyping];
}
}
later on I have
'user is typing' + typingAnimation()
in my code which is appended to the document so I can't use a setTimeout(typingAnimation, 1000) or anything or it would show random numbers.
My fix was to add more elements to the array but there are lot more options but this is easiest and quick find for me.
let items = ['.', '.', '..', '..', '...', '...'];