The countdown plug-in code based on jquery _jquery

Source: Internet
Author: User
Time remaining: 1 hours: 40 minutes: 30 seconds
Copy Code code as follows:

1/*
* Countdown plugin, mainly used for limited-timed purchase
* By Wayshan Version 1.0
* Use method:
* $ (function () {
* $ ("#ElementId"). Countdown ({
* Edate: "2012-12-21 15:14:23"
* });
* })

*/
;(function ($) {
$.fn.countdown = function (options) {
if (This.length = = 0) {
return false;
}
Return This.each (function () {
var Default = {
sdate:null,//Start time (format "2010-10-10 10:10:10") can be set to service-side time
edate:null,//End Date (format "2010-10-10 10:10:10")
Callback:function () {
return false;
}
},
_h_text= ' Hour ',
_m_text= ' min ',
_s_text= ' seconds ',
_lt = NULL,
_CT = new Date (),
_et = NULL,
_elt = NULL,
CTime = NULL,
ETime = NULL,
Domid = NULL,
_timeout = NULL,
_GT = function () {
if (_lt = = null) {
_elt = (etime-ctime);
if (_elt < 0) {
$ (' # ' +domid). HTML ("<strong>0</strong>" +_h_text+ ":<strong>0</strong>" +
_m_text+ ":<strong>0</strong>" +_s_text);
}
var _xt =math.ceil (_elt/(24*60*60*1000));
_CT = parseint (_ct.match (/\s (\d+) \d/) [1] * 3600)
+ parseint (_ct.split (":") [1] *) + parseint (_ct.split (":") [2]);
_et = _xt * 3600 + parseint (_et.match/\s (\d+) \d/) [1] * 3600)
+ parseint (_et.split (":") [1] *) + parseint (_et.split (":") [2]);
_lt = _elt/1000;
}
if (_elt > 0) {
if (_lt >= 0) {
var _h = Math.floor (_lt/3600);
var _m = Math.floor (_lt-_h * 3600)/60);
var _s = (_lt-_h * 3600)% 60;
$ (' # ' +domid). HTML ("<strong>" + _h + "</strong>" +_h_text+ ":<strong>"
+ _m + "</strong>" +_m_text+ ":<strong>" + _s + "</strong>" +_s_text);
_lt--;
} else {
Clearinterval (_timeout);
if (S.callback && $.isfunction (s.callback)) {
S.callback.call (this);
}
}
} else {
Clearinterval (_timeout);
if (S.callback && $.isfunction (s.callback)) {
S.callback.call (this);
}
}
},
Strdatetime = function (str) {
Determine if the date time is entered correctly and the type must be the same as: 2011-01-01 01:01:01
var reg =/^ (\d{1,4}) (-|\/) (\d{1,2}) \2 (\d{1,2}) (\d{1,2}):(\d{1,2}):(\d{1,2}) $/;
var r = Str.match (reg);
if (r==null) return false;
var d= new Date (r[1], r[3]-1,r[4],r[5],r[6],r[7]);
Return (D.getfullyear () ==r[1]&& (D.getmonth () +1) ==r[3]&&d.getdate () ==r[4]
&&d.gethours () ==r[5]&&d.getminutes () ==r[6]&&d.getseconds () ==r[7]);
}
var s = $.extend ({}, Default, Options | | {});
Domid = this.id;
if (Domid = = ' null ') {
Return
}
_et = s.edate;
if (!strdatetime (_et)) {
Alert (' End date format is not correct ');
return false;
}
if (s.sdate!= null) {
_CT = s.sdate;
}
_CT = _ct.tostring ();
CDate = _ct.replace (/-/g, '/');
_et = _et.tostring ();
Edate = _et.replace (/-/g, '/');
CTime = new Date (CDate);
ETime = new Date (edate);
_timeout = SetInterval (_GT, 1000)
});
}
}) (JQuery);

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.