Jump to content

Need a bit of help with the countdown timer.


imgrooot

Recommended Posts

Here's the code for the countdown timer. It works. At the end of the countdown, it's suppose to show the message "EXPIRED". But that message only shows once I reload the page. The countdown itself stops at 00:00:01. Is there a way to automatically show the message after that, instead of reloading the page to show it?

<style>
  div#counter{
      margin: 100px auto;
      width: 305px;
      padding:20px;
      border:1px solid #000000;
  }
  div#counter span{
      background-color: #00CAF6;
      padding:5px;
      margin:1px;
      font-size:30px;
  }
</style>

<?php 
  $target_date = '2019-01-12 05:40:00';
  $timeLeft = (strtotime($target_date) - time()) * 1000;
?>
<script src="javascripts/timer.js"></script>
<script>
$(document).ready(function(){

      var timeLeft = <?php echo $timeLeft ; ?>;
      var timer =  new Timer($('#counter'), timeLeft);
      
      if (timeLeft <= 0) {
        $('#counter').text('EXPIRED');
      }

});
</script>
<div id="counter">
  <span class="hour">00</span>
  <span class="min">00</span>
  <span class="sec">00</span>
</div>

 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.