Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

195
Vistas
Animate text letter by letter with requestAnimationFrame()

I would like to animate text from the DOM letter by letter using requestAnimationFrame(). I have achieved it with setInterval() and also with requestAnimationFrame() too, but I still can't achieve it to be played for predefined time. For example, on my machine every frame plays for 6ms, but I would like the whole text to be played for example for 5s. So if I have 100symbols each symbol should be added for 50ms and then the other one. Could you please recommend me a solution? Here is my code:

const text = document.getElementById('text');
const textContent = text.innerText;
text.innerHTML = '';
let i = 0;
let totalTime = 2000;
let start;

function animateText(time) {
    if (start === undefined) {
        start = time;
    }

    if(text.innerHTML.length < textContent.length) {
             requestAnimationFrame(animateText);
             text.innerHTML += textContent[i];
             i++;
    }
}

requestAnimationFrame(animateText);
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda