10 examples of '30 minutes countdown timer in javascript' in JavaScript

Every line of '30 minutes countdown timer in javascript' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
1(function countdown(remaining) {
2 if(remaining === 0)
3 location.reload(true);
4 else {
5 document.getElementById('countdown').innerHTML = 'Refresh in: ' + remaining + ' sec';
6 setTimeout(function(){ countdown(remaining - 1); }, 1000);
7 }
8})(120);
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

247function countdown(sec, eid) {
248 document.getElementById(eid).innerHTML = sec;
249 if (sec > 0) {
250 setTimeout("countdown("+(sec-1)+", '"+eid+"')", 1000);
251 } else {
252 forwardto('index.tmpl')
253 }
254}
30function Countdown_CountBack(secs) {
31 if (secs < 0) {
32 document.getElementById("Countdown_cntdwn").innerHTML = Countdown_FinishMessage;
33 return;
34 }
35 DisplayStr = Countdown_DisplayFormat.replace(/%%D%%/g, Countdown_calcage(secs,86400,100000));
36 DisplayStr = DisplayStr.replace(/%%H%%/g, Countdown_calcage(secs,3600,24));
37 DisplayStr = DisplayStr.replace(/%%M%%/g, Countdown_calcage(secs,60,60));
38 DisplayStr = DisplayStr.replace(/%%S%%/g, Countdown_calcage(secs,1,60));
39
40 document.getElementById("Countdown_cntdwn").innerHTML = DisplayStr;
41 if (Countdown_CountActive)
42 setTimeout("Countdown_CountBack(" + (secs+Countdown_CountStepper) + ")", Countdown_SetTimeOutPeriod);
43}
6function countdownTick(ms) {
7 if (ms < 0) return;
8 console.log('sleep', ms);
9 setTimeout(() => countdownTick(ms - 1000), 1000);
10}
157function countDown(){
158 var remainSeconds = $("#remainSeconds").val();
159 var timeout;
160 if(remainSeconds > 0){//秒杀还没开始,倒计时
161 $("#buyButton").attr("disabled", true);
162 timeout = setTimeout(function(){
163 $("#countDown").text(remainSeconds - 1);
164 $("#remainSeconds").val(remainSeconds - 1);
165 countDown();
166 },1000);
167 }else if(remainSeconds == 0){//秒杀进行中
168 $("#buyButton").attr("disabled", false);
169 if(timeout){
170 clearTimeout(timeout);
171 }
172 $("#miaoshaTip").html("秒杀进行中");
173 // $("#verifyCodeImg").attr("src", "/miaosha/verifyCode");
174 flushVerifyCodeImg();
175 $("#verifyCodeImg").show();
176 $("#verifyCode").show();
177
178 }else{//秒杀已经结束
179 $("#buyButton").attr("disabled", true);
180 $("#miaoshaTip").html("秒杀已经结束");
181 $("#verifyCodeImg").hide();
182 $("#verifyCode").hide();
183 }
184}
219function countDown() {
220 var remainSeconds = $("#remainSeconds").val();
221 var timeout;
222 if (remainSeconds > 0) {//秒杀还没开始,倒计时
223 $("#buyButton").attr("disabled", true);
224 $("#miaoshaTip").html("秒杀倒计时:" + remainSeconds + "秒");
225 timeout = setTimeout(function () {
226 $("#countDown").text(remainSeconds - 1);
227 $("#remainSeconds").val(remainSeconds - 1);
228 countDown();
229 }, 1000);
230 } else if (remainSeconds == 0) {//秒杀进行中
231 $("#buyButton").attr("disabled", false);
232 if (timeout) {
233 clearTimeout(timeout);
234 }
235 $("#miaoshaTip").html("秒杀进行中");
236 $("#verifyCodeImg").attr("src", "/miaosha/verifyCode?goodsId=" + $("#goodsId").val());
237 $("#verifyCodeImg").show();
238 $("#verifyCode").show();
239 } else {//秒杀已经结束
240 $("#buyButton").attr("disabled", true);
241 $("#miaoshaTip").html("秒杀已经结束");
242 $("#verifyCodeImg").hide();
243 $("#verifyCode").hide();
244 }
245}
6function startCountdown(itemID)
7{
8 counting = true;
9 count = 10;
10 updateCountdown(itemID)
11}
553start ({ onComplete, onTick }) {
554 this.onCompleteCallback = onComplete
555 this.onTickCallback = onTick
556
557 this.counter = 3
558 clearTimeout(this.timer)
559 this._onTick()
560}
9start() {
10 if (this.running) {
11 return;
12 }
13 this.running = true;
14 var tickerFn = () => {
15 let diff = this.duration - (Date.now() - this.start);
16 if (diff > 0) {
17 setTimeout(tickerFn, this.granularity);
18 } else {
19 diff = 0;
20 this.running = false;
21 }
22 this.tickFns.forEach((fn) => {
23 fn(diff);
24 });
25 }
26 this.start = Date.now();
27 tickerFn();
28}
48function update_timer(seconds_left)
49{
50 seconds_left -= 1;
51
52 if (seconds_left <= 0) {
53 window.location.reload(false);
54 }
55 else {
56 // update the pause counter
57 var counter = document.getElementById("reload_pause_counter");
58 if (counter) {
59 counter.innerHTML = seconds_left;
60 }
61
62 g_reload_pause_timer = setTimeout(function() {
63 update_timer(seconds_left);
64 }, 1000);
65 }
66}

Related snippets