基于jQuery的倒計(jì)時(shí)插件代碼
更新時(shí)間:2011年05月07日 09:46:53 作者:
jQuery倒計(jì)時(shí)插件,主要用來(lái)限時(shí)購(gòu)買(mǎi),需要的朋友可以參考下。
剩余時(shí)間:1小時(shí):40分:30秒
1 /*
* 倒計(jì)時(shí)插件,主要用來(lái)限時(shí)購(gòu)買(mǎi)
* By wayshan 版本1.0
* 使用方法:
* $(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,//開(kāi)始時(shí)間(格式為“2010-10-10 10:10:10”)可以設(shè)置為服務(wù)端的時(shí)間
Edate:null,//結(jié)束日期(格式為“2010-10-10 10:10:10”)
callback:function(){
return false;
}
},
_H_Text='小時(shí)',
_M_Text='分',
_S_Text='秒',
_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] * 60)+ parseInt(_cT.split(":")[2]);
_eT = _xT * 24 * 3600 + parseInt(_eT.match(/\s(\d+)\D/)[1] * 3600)
+ parseInt(_eT.split(":")[1] * 60) + 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){
//判斷日期時(shí)間的輸入是否正確,類型必須形如為: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('結(jié)束日期格式不正確');
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);
復(fù)制代碼 代碼如下:
1 /*
* 倒計(jì)時(shí)插件,主要用來(lái)限時(shí)購(gòu)買(mǎi)
* By wayshan 版本1.0
* 使用方法:
* $(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,//開(kāi)始時(shí)間(格式為“2010-10-10 10:10:10”)可以設(shè)置為服務(wù)端的時(shí)間
Edate:null,//結(jié)束日期(格式為“2010-10-10 10:10:10”)
callback:function(){
return false;
}
},
_H_Text='小時(shí)',
_M_Text='分',
_S_Text='秒',
_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] * 60)+ parseInt(_cT.split(":")[2]);
_eT = _xT * 24 * 3600 + parseInt(_eT.match(/\s(\d+)\D/)[1] * 3600)
+ parseInt(_eT.split(":")[1] * 60) + 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){
//判斷日期時(shí)間的輸入是否正確,類型必須形如為: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('結(jié)束日期格式不正確');
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);
您可能感興趣的文章:
- JS基于面向?qū)ο髮?shí)現(xiàn)的多個(gè)倒計(jì)時(shí)器功能示例
- 多個(gè)js毫秒倒計(jì)時(shí)同時(shí)進(jìn)行效果
- 同一頁(yè)面多個(gè)商品倒計(jì)時(shí)JS 基于面向?qū)ο蟮膉avascript
- JQuery實(shí)現(xiàn)倒計(jì)時(shí)按鈕具體方法
- jquery簡(jiǎn)單倒計(jì)時(shí)實(shí)現(xiàn)方法
- jQuery實(shí)現(xiàn)倒計(jì)時(shí)跳轉(zhuǎn)的例子
- JQuery實(shí)現(xiàn)倒計(jì)時(shí)按鈕的實(shí)現(xiàn)代碼
- jquery 倒計(jì)時(shí)效果實(shí)現(xiàn)秒殺思路
- 整理8個(gè)很棒的 jQuery 倒計(jì)時(shí)插件和教程
- JS/jquery實(shí)現(xiàn)一個(gè)網(wǎng)頁(yè)內(nèi)同時(shí)調(diào)用多個(gè)倒計(jì)時(shí)的方法
- jCountr基于jquery的倒計(jì)時(shí)插件
相關(guān)文章
jquery實(shí)現(xiàn)的動(dòng)態(tài)回到頂部特效代碼
這篇文章主要介紹了jquery實(shí)現(xiàn)的動(dòng)態(tài)回到頂部特效代碼,涉及jQuery基于時(shí)間函數(shù)的定時(shí)遞歸調(diào)用實(shí)現(xiàn)帶緩沖效果的移動(dòng)功能,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-10-10
jquery下為Event handler傳遞動(dòng)態(tài)參數(shù)的代碼
在jquery cook book里看到一篇給event handler傳遞動(dòng)態(tài)參數(shù)的文章 感覺(jué)挺實(shí)用的 跟大家分享下2011-01-01
jQuery動(dòng)畫(huà)顯示和隱藏效果實(shí)例演示(附demo源碼下載)
這篇文章主要介紹了jQuery動(dòng)畫(huà)顯示和隱藏效果實(shí)現(xiàn)方法,并附帶了demo源碼供讀者下載參考,涉及jQuery操作圖片的顯示,隱藏及淡入淡出等效果,需要的朋友可以參考下2015-12-12
jQuery點(diǎn)擊改變class并toggle及toggleClass()方法定義用法
這篇文章主要介紹了jQuery點(diǎn)擊改變class并toggle及toggleClass()方法定義用法的相關(guān)資料,需要的朋友可以參考下2015-12-12
jquery select選中的一個(gè)小問(wèn)題
jquery使select選中的注意事項(xiàng)。2009-10-10
jQuery 鼠標(biāo)經(jīng)過(guò)(hover)事件的延時(shí)處理示例
一般情況下,我們是不對(duì)鼠標(biāo)hover事件進(jìn)行延時(shí)處理。但是,有時(shí)候,為了避免不必要的干擾,常會(huì)對(duì)鼠標(biāo)hover事件進(jìn)行延時(shí)處理2014-04-04
Jquery公告滾動(dòng)+AJAX后臺(tái)得到數(shù)據(jù)
ajax得到值,用JQUERY綁定給對(duì)應(yīng)的UL.利用JQUERY的動(dòng)畫(huà)來(lái)實(shí)現(xiàn)他們的滾動(dòng)公告。2011-04-04

