Javascript 倒计时计时器-从天到小时
我使用了这个网站上的倒计时: 我该如何从天到小时显示时间?类型:2天48小时节目-3天72小时表演 这是js代码Javascript 倒计时计时器-从天到小时,javascript,countdown,Javascript,Countdown,我使用了这个网站上的倒计时: 我该如何从天到小时显示时间?类型:2天48小时节目-3天72小时表演 这是js代码 /*gpl stuff*/ (function($){ $.fn.countDown = function (options) { config = {}; $.extend(config, options); diffSecs = this.setCountDown(config); if (conf
/*gpl stuff*/
(function($){
$.fn.countDown = function (options) {
config = {};
$.extend(config, options);
diffSecs = this.setCountDown(config);
if (config.onComplete)
{
$.data($(this)[0], 'callback', config.onComplete);
}
if (config.omitWeeks)
{
$.data($(this)[0], 'omitWeeks', config.omitWeeks);
}
$('#' + $(this).attr('id') + ' .digit').html('<div class="top"></div><div class="bottom"></div>');
$(this).doCountDown($(this).attr('id'), diffSecs, 500);
return this;
};
$.fn.stopCountDown = function () {
clearTimeout($.data(this[0], 'timer'));
};
$.fn.startCountDown = function () {
this.doCountDown($(this).attr('id'),$.data(this[0], 'diffSecs'), 500);
};
$.fn.setCountDown = function (options) {
var targetTime = new Date();
if (options.targetDate)
{
targetTime = new Date(options.targetDate.month + '/' + options.targetDate.day + '/' + options.targetDate.year + ' ' + options.targetDate.hour + ':' + options.targetDate.min + ':' + options.targetDate.sec + (options.targetDate.utc ? ' UTC' : ''));
}
else if (options.targetOffset)
{
targetTime.setFullYear(options.targetOffset.year + targetTime.getFullYear());
targetTime.setMonth(options.targetOffset.month + targetTime.getMonth());
targetTime.setDate(options.targetOffset.day + targetTime.getDate());
targetTime.setHours(options.targetOffset.hour + targetTime.getHours());
targetTime.setMinutes(options.targetOffset.min + targetTime.getMinutes());
targetTime.setSeconds(options.targetOffset.sec + targetTime.getSeconds());
}
var nowTime = new Date();
diffSecs = Math.floor((targetTime.valueOf()-nowTime.valueOf())/1000);
$.data(this[0], 'diffSecs', diffSecs);
return diffSecs;
};
$.fn.doCountDown = function (id, diffSecs, duration) {
$this = $('#' + id);
if (diffSecs <= 0)
{
diffSecs = 0;
if ($.data($this[0], 'timer'))
{
clearTimeout($.data($this[0], 'timer'));
}
}
secs = diffSecs % 60;
mins = Math.floor(diffSecs/60)%60;
hours = Math.floor(diffSecs/60/60)%24;
if ($.data($this[0], 'omitWeeks') == true)
{
days = Math.floor(diffSecs/60/60/24);
weeks = Math.floor(diffSecs/60/60/24/7);
}
else
{
days = Math.floor(diffSecs/60/60/24)%7;
weeks = Math.floor(diffSecs/60/60/24/7);
}
$this.dashChangeTo(id, 'seconds_dash', secs, duration ? duration : 800);
$this.dashChangeTo(id, 'minutes_dash', mins, duration ? duration : 1200);
$this.dashChangeTo(id, 'hours_dash', hours, duration ? duration : 1200);
$this.dashChangeTo(id, 'days_dash', days, duration ? duration : 1200);
$this.dashChangeTo(id, 'weeks_dash', weeks, duration ? duration : 1200);
$.data($this[0], 'diffSecs', diffSecs);
if (diffSecs > 0)
{
e = $this;
t = setTimeout(function() { e.doCountDown(id, diffSecs-1) } , 1000);
$.data(e[0], 'timer', t);
}
else if (cb = $.data($this[0], 'callback'))
{
$.data($this[0], 'callback')();
}
};
$.fn.dashChangeTo = function(id, dash, n, duration) {
$this = $('#' + id);
for (var i=($this.find('.' + dash + ' .digit').length-1); i>=0; i--)
{
var d = n%10;
n = (n - d) / 10;
$this.digitChangeTo('#' + $this.attr('id') + ' .' + dash + ' .digit:eq('+i+')', d, duration);
}
};
$.fn.digitChangeTo = function (digit, n, duration) {
if (!duration)
{
duration = 800;
}
if ($(digit + ' div.top').html() != n + '')
{
$(digit + ' div.top').css({'display': 'none'});
$(digit + ' div.top').html((n ? n : '0')).slideDown(duration);
$(digit + ' div.bottom').animate({'height': ''}, duration, function() {
$(digit + ' div.bottom').html($(digit + ' div.top').html());
$(digit + ' div.bottom').css({'display': 'block', 'height': ''});
$(digit + ' div.top').hide().slideUp(10);
});
}
};
})(jQuery);
/*gpl的东西*/
(函数($){
$.fn.countDown=函数(选项){
config={};
$.extend(配置,选项);
diffSecs=this.setCountDown(配置);
if(config.onComplete)
{
$.data($(this)[0],'callback',config.onComplete);
}
如果(config.com)
{
$.data($(this)[0],'omit weeks',config.omit weeks);
}
$('#'+$(this.attr('id')+'.digit')).html('');
$(this).doCountDown($(this).attr('id'),diffSecs,500);
归还这个;
};
$.fn.stopCountDown=函数(){
clearTimeout($.data(此[0],“计时器”);
};
$.fn.startCountDown=函数(){
this.doCountDown($(this.attr('id'),$.data(this[0],'diffSecs'),500);
};
$.fn.setCountDown=函数(选项){
var targetTime=新日期();
如果(选项。目标日期)
{
targetTime=新日期(options.targetDate.month+'/'+options.targetDate.day+'/'+options.targetDate.year+'+options.targetDate.hour+':'+options.targetDate.min+':'+options.targetDate.sec+(options.targetDate.utc?'utc:'');
}
else if(options.targetOffset)
{
targetTime.setFullYear(options.targetOffset.year+targetTime.getFullYear());
targetTime.setMonth(options.targetOffset.month+targetTime.getMonth());
targetTime.setDate(options.targetOffset.day+targetTime.getDate());
targetTime.setHours(options.targetOffset.hour+targetTime.getHours());
targetTime.setMinutes(options.targetOffset.min+targetTime.getMinutes());
targetTime.setSeconds(options.targetOffset.sec+targetTime.getSeconds());
}
var nowTime=新日期();
diffSecs=Math.floor((targetTime.valueOf()-nowTime.valueOf())/1000);
$.data(此[0],'diffSecs',diffSecs);
返回差秒;
};
$.fn.doCountDown=函数(id、diffSecs、持续时间){
$this=$(“#”+id);
if(diffSecs 0)
{
e=这一美元;
t=setTimeout(函数(){e.doCountDown(id,diffSecs-1)},1000);
$.data(e[0],'timer',t);
}
else if(cb=$.data($this[0],'callback'))
{
$.data($this[0],'callback')();
}
};
$.fn.dashChangeTo=函数(id、破折号、n、持续时间){
$this=$(“#”+id);
对于(变量i=($this.find('.+dash+'.digit')).length-1);i>=0;i--)
{
var d=n%10;
n=(n-d)/10;
$this.digitChangeTo('#'+$this.attr('id')+'.+dash+'.数字:eq('+i++'),d,持续时间);
}
};
$.fn.digitChangeTo=函数(数字,n,持续时间){
如果(!持续时间)
{
持续时间=800;
}
如果($(数字+'div.top').html()!=n+“”)
{
$(数字+'div.top').css({'display':'none'});
$(数字+'div.top').html((n?n:'0')).slideDown(持续时间);
$(数字+'div.bottom')。动画({'height':''},持续时间,函数(){
$(digit+'div.bottom').html($(digit+'div.top').html());
$(数字+'div.bottom').css({'display':'block','height':''});
$(数字+div.top').hide().slideUp(10);
});
}
};
})(jQuery);
只需在HTML代码中隐藏您不需要的内容。就这么简单
<div id="countdown_dashboard">
<div class="dash minutes_dash">
<span class="dash_title"></span>
<div class="digit">0</div>
<div class="digit">0</div>
</div>
<div class="dash seconds_dash">
<span class="dash_title"></span>
<div class="digit">0</div>
<div class="digit">0</div>
</div>
</div>
0
0
0
0
你想要什么?你想只在几个小时内显示倒计时吗?如中所示,永远不要显示其演示所显示的周或日计数器?嗨,帕特里克-是的。我只需要小时分秒。