Autor Zpráva
martin20a
Profil *
Mám odpočet času:
<html> 
<head>
<title> TEST JS REDIRECT </title>
</head> 
<script language="javascript" type="text/javascript"> 
	var episodesDatesTimes = new Array(
		new Array(
						new Array("05 díl", 2009, 10, 20, 1, 0, 0),
					  new Array("06 dil", 2009, 12, 15, 19, 8, 0)
		)	);
	</script> 
	<script language="javascript" type="text/javascript" src="mc.js"></script> 
	<script language="javascript" type="text/javascript"> 
	runMC();
</script> 
<body> 
<span class="odpocitavani" id="countdownepisode1">Načítá se...</span><br><span id="countdown1"></span>
</body> 
</html>


k tomu script: (mc.js)
/*
	Multiple Counter 1.1
	Copyright 2006-2007 popKorn
	popkorn@post.cz
*/

var timerIDs = new Array(),
	timerRunnings = new Array(),
	episodeIDs = new Array(),
	bigDays = new Array(),
	foundCounters = new Array(),
	foundCountersTimerID = null,
	foundCountersRunning = false,
	pageLoaded = false;

window.onload = function() { pageLoaded = true; }

function runMC() {
	for(var i = 0; i < episodesDatesTimes.length; i++) {
		foundCounters[i] = false;
	}
	foundCounters[episodesDatesTimes.length] = 0;
		
	stopFindingCounters();
	findingCounters();

}

function stopFindingCounters() {
	if (foundCountersRunning) {
		clearTimeout(foundCountersTimerID);
	}
	foundCountersRunning = false;
}

function findingCounters() {

	checkAndRun();

	if ((pageLoaded)||(foundCounters[episodesDatesTimes.length] == episodesDatesTimes.length)) {
		stopFindingCounters();
		checkAndRun();
	} else {
		foundCountersTimerID = setTimeout("findingCounters()", 10);
	}
}

function checkAndRun() {
	for(var i = 0; i < episodesDatesTimes.length; i++) {
		if (foundCounters[i]) {
			continue;
		}
		
		var o1 = "countdownepisode" + (i + 1);
		var o2 = "countdown" + (i + 1);
		var obj1 = getRefTo(o1);
		var obj2 = getRefTo(o2);
		
		if ((obj1 != null)&&(obj2 != null)) {
			foundCounters[i] = true;
			foundCounters[episodesDatesTimes.length]++;
			startCountdown(i);
		}
	}
}

function getRefTo(objID) {
	var objRef = null;
	var bbdc = document;

	if ((bbdc.getElementById)&&(bbdc.getElementById(objID) != null)) {
		objRef = bbdc.getElementById(objID);
	} else {
		if ((bbdc.layers)&&(bbdc.layers[objID] != null)) {
			objRef	= bbdc.layers[objID];
		} else if (bbdc.all) {
			objRef = bbdc.all[objID];
		}
	}

	return objRef;
}

function prepareCountdown(id) {
	var thisIsTheEpisode = null;
	var tmpToday = new Date();
	var tmpbigDay = new Date();
	
	timerIDs[id] = null;
	timerRunnings[id] = false;
	bigDays[id] = null;
	episodeIDs[id] = "0x00";

	var tmpEpisodesDatesTimes = episodesDatesTimes[id];
	for(var i = 0; i < tmpEpisodesDatesTimes.length; i++) {
		var ep = tmpEpisodesDatesTimes[i];
		
		tmpbigDay = new Date(Date.UTC(ep[1], ep[2] - 1, ep[3], ep[4], ep[5], ep[6]));
				
		if (tmpToday.getTime() < tmpbigDay.getTime()) {
			thisIsTheEpisode = tmpEpisodesDatesTimes[i];
			break;
		}
	}
	if (thisIsTheEpisode != null) {
		bigDays[id] = tmpbigDay;
		episodeIDs[id] = thisIsTheEpisode[0];
		var o = "countdownepisode" + (id + 1);
		var obj = getRefTo(o);
		obj.innerHTML = episodeIDs[id];
	} else {
		if (tmpEpisodesDatesTimes.length != 0) {
			episodeIDs[id] = tmpEpisodesDatesTimes[tmpEpisodesDatesTimes.length - 1][0];
			var o = "countdownepisode" + (id + 1);
			var obj = getRefTo(o);
			obj.innerHTML = episodeIDs[id];
		}
		bigDays[id] = null;
	}
}

function startCountdown(id) {
	prepareCountdown(id);
	
	if (bigDays[id] != null) {
		startclock(id);
	} else {
		stopclock(id);
	}
}

function showtime(id) {
	var today = new Date();

	var msPerSec = 1000,
		secPerMin = 60,
		minPerHr = 60,
		hrsPerDay = 24;
	
	var tmpbigDay = bigDays[id];
	
	var timeLeft = (tmpbigDay.getTime() - today.getTime());
	timeLeft = (timeLeft < 0) ? 0 : timeLeft;
	timeLeft = Math.floor(timeLeft / msPerSec);

	var secLeft = timeLeft % secPerMin;
	timeLeft = Math.floor(timeLeft / secPerMin);

	var minsLeft = timeLeft % minPerHr;
	timeLeft = Math.floor(timeLeft / minPerHr);
	
	var hrsLeft = timeLeft % hrsPerDay;
	var daysLeft = Math.floor(timeLeft / hrsPerDay);
	
	var showText = daysLeft + "d " + checkZero(hrsLeft) + ":"
				+ checkZero(minsLeft) + ":" + checkZero(secLeft);
	
	var o = "countdown" + (id + 1);
	var obj = getRefTo(o);
	obj.innerHTML = showText;
	
	if ((daysLeft <= 0)&&(hrsLeft <= 0)&&(minsLeft <= 0)&&(secLeft <= 0)) {
		stopclock(id);
		timerIDs[id] = setTimeout("startCountdown(" + id + ")", secPerMin * msPerSec);
	} else {
		timerIDs[id] = setTimeout("showtime(" + id + ")", msPerSec);
	}
	timerRunnings[id] = true;
}

function stopclock(id) {
	if (timerRunnings[id]) {
		clearTimeout(timerIDs[id]);
	}
	timerRunnings[id] = false;
}

function startclock(id) {
	stopclock(id);
	showtime(id);
}

function checkZero(number) {
	return ((number < 10) ? ("0" + number) : number);
}


no a potřeboval bych udělat takové odpočítávání 2x na jedné stránce, ale nevím co všechno musím změnit aby mně to udělalo to co chci. čili jaké věci musím přejmenovat aby to bylo od sebe oddělené. Děkuji všem co odpoví. Našel jsem tady pár odpočtů času, ale já potřebuji aby to po uplynutí spustil zas nový. Díky
martin20a
Profil *
vyřešeno
Chamurappi
Profil
Reaguji na martina20:
Prozradíš jak?
popKorn
Profil
Stačí si stáhnout původní zdrojový kód, kde je i přehledný návod, jak definovat více počítadel: http://bones.gothics.cz/data/subtitles/MultipleCounter.zip

Vaše odpověď

Mohlo by se hodit

Neumíte-li správně určit příčinu chyby, vkládejte odkazy na živé ukázky.
Užíváte-li nějakou cizí knihovnu, ukažte odpovídajícím, kde jste ji vzali.

Užitečné odkazy:

Prosím používejte diakritiku a interpunkci.

Ochrana proti spamu. Napište prosím číslo dvě-sta čtyřicet-sedm:

0