|
@@ -1,39 +1,55 @@
|
|
|
/**
|
|
|
* Created by huanggang on 16/10/17.
|
|
|
*/
|
|
|
-$(function()
|
|
|
-{
|
|
|
- var server_local_time = $('#server_local_time').val();
|
|
|
- var server_start_time = $('#server_start_time').val();
|
|
|
-
|
|
|
- nowTime = new Date();
|
|
|
- cur_sec = parseInt(nowTime.getTime() / 1000);
|
|
|
- delta_secs = server_local_time - cur_sec;
|
|
|
|
|
|
- d_secs = 24 * 60 * 60;
|
|
|
- h_secs = 60 * 60;
|
|
|
- m_secs = 60;
|
|
|
+var CountDowner = function()
|
|
|
+{
|
|
|
+ this.server_time = 0;
|
|
|
+ this.start_time = 0;
|
|
|
+ this.delta_secs = 0;
|
|
|
|
|
|
- function GetRTime()
|
|
|
+ this.init = function (server_time,start_time) {
|
|
|
+ this.server_time = server_time;
|
|
|
+ this.start_time = start_time;
|
|
|
+ nowTime = new Date();
|
|
|
+ cur_sec = parseInt(nowTime.getTime() / 1000);
|
|
|
+ this.delta_secs = this.server_time - cur_sec;
|
|
|
+ }
|
|
|
+
|
|
|
+ this.run = function ()
|
|
|
{
|
|
|
+ d_secs = 24 * 60 * 60;
|
|
|
+ h_secs = 60 * 60;
|
|
|
+ m_secs = 60;
|
|
|
+
|
|
|
nowTime = new Date();
|
|
|
- left_secs = server_start_time - (parseInt(nowTime.getTime() / 1000) + delta_secs);
|
|
|
+ left_secs = this.start_time - (parseInt(nowTime.getTime() / 1000) + this.delta_secs);
|
|
|
|
|
|
left_h = parseInt(left_secs / h_secs);
|
|
|
left_m = parseInt((left_secs % h_secs) / m_secs);
|
|
|
left_s = parseInt(left_secs % m_secs);
|
|
|
|
|
|
- function add_zero(time,id){
|
|
|
- if(time<10){
|
|
|
- document.getElementById(id).innerHTML ="0"+time;
|
|
|
- }
|
|
|
- else {
|
|
|
- document.getElementById(id).innerHTML = time;
|
|
|
- }
|
|
|
+ this.add_zero(left_h,"hour");
|
|
|
+ this.add_zero(left_m,"min");
|
|
|
+ this.add_zero(left_s,"second");
|
|
|
+ }
|
|
|
+ this.isEnd = function () {
|
|
|
+ left_secs = this.start_time - (parseInt(nowTime.getTime() / 1000) + this.delta_secs);
|
|
|
+ if(left_secs > 0) {
|
|
|
+ return false;
|
|
|
+ } else {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ this.add_zero = function (time, id)
|
|
|
+ {
|
|
|
+ if(time<10){
|
|
|
+ document.getElementById(id).innerHTML ="0"+time;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ document.getElementById(id).innerHTML = time;
|
|
|
}
|
|
|
- add_zero(left_h,"hour");
|
|
|
- add_zero(left_m,"min");
|
|
|
- add_zero(left_s,"second");
|
|
|
}
|
|
|
-});
|
|
|
+};
|
|
|
|