⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 w3timer.js

📁 某网络游戏前台JS程序
💻 JS
字号:
//

function w3Timer (size)
{
	this.size = size;
	this.timerArray = new Array(size);
	this.urlArray = new Array(size);
	this.curSize = 0;
	this.timerRun = false;
}

w3Timer.prototype.addTimer = function(obj,tUrl){

	if ( typeof ( obj ) == 'string' )
	{
		obj = document.getElementById ( obj );
	}

	this.delTimer(obj);

	for (i = 0; i < this.timerArray.length; i++){
   		if(this.timerArray[i] == null){
   			this.timerArray[i] = obj;
   			this.urlArray[i] = tUrl;
   			break;
   		}
	}

	this.curSize++;

	if(!this.timerRun){
		this.timerRun = true;
		this.runTimer();
	}
}

w3Timer.prototype.delTimer = function(obj){
	for (i = 0; i < this.timerArray.length; i++){
   		if(this.timerArray[i] != null && this.timerArray[i].id == obj.id){
   			this.timerArray[i] = null;
   			this.urlArray[i] = null;
   			this.curSize--;
   		}
   	}
}

w3Timer.prototype.runTimer = function(){
	v = new Date();
	n = new Date();
	o = new Date();

	for (cn = 0; cn < this.timerArray.length; cn++) {
		timer = this.timerArray[cn];

		if(timer  == null || typeof(timer)=="undefined"){
			continue;
		}

		var tmpDiv = document.getElementById(timer.id);//重新检测页面元素
		if(tmpDiv  == null || typeof tmpDiv =="undefined"){
			this.delTimer(timer);
			continue;
		}



		ss = timer.title;
		s = ss - Math.round((n.getTime() - v.getTime()) / 1000.);
		m = 0;
		h = 0;
		if (s < 0) {
			timer.innerHTML="完成";
			if(this.urlArray[cn] != null && typeof(this.urlArray[cn]) != "undefined"){
				//alert(this.urlArray[cn]);
				loadPage(this.urlArray[cn],'body_content');
			}
			this.delTimer(timer);

			//document.location.reload();
		}else {
			if (s > 59) {
			m = Math.floor(s/60);
			s = s - m * 60;
			}
			if (m > 59) {
			h = Math.floor(m / 60);
			m = m - h * 60;
			}
			if (s < 10) {
			s = "0" + s;
			}
			if (m < 10) {
			m = "0" + m;
			}

			timer.innerHTML = h+":"+m+":"+s;
			timer.title = timer.title - 1;
		}
	}

	if(this.curSize > 0){
		window.setTimeout("runDivTimer();", 1000);
	}else{
		this.timerRun = false;
	}
}

var divTimer = new w3Timer (20);

function runDivTimer(){
	divTimer.runTimer();
}

// -->

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -