我使用一個jQuery倒計時腳本,我在YouTube上找到的教程,但我想改變一些因素:jQuery的倒計時隱藏小時沒有離開小時
我想隱藏日,分鐘等,如果有都不剩(即達到0)。
此時會顯示類似..
00天00小時13分58秒
我想要顯示它像..
13分58秒
這就是我正在使用的:
個countdown.js
(function($){
$.fn.countdown = function(options, callback){
var settings = { 'date': null };
if(options){
$.extend(settings, options);
};
this_sel = $(this);
function count_exec() {
eventDate = Date.parse(settings['date'])/1000;
currentDate = Math.floor($.now()/1000);
if(eventDate <= currentDate){
callback.call(this);
clearInterval(interval);
}
seconds = eventDate - currentDate;
days = Math.floor(seconds/(60 * 60 * 24));
seconds -= days * 60 * 60 * 24;
hours = Math.floor(seconds/(60 * 60));
seconds -= hours * 60 * 60;
minutes = Math.floor(seconds/60);
seconds -= minutes * 60;
days = (String(days).length !== 2) ? '0' + days : days;
hours = (String(hours).length !== 2) ? '0' + hours : hours;
minutes = (String(minutes).length !== 2) ? '0' + minutes : minutes;
seconds = (String(seconds).length !== 2) ? '0' + seconds : seconds;
if(!isNaN(eventDate)){
this_sel.find('.days').text(days);
this_sel.find('.hours').text(hours);
this_sel.find('.minutes').text(minutes);
this_sel.find('.seconds').text(seconds);
}
}
count_exec();
interval = setInterval(count_exec, 1000);
}
})(jQuery);
HTML
<span class="days">00</span> Days
<span class="hours">00</span> Hours
<span class="minutes">00</span> Minutes
<span class="seconds">00</span> Seconds
運行
<script>
$(document).ready(function(){
$('#item-1').countdown({ date: '30 July 2015 12:00:00' }, function() {
$('#item-1').text('Finished');
$.ajax({
url: "/ajax",
type: "GET",
data: { 'id' : 1 }
});
window.setTimeout(function(){location.reload()},3000);
});
});
</script>
謝謝!
感謝隊友!有用!然而這個班是不同的:p days_show和show_days。 Thankes再次交配,節省生活! :) – TiagoF
樂意幫助你的抱歉:再次P – squiroid
謝謝! <3 – TiagoF