mirror of
https://github.com/sigmasternchen/glitch-countdown
synced 2025-03-15 10:38:53 +00:00
feat: Disable input once countdown has started
This commit is contained in:
parent
9e4edbf0bc
commit
214963bb88
2 changed files with 38 additions and 7 deletions
4
dist/main.css
vendored
4
dist/main.css
vendored
|
@ -43,4 +43,8 @@ body {
|
||||||
|
|
||||||
#countdown .down {
|
#countdown .down {
|
||||||
top: calc(3.3vw + 0.2vw);
|
top: calc(3.3vw + 0.2vw);
|
||||||
|
}
|
||||||
|
|
||||||
|
#countdown.counting .up, #countdown.counting .down {
|
||||||
|
display: none;
|
||||||
}
|
}
|
41
src/index.js
41
src/index.js
|
@ -1,4 +1,6 @@
|
||||||
(function() {
|
(function() {
|
||||||
|
var countdown = null;
|
||||||
|
|
||||||
const parts = {
|
const parts = {
|
||||||
"days": {
|
"days": {
|
||||||
"next": null,
|
"next": null,
|
||||||
|
@ -68,8 +70,37 @@
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const start = function() {
|
||||||
|
state.total = parseTime();
|
||||||
|
state.current = state.total;
|
||||||
|
state.counting = true;
|
||||||
|
|
||||||
|
countdown.classList.add("counting");
|
||||||
|
|
||||||
|
var part = "seconds";
|
||||||
|
while(part) {
|
||||||
|
const partObj = parts[part];
|
||||||
|
partObj.input.disabled = true;
|
||||||
|
part = partObj.next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const stop = function() {
|
||||||
|
state.counting = false;
|
||||||
|
|
||||||
|
countdown.classList.remove("counting");
|
||||||
|
|
||||||
|
var part = "seconds";
|
||||||
|
while(part) {
|
||||||
|
const partObj = parts[part];
|
||||||
|
partObj.input.disabled = false;
|
||||||
|
part = partObj.next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
window.addEventListener("load", function() {
|
window.addEventListener("load", function() {
|
||||||
Array.from(document.getElementById("countdown").getElementsByClassName("part")).forEach(element => {
|
countdown = document.getElementById("countdown");
|
||||||
|
Array.from(countdown.getElementsByClassName("part")).forEach(element => {
|
||||||
const part = parts[element.id];
|
const part = parts[element.id];
|
||||||
part.element = element;
|
part.element = element;
|
||||||
part.input = element.getElementsByTagName("input")[0];
|
part.input = element.getElementsByTagName("input")[0];
|
||||||
|
@ -117,11 +148,7 @@
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
document.getElementById("start").addEventListener("click", function() {
|
document.getElementById("start").addEventListener("click", start);
|
||||||
state.total = parseTime();
|
|
||||||
state.current = state.total;
|
|
||||||
state.counting = true;
|
|
||||||
});
|
|
||||||
|
|
||||||
window.setInterval(function() {
|
window.setInterval(function() {
|
||||||
if (state.counting) {
|
if (state.counting) {
|
||||||
|
@ -130,7 +157,7 @@
|
||||||
update(state.current);
|
update(state.current);
|
||||||
|
|
||||||
if (state.current == 0) {
|
if (state.current == 0) {
|
||||||
state.counting = false;
|
stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, 1000);
|
}, 1000);
|
||||||
|
|
Loading…
Reference in a new issue