
[英]How to make this countdown timer countdown to a specific date, not just from a time?
[英]How to Make This “Future Date” countdown to “5 Minutes from Now”
我真的为此脚本苦苦挣扎。 这不是我的脚本,而且我显然不是最强的程序员。 我只是想修改此脚本,以代替设置日期:“日,月,年”(第5-8行),它只是获取当前时间,并将倒数计时器设置为从现在开始的xx分钟xx秒。
任何帮助都将是惊人的。 您可以在http://mobisin.com/txtrd/上查看其工作方式(如果需要该文件,也可以下载该页面)。
<script>
var $countdown = $('.ce-countdown');
var firstCalculation = true;
$countdown.countEverest({
day: 30,
month: 6,
year: 2015,
leftHandZeros: true,
afterCalculation: function() {
var plugin = this,
units = {
days: this.days,
hours: this.hours,
minutes: this.minutes,
seconds: this.seconds
},
//max values per unit
maxValues = {
hours: '23',
minutes: '59',
seconds: '59'
},
actClass = 'active',
befClass = 'before';
//build necessary elements
if (firstCalculation == true) {
firstCalculation = false;
//build necessary markup
$countdown.find('.ce-unit-wrap div').each(function () {
var $this = $(this),
className = $this.attr('class'),
value = units[className],
sub = '',
dig = '';
//build markup per unit digit
for(var x = 0; x < 10; x++) {
sub += [
'<div class="digits-inner">',
'<div class="flip-wrap">',
'<div class="up">',
'<div class="shadow"></div>',
'<div class="inn">' + x + '</div>',
'</div>',
'<div class="down">',
'<div class="shadow"></div>',
'<div class="inn">' + x + '</div>',
'</div>',
'</div>',
'</div>'
].join('');
}
//build markup for number
for (var i = 0; i < value.length; i++) {
dig += '<div class="digits">' + sub + '</div>';
}
$this.append(dig);
});
}
//iterate through units
$.each(units, function(unit) {
var digitCount = $countdown.find('.' + unit + ' .digits').length,
maxValueUnit = maxValues[unit],
maxValueDigit,
value = plugin.strPad(this, digitCount, '0');
//iterate through digits of an unit
for (var i = value.length - 1; i >= 0; i--) {
var $digitsWrap = $countdown.find('.' + unit + ' .digits:eq(' + (i) + ')'),
$digits = $digitsWrap.find('div.digits-inner');
//use defined max value for digit or simply 9
if (maxValueUnit) {
maxValueDigit = (maxValueUnit[i] == 0) ? 9 : maxValueUnit[i];
} else {
maxValueDigit = 9;
}
//which numbers get the active and before class
var activeIndex = parseInt(value[i]),
beforeIndex = (activeIndex == maxValueDigit) ? 0 : activeIndex + 1;
//check if value change is needed
if ($digits.eq(beforeIndex).hasClass(actClass)) {
$digits.parent().addClass('play');
}
//remove all classes
$digits
.removeClass(actClass)
.removeClass(befClass);
//set classes
$digits.eq(activeIndex).addClass(actClass);
$digits.eq(beforeIndex).addClass(befClass);
}
});
}
});
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.