没有合适的资源?快使用搜索试试~ 我知道了~
近期在做排列五的彩票项目,每一期都有购彩时段,即用户打开这个排列五的页面时,会从服务器传来一个remaintime(离本次彩期结束的剩余时间),然后这个时间在客户端递减呈现给用户看,让用户获得本次彩期的剩余时间。 实现原理挺简单的,在此不在赘述,运行以下代码查看demo: <!doctype html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gbk" /> <title>index</title> <style type="text/css"> em{color:#f00;} </
资源推荐
资源详情
资源评论
JavaScript实现的一个倒计时的类实现的一个倒计时的类
近期在做排列五的彩票项目,每一期都有购彩时段,即用户打开这个排列五的页面时,会从服务器传来一个remaintime(离本
次彩期结束的剩余时间),然后这个时间在客户端递减呈现给用户看,让用户获得本次彩期的剩余时间。
实现原理挺简单的,在此不在赘述,运行以下代码查看demo:
<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk" />
<title>index</title>
<style type="text/css">
em{color:#f00;}
</style>
</head>
<body>
<div id="remaintime"></div>
<script type="text/javascript">
var TheTime = function(){
this.init.apply(this,arguments);
};
TheTime.prototype = {
init: function(obj){
var that = this;
obj = that.buildParam(obj);
that.callback = obj.callback;
var container = that.container = document.getElementById(obj.container);
container.innerHTML = '<em></em>小时<em></em>分钟<em></em>秒';
var hourSpace = that.hourSpace = container.getElementsByTagName('em')[0];
var minuteSpace = that.minuteSpace = container.getElementsByTagName('em')[1];
var secondSpace = that.secondSpace = container.getElementsByTagName('em')[2];
if(obj.remaintime==0){
that.resetTime();
return;
}
that.hours = Math.floor(obj.remaintime/3600);
that._remainder1 = obj.remaintime % 3600;
that.minutes = Math.floor(that._remainder1/60);
that.seconds = that._remainder1 % 60;
var timer = that.timer = setInterval(function(){
that.renderTime.apply(that);
},1000);
},
buildParam: function(obj){
obj = {
//container为dom节点的id
container: obj.container || 'container',
remaintime: Number(obj.remaintime) || 0,
//倒计时完成后的回调
callback: obj.callback || new Function
};
return obj;
},
resetTime: function(){
var that = this;
that.container.innerHTML = "已经截止";
},
//刷新时间
renderTime: function(){
//debugger;
var that = this;
if(that.seconds>0){
that.seconds--;
}else{
资源评论
weixin_38558054
- 粉丝: 2
- 资源: 971
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功