У меня есть этот футбольный подсчитывать сценарийCount Up Script
// Class: Timer
var Timer = function (callback) {
// Property: Frequency of elapse event of the timer in milliseconds
this.Interval = 1000;
// Property: Whether the timer is enable or not
this.Enable = new Boolean(false);
// Event: Timer tick
this.Tick = callback;
// Member variable: Hold interval id of the timer
var timerId = 0;
// Member variable: Hold instance of this class
var thisObject;
// Function: Start the timer
this.Start = function() {
this.Enable = new Boolean(true);
thisObject = this;
if (thisObject.Enable) {
thisObject.timerId = setInterval(
function() {
thisObject.Tick();
}, thisObject.Interval);
}
};
// Function: Stops the timer
this.Stop = function() {
thisObject.Enable = new Boolean(false);
clearInterval(thisObject.timerId);
};
};
// Namespace: Match rules and timings
var Match = {
Timers: {
FirstHalf: new Timer(TimerTick),
HalfTime: new Timer(TimerTick),
SecondHalf: new Timer(TimerTick),
TickCount: -1
},
Strings: {
FirstHalf: 'First Half',
HalfTime: 'Half Time',
SecondHalf: 'Second Half',
FullTime: 'Finished'
},
DisplayTime: function (t) {
var m = parseInt(t/60);
var s = t % 60;
return (m < 10 ? '0' + m : m) + ":" + (s < 10 ? '0' + s : s);
}
};
// Function: Tick Event Handler (callback function)
function TimerTick(timer) {
// Document elements used.
var TimerP = document.getElementById('time');
var DisplayP = document.getElementById('display');
// During First Half
if (Match.Timers.FirstHalf.Enable == true) {
if (Match.Timers.TickCount == -1) { Match.Timers.TickCount = 0 }
if (Match.Timers.TickCount == 2700) {
Match.Timers.FirstHalf.Stop();
Match.Timers.TickCount = -1;
Match.Timers.HalfTime.Start();
} else {
TimerP.innerHTML = Match.DisplayTime(Match.Timers.TickCount);
DisplayP.innerHTML = Match.Strings.FirstHalf;
Match.Timers.TickCount++;
}
}
// During Half Time
else if (Match.Timers.HalfTime.Enable == true) {
if (Match.Timers.TickCount == -1) { Match.Timers.TickCount = 0 }
if (Match.Timers.TickCount == 900) {
Match.Timers.HalfTime.Stop();
Match.Timers.TickCount = -1;
Match.Timers.SecondHalf.Start();
} else {
TimerP.innerHTML = '45:00';
DisplayP.innerHTML = Match.Strings.HalfTime + ' (' + Match.DisplayTime(900 - Match.Timers.TickCount) + ')';
Match.Timers.TickCount++;
}
}
// During Second Half
else if (Match.Timers.SecondHalf.Enable == true) {
if (Match.Timers.TickCount == -1) { Match.Timers.TickCount = 2700 }
if (Match.Timers.TickCount == 5400) {
TimerP.innerHTML = '90:00';
DisplayP.innerHTML = Match.Strings.FullTime;
Match.Timers.SecondHalf.Stop();
Match.Timers.TickCount = -1;
} else {
TimerP.innerHTML = Match.DisplayTime(Match.Timers.TickCount);
DisplayP.innerHTML = Match.Strings.SecondHalf;
Match.Timers.TickCount++;
}
}
}
function KickOff() {
var btn = document.getElementById('btnKickOff');
btn.setAttribute('style','display: none;');
Match.Timers.FirstHalf.Start();
}
или проверить его здесь http://pastebin.com/CkmPQ9ZV
и у меня есть этот HTML-код для сценария: старт подсчета
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<title>Simple Football Match Timer</title>
<script src="timer.js" type="text/javascript"></script>
</head>
<body>
<form id="pageForm" runat="server">
<div>
<p id="display">Waiting for kick off.</p>
<p id="time">00:00</p>
<input id="btnKickOff" type="button" value="Kick Off!" onclick="KickOff();" />
</div>
</form>
</body>
</html>
Этот сценарий когда я нажимаю Kick off .. он отсчитывает от 0 до 45 минут, после чего показывает HalfTime и обратный отсчет 15 минут после 15 минут заканчивается, он начинает отсчет снова с 45 до 90 и когда он достигает 90 он показывает «Готово»
Его хороший сценарий, но моя проблема в том, что я хочу, чтобы этот скрипт не начинался снова после каждого обновления страницы, я хочу опубликовать его на своем веб-сайте, поэтому, когда пользователи открывают мой сайт, они смогут увидеть, что время будет .. я нажму на него в начале матча .. и он продолжит до конца
PS: я не очень хорошо разбираюсь в Javascript .. Мне нужна помощь при создании этого скрипта :)
'new Boolean (false);'. Я не видел этого в долгое время ... – elclanrs