簡體   English   中英

我想每 30 分鍾倒計時一次,怎么做?

[英]I want to run the countdown every 30 minutes, how can that be done?

我想在下面的代碼中每 30 分鍾運行一次倒計時,倒計時應該每 30 分鍾運行一次。

function createCountDown(elementId, sec) {
        var tms = sec;
        var x = setInterval(function() {
            var distance = tms*1000;
            var days = Math.floor(distance / (1000 * 60 * 60 * 24));
            var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
            var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
            var seconds = Math.floor((distance % (1000 * 60)) / 1000);
            document.getElementById(elementId).innerHTML =days+"d: "+ hours + "h "+ minutes + "m " + seconds + "s ";
            if (distance < 0) {
                clearInterval(x);
                document.getElementById(elementId).innerHTML = "{{__('COMPLETE')}}";
            }
            tms--;
        }, 1000);
    }
  createCountDown('counter', {{\Carbon\Carbon::tomorrow()->diffInSeconds()}});
  }
}
};

您可以使用setInterval()

setInterval(function () {
   // Run your countdown script
   ....
}, 1800000)

// 1800000 // miliseconds = 30 minutes

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM