generated from iamsonukushwaha/README
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tl.js
32 lines (28 loc) · 900 Bytes
/
tl.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
let nIntervId;
function changeColor() {
// check if already an interval has been set up
if (!nIntervId) {
nIntervId = setInterval(flashText, 2000);
}
}
function flashText() {
const oElem = document.getElementById("my_box");
const tl = document.getElementById("tl");
if (oElem.className === "ready") {
oElem.className = "go";
tl.innerText = "GO";
} else if (oElem.className === "go") {
oElem.className = "stop";
tl.innerText = "STOP";
} else {
oElem.className = "ready";
tl.innerText = "READY";
}
}
function stopTextColor() {
clearInterval(nIntervId);
// release our intervalID from the variable
nIntervId = null;
}
document.getElementById("start").addEventListener("click", changeColor);
document.getElementById("stop").addEventListener("click", stopTextColor);