Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

179
Views
Cuente hasta números superiores a mil millones en unos pocos segundos sin que el navegador se congele

Estoy tratando de hacer un contador que cuente números grandes como 6 mil millones ( como el generador de números aleatorios de Google ), pero el navegador se congela.

 var counter = document.querySelector("#blahblahblah"); var nb = 0; var ne = 6_000_000_000; for (;nb<=ne;nb++) { counter.innerHTML = nb; };
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Lo mejor que puedes hacer es usar requestAnimationFrame . Esto representa la velocidad más rápida a la que puede actualizar el DOM.

Use la devolución de llamada para actualizar el texto de su elemento al número proporcional al tiempo permitido; 3 segundos ( algunos ) del título de su pregunta

 const runCounter = (num, timeout, el) => { let start; const step = (ts) => { if (!start) { start = ts; // record the first iteration timestamp } const progress = (ts - start) / timeout; // how far into the time span if (progress < 1) { el.textContent = Math.floor(num * progress); requestAnimationFrame(step); // request the next frame } else { el.textContent = num; // finish } }; requestAnimationFrame(step); }; runCounter(6_000_000_000, 3000, document.getElementById("blahblahblah"));
 <output id="blahblahblah">0</output>

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!