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

269
Views
Temporizador de cuenta regresiva de Javascript puro (Vanilla.js)

Tengo las siguientes dos funciones:

 // COUNTDOWN TIMER FUNCTION function refillTimer(theTime) { var timer = new Date().getTime() + theTime; $('#refillTimer').countdown(timer).on('update.countdown', function(event) { $(this).show(); var $this = $(this); if(event.elapsed){ $this.html(event.strftime('0:0:0')); }else{ $this.html(event.strftime('<strong>%S</strong>')); } }).on('finish.countdown', function(){ $(this).hide(); }); } // ON SWIPE PERFORM ACTION async function swipeAction(currentElementObj, swipeType) { var cardId = currentElementObj.getAttribute("value"); var dataString = { card: cardId, swipe: swipeType }; let response = await new Promise((resolve, reject) => { try { var xhr = new XMLHttpRequest(); xhr.open("POST", "processes/swipe.php", true); xhr.setRequestHeader("Content-Type", "application/json"); xhr.responseType = "json"; xhr.send(JSON.stringify(dataString)); xhr.onreadystatechange = function () { let resObj = xhr.response; if(xhr.readyState == 4 && xhr.status == 200 && resObj) { $('#content').modal('show'); refillTimer(resObj.nextswipe); // resObj.nextswipe returns 37000 seconds } }; }catch(e){ reject(e.toString()); } }); }

Aquí, en el código anterior, como puede ver, tengo un temporizador de cuenta regresiva que estoy tratando de usar en la función swipeAction() . El problema aquí es que el temporizador no funciona según la entrada proporcionada. Digamos, por ejemplo, que la entrada pasada en la refilTImer(theTime) como theTime es 37000. Por lo tanto, la función debe tomar 37000 segundos, convertirla a HH:MM:SS e iniciar la visualización de la cuenta regresiva en consecuencia. Simple como eso. Sin embargo, en cada llamada, el temporizador de cuenta regresiva comienza a los 37 segundos. Los segundos pasaron 43650, el temporizador cuenta regresivamente desde 43 segundos solamente. No entiendo por qué sucede esto. ¿Cuál puede ser la solución aquí?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Estás pasando milisegundos , no segundos.


Mirando la definición de la función que estás usando:

obtenerHora() MDN

numero de milisegundos ...

y una suposición de su complemento como The Final Countdown

fecha final

La fecha objetivo en la que desea realizar la cuenta regresiva. Este argumento puede ser uno de los siguientes:

  • Un objeto de fecha nativo
  • Los milisegundos del tiempo de Epoch
  • Cadena formateada

muestra que pasar 37000 es 37000 milisegundos , por lo que 37 segundos.

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!