The same page can be used many times the countdown JS code

Source: Internet
Author: User
Tags jquery library

Today because of the need to do a page multiple countdown to such a feature, but on the internet for a long time to see only some of jquery has been written plug-ins.
But my project can not use jquery (too many reasons, such as conflict with the system library), and for such a feature to introduce 80K size of the jquery library,
Also a bit wasteful, but also have to add a plug-in library, it is even greater,
Under the rogue, to find Ecshop a JS modified into a page multiple countdown, although not very perfect, but the basic can be used
Leave it to those who need it;

/**
Change to a page to show multiple countdown

Call Mode:
Onload_lefttime (start timestamp, end timestamp, display ID);
Such as:

Onload_lefttime (1322603631,1352793600, ' lefttime ');
Onload_lefttime (1322603631,1352793600, ' lefttime1′);
Onload_lefttime (1322603631,1352793600, ' lefttime2′);

**/

The code is as follows Copy Code

var timerrunning = [];
var timerid = [];
var auctiondate = [];
var starttime = [];
var showtimeid = [];

function Showtime () {
var _day = ' Day ';
var _hour = ' Hour ';
var _minute = ' min ';
var _second = ' sec ';
var _end = ' End ';
var dateleft = 0;
var hourleft = 0;
var minuteleft = 0;
var secondleft = 0;
var hourzero = ";
var minutezero = ";
var secondzero = ";

var c = auctiondate.length;

for (var i = 0, j = auctiondate.length I < J; i++) {

if (auctiondate[i] = = null) {
C-
Continue
}
now = new Date ();
var ts = parseint ((starttime[i]–now.gettime ())/1000) + auctiondate[i];

if (TS < 0) {
ts = 0;
Curhour = 0;
Curminute = 0;
Cursecond = 0;
} else {
Dateleft = parseint (ts/86400);
TS = ts–dateleft * 86400;
Hourleft = parseint (ts/3600);
TS = ts–hourleft * 3600;
Minuteleft = parseint (TS/60);
Secondleft = Ts–minuteleft * 60;
}

if (Hourleft < 10) {
Hourzero = ' 0′;
}
if (Minuteleft < 10) {
Minutezero = ' 0′;
}
if (Secondleft <) {Secondzero = ' 0′} if (Dateleft > 0) {
Temp = dateleft + _day + hourzero + hourleft + _hour + minutezero + minuteleft + _minute + secondzero + secondleft + _seco nd
} else {
if (Hourleft > 0) {
Temp = hourleft + _hour + minutezero + minuteleft + _minute + secondzero + secondleft + _second;
} else {
if (Minuteleft > 0) {
Temp = minuteleft + _minute + secondzero + secondleft + _second;
} else {
if (Secondleft > 0) {
Temp = Secondleft + _second;
} else {
Temp = ";
}
}
}
}

if (ts Temp = "<strong>" + _end + "</strong>";
Auctiondate[i] = null;
}

if (document.getElementById (Showtimeid[i])) {
document.getElementById (Showtimeid[i]). InnerHTML = Temp;
}

Timerrunning[i] = true;

}

if (C > 0) {
Timerid = settimeout ("Showtime ()", 1000);
}

}

function Stopclock (timerrunning, Timerid) {
if (timerrunning) {
Cleartimeout (Timerid);
}
Timerrunning = false;
}

function Onload_lefttime (now_time, Gmt_end_time, ShowTime) {

var auctiondate_tmp = 0;
var _gmtendtime = 0;

var cur_date = new Date ();

_gmtendtime = Gmt_end_time;

if (_gmtendtime > 0) {
if (now_time = = undefined) {
var tmp_val = parseint (_gmtendtime)
-parseint (Cur_date.gettime ()/1000
+ cur_date.gettimezoneoffset () * 60);
} else {
var tmp_val = parseint (_gmtendtime) –now_time;
}

if (Tmp_val > 0) {
Auctiondate_tmp = Tmp_val;
}

}

Timerrunning[timerrunning.length] = false;
Timerid[timerid.length] = null;
Auctiondate[auctiondate.length] = auctiondate_tmp;
Starttime[starttime.length] = Cur_date.gettime ();
Showtimeid[showtimeid.length] = ShowTime;

Showtime ();

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.