最近做的五彩票项目安排,各有各的彩票时,用户打开五个页面的布局从服务器,一个remaintime(从这段时间的休息,然后颜色)此时客户下降呈现给用户,让用户获得色彩的时间休息。

实现原理很简单,不在这里,运行下面的代码来查看demo:








指数

EM {颜色:# F00;}







时间=函数(){()
This.init.apply(这个参数);
};

thetime.prototype = { {
初始化:功能(obj){
var =;
obj = that.buildparam(obj);
that.callback = obj.callback;
var container = that.container = document.getelementbyid(obj,容器);
container.innerHTML =小时分钟;
无功hourspace = that.hourspace = container.getelementsbytagname(不过){ 0 };
无功minutespace = that.minutespace = container.getelementsbytagname(不过){ 1 };
无功secondspace = that.secondspace = container.getelementsbytagname(不过){ 2 };
如果(obj。remaintime = = 0){
That.resetTime();
返回;
}

that.hours = math.floor(obj。remaintime / 3600);
,_remainder1 = obj。remaintime % 3600;
That.minutes = Math.floor (that._remainder1/60);
that.seconds =,_remainder1 % 60;
VaR定时器= that.timer = setInterval(){()函数(
That.renderTime.apply (that);
},1000);
},
BuildParam:功能(obj){
obj = { {
容器是DOM节点的id。
集装箱:| | container'container OBJ,
remaintime:数(obj。remaintime)| | 0,
在完成倒计时/回调之后
回调:obj.callback新功能| |
};
返回对象;
},
时间:函数(){
var =;
that.container.innerhtml =已停产;
},
刷新时间
RenderTime:函数(){
调试器;
var =;
如果(秒= 0){
that.seconds--;
其他{ }
that.seconds = 59;
如果(.分钟> 0){
that.minutes--;
其他{ }
that.minutes = 59;
如果(小时> 0){
that.hours--;
}
}
}

听/听
如果(0=0,= 0。)
回调
这_callback();
}
无功bithandle = that.bithandle;

无功_hour = bithandle(的时间);
无功_minute = bithandle(,分钟);
无功_second = bithandle(,秒);
that.hourspace.innerhtml = _hour;
that.minutespace.innerhtml = _minute;
that.secondspace.innerhtml = _second;
},
对于数字处理,确保返回两位数
BitHandle:功能(NUM){
var str = num.tostring();
如果(str.length<2){
STR = 0 + STR;
}
返回字符;
},
_callback:函数(){
var =;
ClearInterval(,定时器);
that.callback();
}

};

新时间({
身份证/容器
容器:'remaintime,
服务器返回的剩余时间(以秒为单位)
remaintime:10000,
当倒计时/回调时
回调函数(){
document.getelementbyid('remaintime).innerHTML =截止;
}
});