jQuery.countdown icon indicating copy to clipboard operation
jQuery.countdown copied to clipboard

Remove Days when timer hits 00

Open itsabhik opened this issue 6 years ago • 3 comments

Hi, Not sure if this is the proper place to get help.

I want to remove the count section (such as Weeks, Days) when the respective timer hits 0. Current setup shows 00 Weeks 00 Days 23 Hours 59 Minutes 59 Seconds, however, I need it to show only 23 Hours 59 Minutes 59 Seconds. Hows this possible?

itsabhik avatar May 12 '18 10:05 itsabhik

#287

devrck avatar Oct 19 '18 11:10 devrck

This is what I have and It will remove each one of them if they are equal to 0:

$('#clock').countdown('2020/11/02 23:48')
	.on('update.countdown', function(event) {
	var format = '<span>%-d</span> day%!d '
		+ '<span>%H</span> hr '
		+ '<span>%M</span> min '
		+ '<span>%S</span> sec';
	if(event.offset.totalDays === 0) {
		format = '<span>%H</span> hr '
		+ '<span>%M</span> min '
		+ '<span>%S</span> sec';
	} 
	if(event.offset.totalHours === 0) {
		format = 
		'<span>%M</span> min '
		+ '<span>%S</span> sec';
	}
	if(event.offset.totalMinutes === 0) {
		format = '<span>%S</span> sec';
	}
	if(event.offset.totalSeconds === 0) {
		format = '';
	}
  $(this).html(event.strftime(format));
});

costheme avatar Sep 01 '20 21:09 costheme

@costheme it is working fine. but, just one issue. It is stop on 01sec when end of last second in last minute. So, it does not hide. why it does not 00 sec? For example: 01s Below my code with use your code:

var countdown = $('.countdown[data-countdown-end]');
if (countdown.length > 0) {
	countdown.each(function() {
		var $countdown = $(this),
			finalDate = $countdown.data('countdown-end');
		$countdown.countdown(finalDate)
			.on('update.countdown', function(event) {
			  var format = '<span>%-d</span> day%!d '
				  + '<span>%H</span> hr '
				  + '<span>%M</span> min '
				  + '<span>%S</span> sec';
			  if(event.offset.totalDays === 0) {
				  format = '<span>%H</span> hr '
				  + '<span>%M</span> min '
				  + '<span>%S</span> sec';
			  } 
			  if(event.offset.totalHours === 0) {
				  format = 
				  '<span>%M</span> min '
				  + '<span>%S</span> sec';
			  }
			  if(event.offset.totalMinutes === 0) {
				  format = '<span>%S</span> sec';
			  }
			  if(event.offset.totalSeconds === 0) {
				  format = '';
			  }
			$countdown.html(event.strftime(format));
	});	
});
}

if, I have used my old code. So, It is stop on 00sec when end of last second in last minute. For example: 00d 00h 00m 00s

var countdown = $('.countdown[data-countdown-end]');
if (countdown.length > 0) {
	countdown.each(function() {
		var $countdown = $(this),
			finalDate = $countdown.data('countdown-end');
		$countdown.countdown(finalDate, function(event) {
			$countdown.html(event.strftime(
				'%Dd %Hh %Mm %Ss'
			));
		});
	});
}

Why it does not 00 sec with your code? can you please help.

harnishdesign avatar Jan 20 '22 12:01 harnishdesign