😂Code countdown tự động lặp lại giúp chốt sale

https://webantam.com/code-countdown-tu-dong-lap-lai/?fbclid=IwAR07GCnQheUbvSpBG3wfUZRyt2rAR_z_EaZwAzvQ16iWNjfa4E8vwu7vghg

Vừa rồi khách hàng của mình yêu cầu code countdown tự động lặp lại sau 24h, không cần vào set lại thời gian mà nó sẽ tự động lặp lại thời gian sau khi hết 24h, mình thấy hay quá nên share cho anh em luôn

<!-- code countdown webantam.com share -->
<style>
p#demo {
    text-align: center;
    font-size: 20px;
    margin-top: 0px;
    border-style: none;
    background: #f7cb16;
    border-radius: 10px;
    padding: 20px 20px 20px 20px;
    display: block !important;
    font-weight: normal;
    box-shadow: rgb(0 0 0 / 40%) 0 5px 10px;
}
</style>
<p id="demo"></p>
<script>
function startCountdown() {
  // Set the date we're counting down to
  var countDownDate = new Date();
  countDownDate.setDate(countDownDate.getDate() + 1); // Set the countdown to 24 hours later from now
  countDownDate.setHours(14, 41, 25); // Set the time to 18:39:25

  // Update the count down every 1 second
  var x = setInterval(function() {

    // Get today's date and time
    var now = new Date().getTime();
      
    // Find the distance between now and the count down date
    var distance = countDownDate - now;
      
    // Time calculations for days, hours, minutes and seconds
    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);
      
    // Output the result in an element with id="demo"
    document.getElementById("demo").innerHTML =  hours + "h "
    + minutes + "m " + seconds + "s ";
      
    // If the count down is over, start a new countdown after 24 hours
    if (distance < 0) {
      clearInterval(x);
      document.getElementById("demo").innerHTML = "EXPIRED";

      // Start a new countdown after 24 hours
      startCountdown();
    }
  }, 1000);
}

// Start the initial countdown
startCountdown();
</script>

Last updated