매시간 00 분에 시작하고 10 분에 끝나야하는 카운트 다운 타이머를 보여주는 다음 JS 코드가 있습니다.
@php
$dt = date('Y/m/d H:i:s');
@endphp
<script>
var countDownDate = new Date("Jan 5, 2100 23:10:00").getTime();
var now = new Date("<?php echo $dt; ?>").getTime();
var x = setInterval(function() {
now+= 1000
var distance = countDownDate - now;
var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
var seconds = Math.floor((distance % (1000 * 60)) / 1000);
document.getElementById("timer10").innerHTML =
minutes + "m " + seconds + "s ";
}, 1000);
00:00에 멈추지 않고 59:59부터 다시 시작하는 타이머를 재설정하는 것을 제외하고는 정상적으로 작동합니다. 00:00에 타이머를 중지하려면 무엇을 추가해야합니까?
간격을 지우지 않습니다. clearInterval
함수 를 호출해야 합니다.
@php
$dt = date('Y/m/d H:i:s');
@endphp
<script>
var countDownDate = new Date("Jan 5, 2100 23:10:00").getTime();
var now = new Date("<?php echo $dt; ?>").getTime();
var x = setInterval(function() {
now+= 1000
var distance = countDownDate - now;
var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
var seconds = Math.floor((distance % (1000 * 60)) / 1000);
document.getElementById("timer10").innerHTML =
minutes + "m " + seconds + "s ";
if(minutes === 0 && seconds === 0) {
clearInterval(x);
// the interval will stop at this point.
}
}, 1000);
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다