六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 21|回复: 0

count down 倒计时

[复制链接]

升级  80.67%

51

主题

51

主题

51

主题

秀才

Rank: 2

积分
171
 楼主| 发表于 2013-2-7 16:04:04 | 显示全部楼层 |阅读模式
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <title> new document </title>
  <meta name="generator" content="editplus" />
  <meta name="author" content="" />
  <meta name="keywords" content="" />
  <meta name="description" content="" />
</head>

<body>
  <ul>
<li id="day">0</li>
<li id="hour">0</li>
<li id="min">0</li>
<li id="sec">0</li>
<li id="nsec">0</li>
  </ul>
</body>
<script language="JavaScript" type="text/javascript">
<!--
function Timer(opt){
option = opt||{};
this.startDate=option.star||new Date("2011/5/11 07:00:00");
//this.endDate=option.star||new Date("2011/8/6 07:00:00");
                this.endDate=option.end||new Date("2011/8/6 07:00:00");
this.nDay=document.getElementById("day");
this.nHour=document.getElementById("hour");
this.nMin=document.getElementById("min");
this.nSec=document.getElementById("sec");
this.nNsec=document.getElementById("nsec");
this.count();
}
Timer.prototype = {
leftPad: function(num){
if(num.toString().length==1){
return "0"+ num;
}
return num;
}
,count: function(){
var self = this;
var nowDate = new Date();
if(nowDate.getTime()-this.startDate.getTime() > 0){
//way 1. I write
var totalns = this.endDate.getTime() - nowDate.getTime();
var nDayn=Math.floor(totalns/(1000*60*60*24));
var nHourn=Math.floor(totalns%(1000*60*60*24)/(1000*60*60));
//对余数(毫秒数)除以一小时的毫秒数
var nMinn=Math.floor(totalns%(1000*60*60*24)%(1000*60*60)/(1000*60));
//对余数(毫秒数)除以一分钟的毫秒数
var nSecn=Math.floor(totalns%(1000*60*60*24)%(1000*60*60)%(1000*60)/1000);
var nNsecn=Math.floor(totalns%(1000*60*60*24)%(1000*60*60)%(1000*60)%1000);
//way 2. Someone write. good code
/*var nDayn=Math.floor(totalns/(1000*60*60*24));
var nHourn=Math.floor(totalns/(1000*60*60))%24;
//对余数(所有小时)除以24求余
var nMinn=Math.floor(totalns/(1000*60))%60;
var nSecn=Math.floor(totalns/(1000))%60;
var nNsecn=Math.floor(totalns%1000);*/
if(nowDate>0){
this.nDay.innerHTML=nDayn;
this.nHour.innerHTML=nHourn;
this.nMin.innerHTML=nMinn;
this.nSec.innerHTML=nSecn;
this.nNsec.innerHTML=nNsecn;
}
}

setTimeout(function(){self.count();},1);
}
}
new Timer({});
//Timer({})
//-->
</script>
</html>
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表