gpt4 book ai didi

javascript - 需要帮助对齐 Javascript 倒计时的结果

转载 作者:行者123 更新时间:2023-11-30 06:04:08 25 4
gpt4 key购买 nike

我正在做这个倒计时:http://apps.facebook.com/tjdcountdown/

我想为倒计时的每个结果(分钟、小时、天)添加一个特定的宽度,以便数字始终与下面的文本完美对齐。

是否可以为每个结果创建一个变量并稍后在我的 html 代码中调用它们?

这是倒计时的脚本:

<script type="text/javascript">

var myMonth = "<?= $myMonth ?>";
var myDay = "<?= $myDay ?>";
var myYear = "<?= $myYear ?>";
var myHour = "<?= $myHour ?>";
var myMin = "<?= $myMin ?>";

dateFuture1 = new Date(2013,03,26,14,15,00);

function GetCount(ddate,iid){

dateNow = new Date(); //grab current date
amount = ddate.getTime() - dateNow.getTime(); //calc milliseconds between dates
delete dateNow;

// if time is already past
if(amount < 0){
document.getElementById(iid).innerHTML="I'm now married!";
}
// else date is still good
else{
years=0;weeks=0;days=0;hours=0;mins=0;secs=0;out="";

amount = Math.floor(amount/1000);//kill the "milliseconds" so just secs

years=Math.floor(amount/31536000);//years (no leapyear support)
amount=amount%31536000;

weeks=Math.floor(amount/604800);//weeks
amount=amount%604800;

days=Math.floor(amount/86400);//days
amount=amount%86400;

hours=Math.floor(amount/3600);//hours
amount=amount%3600;

mins=Math.floor(amount/60);//minutes
amount=amount%60;

secs=Math.floor(amount);//seconds

out += years +""+((years==1)?"":"")+"";
out += weeks +""+((weeks==1)?"":"")+"";
if(days != 0){out += days +""+((days==1)?"":"")+"";}
if(hours != 0){out += hours +""+((hours==1)?"":"")+"";}
out += mins +""+((mins==1)?"":"")+"";
out += secs +""+((secs==1)?"":"")+", ";
out = out.substr(0,out.length-2);
document.getElementById(iid).innerHTML=out;
setTimeout(function(){GetCount(ddate,iid)}, 1000);
}
}

window.onload=function(){
GetCount(dateFuture1, 'countbox1');
//you can add additional countdowns here (just make sure you create dateFuture2 and countbox2 etc for each)
};
</script>

非常感谢您的帮助!

最佳答案

是的,你可以做到这一切。将每个数字放在其自己的 div 中,并将文本居中放置在每个 div 中。无需编码即可确保文本居中。

现在的主要问题是,当所有数字(年、周、日、小时等)需要分开到它们自己的 div 中时,它们都被压缩到一个 div(iid 又名“countbox1”)中。

关于javascript - 需要帮助对齐 Javascript 倒计时的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6191256/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com