Because the usual work is very commonly used to this function, so use this national day holiday, to comb and the original code to improve, and then integrated a common function, and finally encapsulated this "simple Countdown" function.
The countdown method has the following features:
1. Match the current computer time according to the specified date
2. Set the countdown for different time periods within each day by specifying an array parameter.
* The method has not been detected by the actual work, the stability is unknown (if the actual work through, will delete this paragraph)
function Countdown (date,target,filter) {var settime = new Date (date). GetTime (), timer = null;
function core () {var nowtime = new Date (). GetTime (), Lefttime = 0, d = 0,h = 0,m = 0,s = 0;
Conditation @ doublue time if (filter.length) {settime = new Date ();
for (Var i=0,l=filter.length;i<l;i++) {settime.sethours (filter[i]);
Settime.setminutes (0);
Settime.setseconds (0);
if (Nowtime < Settime.gettime ()) {break;
}else if (i = = filter.length-1) {settime.setdate (Settime.getdate () +1);
Settime.sethours (Filter[0]);
}}////////////////////////////Lefttime = Math.ceil ((settime-nowtime)/1000);
if (nowtime <= settime) {d = ~ ~ (lefttime/86400);
H = ~ ~ (lefttime%86400/3600);
m = ~ ~ (LEFTTIME%86400%3600/60);
s = ~ ~ (lefttime%86400%3600%60);
Timer = settimeout (CORE,1E3); }else{cleartimeout (timer);
timer = null;
//here set out format target.innerhtml = ' d: ' +d+ ' H: ' +h+ ' m: ' +m+ ' s: ' +s;
Core (); }
Call Mode:
Ordinary Call
countdown (' 2016/10/02/23:43 ', odiv);
Specify Time Cycle Countdown
countdown (' 2016/10/02/23:43 ', odiv,[9,11,18]);
The above of their own encapsulation of a simple countdown function example is a small series to share all the content, hope to give you a reference, but also hope that we support the cloud-dwelling community.