Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

252
Visualizações
How do I make a typing animation?

I've been attempting to create a typing animation program that creates an animation of typing a word. Every period of time (1 second), it adds a letter to the output, seemingly "typing" the word out. Here is my code:

let input = document.querySelector("#input");
let text = document.querySelector("#text");
let run = document.querySelector("#run");
let str = input.value;

run.onclick = function() {
  text.innerText = "";
  str = input.value;
  let chars = [];
  for (let i = 0; i < str.length; i++) {
    chars[i] = str.charAt(i);
  }
  
  for (let i = 0; i < chars.length; i++) {
    setTimeout(function() {
      text.innerText += chars[i];
    }, 1000)
  }
}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Here's one implementation using setInterval.

As Andy mentioned in the comments, just search and you'll find plenty of other implementations and answers here at SO.

let input = document.querySelector("#input");
let text = document.querySelector("#text");
let run = document.querySelector("#run");

run.addEventListener("click", function() {
  text.innerText = "";
  const str = input.value;
  const chars = str.split("");
  const interval = setInterval(()=>{
    if ( !chars.length ){ 
      return clearInterval(interval); 
    }
    text.textContent += chars.shift();
  }, 100 );

});
<input id="input" value="Hello world" />
<p id="text"></p>
<button id="run">Run</button>

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda