truongoi
4/18/2017 - 3:04 AM

Countdown with callback

Countdown with callback

function countdown(time, callback) {
		  var x = setInterval(function() {

		    var days = Math.floor(time / (1000 * 60 * 60 * 24));
		    var hours = Math.floor((time % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
		    var minutes = Math.floor((time % (1000 * 60 * 60)) / (1000 * 60));
		    var seconds = Math.floor((time % (1000 * 60)) / 1000);

		    $('.countdown .day .num').html(days);
		    $('.countdown .hour .num').html(hours);
		    $('.countdown .minute .num').html(minutes);

		    if (time < 0) {
		      clearInterval(x);
		      callback();
		    }

		    time -= 1000;
		  }, 1000);
		}