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

83
Vistas
My requestAnimationFrame function problem from number 482
  • I want to display a counting number from 0 to 2022.
  • I looked up and adapted the code from MDN and from another stack question.
  • My counter goes up to 2026 for an input of 2022, where 2022 is the text content of an HTML element.
  • I tested other inputs and found that the issue starts from the number 482... which outputs +1. Bellow that number, the counter works fine.
  • I think it might be a Math.floor problem, but cannot get it...

Thanks in advance And happy new Year :)

function countNumbers(queryID, time){
    let count = document.getElementById(queryID)
    let finalNumber = parseInt(count.textContent, 10)
    let duration = time
    let start

    const step = timeStamp => {
        if (!start) start = timeStamp

        let progress = (timeStamp - start) / duration 
        count.textContent = Math.floor(progress * finalNumber)

        if (progress < 1) requestAnimationFrame(step) 
    }

    requestAnimationFrame(step)
}
document.onload = countNumbers('count', 2000)
<p>Happy new year <span id="count">2022</span></p>

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