当前位置: 代码迷 >> Web前端 >> 基于jQuery的(hh:mm:ss)记时
  详细解决方案

基于jQuery的(hh:mm:ss)记时

热度:612   发布时间:2012-10-28 09:54:44.0
基于jQuery的(hh:mm:ss)倒计时
基于这里的版本修改,感谢原作者
http://www.iteye.com/topic/785609
改成了 hh:mm:ss 形式的倒计时
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<script type="text/javascript" src="jquery-1.4.2.js"></script>
</head>
<body>
	<div class="t"></div>
</body>
</html>
<script type="text/javascript">
$(function(){
	$.fn.countDown = function(settings,hh,mm,ss) {
		if(typeof ss=='undefined') { hh = settings.hh;mm = settings.mm;ss = settings.ss; }
		this.data("CR_currentTime_hh",hh);
		this.data("CR_currentTime_mm",mm);
		this.data("CR_currentTime_ss",ss);
		var to=(hh<10?'0'+hh:hh)+":"+(mm<10?'0'+mm:mm)+":"+(ss<10?'0'+ss:ss);
		if(ss==0&&(mm>0||hh>0)){
			if(mm>0){
				mm-=1;
			}else if(mm==0&&hh>0){
				hh-=1;
				mm+=59;
			}
			ss+=60;
		}
		$(this).text(to).animate({"none":"none"},settings.duration,'',function() {
			if(hh!=0||mm!=0||ss!=0) {
				$(this).countDown(settings,hh,mm,ss- 1);
			}else{
				settings.callBack(this);
			}
		});		
		return this;
	};
	$.fn.CRcountDown = function(settings) {
		settings = jQuery.extend({
			hh:0,
			mm:0,
			ss:0,
			startNumber: 10,
			endNumber: 0,
			duration: 1000,
			callBack: function() { }
		}, settings);
		this.data("CR_hh",settings.hh);
		this.data("CR_mm",settings.mm);
		this.data("CR_ss",settings.ss);
		this.data("CR_duration",settings.duration);
		this.data("CR_callBack",settings.callBack);
		return this.stop().countDown(settings);
	};
	$.fn.pause = function(settings) {
		return this.stop();
	};
	$.fn.reStart = function() {
		return this.pause().CRcountDown({
			hh : this.data("CR_currentTime_hh"),
			mm : this.data("CR_currentTime_mm"),
			ss : this.data("CR_currentTime_ss"),
			duration : 	this.data("CR_duration"),
			callBack : this.data("CR_callBack")
		});
	};

})

$(function (){

	$(".t").CRcountDown({mm:1,ss:10,callBack:function(){
		alert("time over");
	}});
});

</script>

  相关解决方案