I would like to animate text decryption.
For ex., I have the encrypted text **** long ********* ****
and I would like to slowly replace it with some long encrypted text
.
I tried to use the code below, but it replaces the text immediately when I need to pause after each symbol is replaced.
function play(encText, decrText) {
function showText() {
var text = decrText.substring(0, i+1) + encText.substring(i+1);
console.log(text);
document.getElementById('text').innerHTML = text;
}
for( var i=0; i < encText.length+1; i++ ) {
setTimeout( showText(), i*5000 );
}
}
See https://jsfiddle.net/bwf0Layg/.
How could I fix that?