function calcage(secs, num1, num2) { s = ((Math.floor(secs/num1))%num2).toString(); if (LeadingZero && s.length < 2) s = "0" + s; return s; } function CountBack(secs, SetTimeOutPeriod, DisplayFormat, CountActive, CountStepper) { if (secs < 100) { var new_date = new Date(); $.cookie('target_date', new_date.setDate(new_date.getDate() + 3)); //document.getElementById("clockJS").innerHTML = FinishMessage; return; } DisplayStr = DisplayFormat.replace(/%%D%%/g, calcage(secs,86400,100000)); DisplayStr = DisplayStr.replace(/%%H%%/g, calcage(secs,3600,24)); DisplayStr = DisplayStr.replace(/%%M%%/g, calcage(secs,60,60)); DisplayStr = DisplayStr.replace(/%%S%%/g, calcage(secs,1,60)); document.getElementById("clockJS").innerHTML = DisplayStr; if (CountActive) setTimeout($.proxy(CountBack, this, (secs+CountStepper), SetTimeOutPeriod, DisplayFormat, CountActive, CountStepper), "CountBack(" + (secs+CountStepper) + ", " + SetTimeOutPeriod + ", " + DisplayFormat + ", " + CountActive + ", " + CountStepper + ")", SetTimeOutPeriod); } $(function(){ if($.cookie('target_date')) { TargetDate = parseInt($.cookie('target_date')); } else { TargetDate = new Date(); $.cookie('target_date', TargetDate); } CountActive = true; CountStepper = -1; LeadingZero = true; DisplayFormat = "<span class='countdown_schet'><span class='countdown_schet-d'>%%D%%</span><span class='countdown_schet-h'>%%H%%</span><span class='countdown_schet-m'>%%M%%</span></span>"; FinishMessage = "Time's Up"; CountStepper = Math.ceil(CountStepper); if (CountStepper == 0) CountActive = false; var SetTimeOutPeriod = (Math.abs(CountStepper)-1)*1000 + 990; var dthen = new Date(TargetDate); var dnow = new Date(); if(CountStepper>0) ddiff = new Date(dnow-dthen); else ddiff = new Date(dthen-dnow); gsecs = Math.floor(ddiff.valueOf()/1000); CountBack(gsecs, SetTimeOutPeriod, DisplayFormat, CountActive, CountStepper); });
на следующий
function calcage(secs, num1, num2) { s = ((Math.floor(secs/num1))%num2).toString(); if (LeadingZero && s.length < 2) s = "0" + s; return s; } function CountBack(secs) { if (secs < 100) { var new_date = new Date(); $.cookie('target_date', new_date.setDate(new_date.getDate() + 3)); document.getElementById("clockJS").innerHTML = FinishMessage; return; } DisplayStr = DisplayFormat.replace(/%%D%%/g, calcage(secs,86400,100000)); DisplayStr = DisplayStr.replace(/%%H%%/g, calcage(secs,3600,24)); DisplayStr = DisplayStr.replace(/%%M%%/g, calcage(secs,60,60)); DisplayStr = DisplayStr.replace(/%%S%%/g, calcage(secs,1,60)); document.getElementById("clockJS").innerHTML = DisplayStr; if (CountActive) setTimeout($.proxy(CountBack, this, (secs+CountStepper)), SetTimeOutPeriod); } $(function(){ if($.cookie('target_date')) { TargetDate = parseInt($.cookie('target_date')); } else { TargetDate = new Date(); $.cookie('target_date', TargetDate); } CountActive = true; CountStepper = -1; LeadingZero = true; DisplayFormat = "<span class='countdown_schet'><span class='countdown_schet-d countdown-%%D%%'>%%D%%</span><span class='countdown_schet-h countdown-%%H%%'>%%H%%</span><span class='countdown_schet-m countdown-%%M%%'>%%M%%</span></span>"; FinishMessage = "<span class='countdown_schet-finish'>Time's Up</span>"; CountStepper = Math.ceil(CountStepper); if (CountStepper == 0) CountActive = false; SetTimeOutPeriod = (Math.abs(CountStepper)-1)*1000 + 990; var dthen = new Date(TargetDate); var dnow = new Date(); if(CountStepper>0) ddiff = new Date(dnow-dthen); else ddiff = new Date(dthen-dnow); gsecs = Math.floor(ddiff.valueOf()/1000); CountBack(gsecs); });
Изначально данный код не был предназначен для отображения графического счетчика, а только числового. В отображении DisplayFormat мы задали дополнительные классы которые можно будет простилизовать для графического отображения. Для начала сделайте предложенные изменения, а после уже будем стилизовать цифры.