从倒计时中删除Min和Sec

时间:2013-05-08 09:20:18

标签: joomla countdown min

我想从我的倒计时中移除分钟和秒并添加几个月......如何做到这一点???

http://techcongress.net/demo/

CSS: http://techcongress.net/demo/modules/mod_sp_countdown/assets/css/sp_countdown.css

1 个答案:

答案 0 :(得分:0)

这就是javascript在倒计时:

    <script type="text/javascript">
//<![CDATA[
window.addEvent('domready', function() {
function calcage(secs, num1, num2, starthtml, endhtml, singular, plural) {
s = ((Math.floor(secs/num1))%num2).toString();
z = ((Math.floor(secs/num1))%num2);
if (LeadingZero && s.length < 2)
{
s = "0" + s;
}
return starthtml
+ '<div class="sp_countdown_int"> '
+ s + '</div>'
+ '<div class="sp_countdown_string"> '
+ ((z<=1)?singular:plural)
+ '</div>'
+ endhtml;
}
function CountBack(secs) {
if (secs < 0) {
document.getElementById("sp_countdown_cntdwn144").innerHTML = '<div class="sp_countdown_finishtext">'+FinishMessage+'</div>';
return;
}
DisplayStr = DisplayFormat.replace(/%%D%%/g, calcage(secs,86400,100000,
'<div class="sp_countdown_days">','</div>',' Day', ' Days'));
DisplayStr = DisplayStr.replace(/%%H%%/g, calcage(secs,3600,24,
'<div class="sp_countdown_hours">','</div>',' Hr', ' Hrs'));
DisplayStr = DisplayStr.replace(/%%M%%/g, calcage(secs,60,60,
'<div class="sp_countdown_mins">','</div>', ' Min', ' Mins'));
DisplayStr = DisplayStr.replace(/%%S%%/g, calcage(secs,1,60,
'<div class="sp_countdown_secs">','</div>', ' Sec', " Secs"));
document.getElementById("sp_countdown_cntdwn144").innerHTML = DisplayStr;
if (CountActive)
setTimeout(function(){
CountBack((secs+CountStepper))
}, SetTimeOutPeriod);
}
function putspan(backcolor, forecolor) {
}
if (typeof(BackColor)=="undefined")
BackColor = "";
if (typeof(ForeColor)=="undefined")
ForeColor= "";
if (typeof(TargetDate)=="undefined")
TargetDate = "07/24/2013 12:00 AM";
if (typeof(DisplayFormat)=="undefined")
DisplayFormat = "%%D%% %%H%% %%M%% %%S%% ";
if (typeof(CountActive)=="undefined")
CountActive = true;
if (typeof(FinishMessage)=="undefined")
FinishMessage = "Finally we are here";
if (typeof(CountStepper)!="number")
CountStepper = -1;
if (typeof(LeadingZero)=="undefined")
LeadingZero = true;
CountStepper = Math.ceil(CountStepper);
if (CountStepper == 0)
CountActive = false;
var SetTimeOutPeriod = (Math.abs(CountStepper)-1)*1000 + 990;
putspan(BackColor, ForeColor);
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);
});
//]]>
</script> 

编辑它以满足您的需求,包括计算一个月的秒数

DisplayStr = DisplayFormat.replace(/%%MN%%/g, calcage(secs,2592000,12,
'<div class="sp_countdown_months">','</div>',' Month', ' Months'));
DisplayStr = DisplayFormat.replace(/%%D%%/g, calcage(secs,86400,30,
'<div class="sp_countdown_days">','</div>',' Day', ' Days'));

添加月份并删除分钟和秒

 DisplayFormat = "%%MN%% %%D%% %%H%%";

你看到你得到的问题是一个月内30到31天之间的切换(没有成本)所以脚本需要更好的计算,才能让月份正确...

希望这有帮助,如果不是,我们都需要学习更多关于javaScript的内容;)