倒计时JS代码,简洁实用,大气。

<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="initial-scale=1.0,user-scalable=0">
<title>JS和jQuery倒计时插件</title>
<style type="text/css">
*{margin: 0;padding: 0;font-family: 'Microsoft YaHei','Lantinghei SC','Open Sans',Arial,'Hiragino Sans GB','STHeiti','WenQuanYi Micro Hei','SimSun',sans-serif;}
div{
	float:left;
	width: auto;
	height: 100px;
	background: #0c2345;
	font-size: 60px;
	color: #fff;
	line-height: 100px;
	text-align: center;
	font-weight: 500;
	border-radius: 5px;
	margin-right: 10px;
	padding-left:20px;
	padding-right:20px;
}
</style>
</head>

<body style="padding:30px">
<div id="day">--</div>
<div id="hours">--</div>
<div id="minutes">--</div>
<div id="seconds">--</div>


<script type="text/javascript">
var countDownTime = {
	init: function(a, b, c, d, e) {
		this.t = a, this.d = b, this.h = c, this.m = d, this.s = e
	},
	start: function() {
		var a = this;
		setInterval(a.timer, 1e3)
	},
	timer: function(a) {
		var b, c, d, e, f, g, h;
		a = this.countDownTime, b = new Date, c = new Date(a.t), d = c.getTime() - b.getTime(), e = Math.floor(a.formatTime(d, "day")), f = Math.floor(a.formatTime(d, "hours")), g = Math.floor(a.formatTime(d, "minutes")), h = Math.floor(a.formatTime(d, "seconds")), a.d && (a.d.innerText = a.formatNumber(e)), a.h && (a.h.innerText = a.formatNumber(f)), a.m && (a.m.innerText = a.formatNumber(g)), a.s && (a.s.innerText = a.formatNumber(h))
	},
	formatNumber: function(a) {
		if(a<=0){a=0}
		return a = a.toString(), a[1] ? a : "0" + a
	},
	formatTime: function(a, b) {
		switch (b) {
			case "day":
				return a / 1e3 / 60 / 60 / 24;
			case "hours":
				return a / 1e3 / 60 / 60 % 24;
			case "minutes":
				return a / 1e3 / 60 % 60;
			case "seconds":
				return a / 1e3 % 60
		}
	}
};
var	day = document.getElementById('day');
var	hours = document.getElementById('hours');
var	minutes = document.getElementById('minutes');
var seconds = document.getElementById('seconds');
// 日 时 分 秒的dom对象
countDownTime.init('2018/08/08 18:38:08', day, hours, minutes, seconds);
countDownTime.start();
</script>
</body>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值