mirror of
https://github.com/sigmasternchen/glitch-countdown
synced 2025-03-15 10:38:53 +00:00
feat: Add buttons for time selection
This commit is contained in:
parent
2102b40a88
commit
d33dc68b6f
3 changed files with 67 additions and 10 deletions
20
dist/index.html
vendored
20
dist/index.html
vendored
|
@ -15,16 +15,24 @@
|
||||||
<section>
|
<section>
|
||||||
<div id="countdown">
|
<div id="countdown">
|
||||||
<div id="days" class="part">
|
<div id="days" class="part">
|
||||||
|
<span class="up">⟪</span>
|
||||||
<input type="text" value="0">
|
<input type="text" value="0">
|
||||||
|
<span class="down">⟫</span>
|
||||||
</div>
|
</div>
|
||||||
<div id="hours" class="part">
|
<div id="hours" class="part">
|
||||||
<input type="text" value="0"> :
|
<span class="up">⟪</span>
|
||||||
</div>
|
|
||||||
<div id="minutes" class="part">
|
|
||||||
<input type="text" value="0"> :
|
|
||||||
</div>
|
|
||||||
<div id="seconds" class="part">
|
|
||||||
<input type="text" value="0">
|
<input type="text" value="0">
|
||||||
|
<span class="down">⟫</span>
|
||||||
|
</div> :
|
||||||
|
<div id="minutes" class="part">
|
||||||
|
<span class="up">⟪</span>
|
||||||
|
<input type="text" value="0">
|
||||||
|
<span class="down">⟫</span>
|
||||||
|
</div> :
|
||||||
|
<div id="seconds" class="part">
|
||||||
|
<span class="up">⟪</span>
|
||||||
|
<input type="text" value="0">
|
||||||
|
<span class="down">⟫</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
23
dist/main.css
vendored
23
dist/main.css
vendored
|
@ -12,8 +12,10 @@ body {
|
||||||
background-color: grey;
|
background-color: grey;
|
||||||
}
|
}
|
||||||
|
|
||||||
#countdown div {
|
#countdown .part {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
|
position: relative;
|
||||||
|
padding-top: 1vw;
|
||||||
}
|
}
|
||||||
|
|
||||||
#countdown * {
|
#countdown * {
|
||||||
|
@ -22,4 +24,23 @@ body {
|
||||||
|
|
||||||
#countdown input {
|
#countdown input {
|
||||||
width: 6vw;
|
width: 6vw;
|
||||||
|
height: 3.3vw;
|
||||||
|
}
|
||||||
|
|
||||||
|
#countdown .up, #countdown .down {
|
||||||
|
position: absolute;
|
||||||
|
line-height: 3vw;
|
||||||
|
width: 1vw;
|
||||||
|
text-align: center;
|
||||||
|
left: calc(50% - 0.5vw);
|
||||||
|
transform: rotate(90deg);
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
#countdown .up {
|
||||||
|
top: calc(-1vw - 0.2vw);
|
||||||
|
}
|
||||||
|
|
||||||
|
#countdown .down {
|
||||||
|
top: calc(3.3vw + 0.2vw);
|
||||||
}
|
}
|
34
src/index.js
34
src/index.js
|
@ -1,8 +1,11 @@
|
||||||
(function() {
|
(function() {
|
||||||
|
var counting = false;
|
||||||
|
|
||||||
const parts = {
|
const parts = {
|
||||||
"days": {
|
"days": {
|
||||||
"next": null,
|
"next": null,
|
||||||
"prev": "hours",
|
"prev": "hours",
|
||||||
|
"value": 0,
|
||||||
"maxValue": 999,
|
"maxValue": 999,
|
||||||
"element": null,
|
"element": null,
|
||||||
"input": null,
|
"input": null,
|
||||||
|
@ -10,6 +13,7 @@
|
||||||
"hours": {
|
"hours": {
|
||||||
"next": "days",
|
"next": "days",
|
||||||
"prev": "minutes",
|
"prev": "minutes",
|
||||||
|
"value": 0,
|
||||||
"maxValue": 24,
|
"maxValue": 24,
|
||||||
"element": null,
|
"element": null,
|
||||||
"input": null,
|
"input": null,
|
||||||
|
@ -17,6 +21,7 @@
|
||||||
"minutes": {
|
"minutes": {
|
||||||
"next": "hours",
|
"next": "hours",
|
||||||
"prev": "seconds",
|
"prev": "seconds",
|
||||||
|
"value": 0,
|
||||||
"maxValue": 60,
|
"maxValue": 60,
|
||||||
"element": null,
|
"element": null,
|
||||||
"input": null,
|
"input": null,
|
||||||
|
@ -24,6 +29,7 @@
|
||||||
"seconds": {
|
"seconds": {
|
||||||
"next": "minutes",
|
"next": "minutes",
|
||||||
"prev": null,
|
"prev": null,
|
||||||
|
"value": 0,
|
||||||
"maxValue": 60,
|
"maxValue": 60,
|
||||||
"element": null,
|
"element": null,
|
||||||
"input": null,
|
"input": null,
|
||||||
|
@ -44,16 +50,38 @@
|
||||||
if (value >= part.maxValue) {
|
if (value >= part.maxValue) {
|
||||||
if (part.next) {
|
if (part.next) {
|
||||||
part.input.value = value % part.maxValue;
|
part.input.value = value % part.maxValue;
|
||||||
parts[part.next].input.value = Math.floor(value / part.maxValue);
|
parts[part.next].input.value = parseInt(parts[part.next].input.value) + Math.floor(value / part.maxValue);
|
||||||
|
parts[part.next].input.dispatchEvent(new FocusEvent("blur"));
|
||||||
|
} else {
|
||||||
|
// ugly hack to only reset to 0 if the blur event was caused by cascading changes
|
||||||
|
if (Math.abs(value - part.value) == 1) {
|
||||||
|
part.input.value = 0;
|
||||||
|
} else {
|
||||||
|
part.input.value = part.maxValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (value < 0) {
|
||||||
|
if (part.next) {
|
||||||
|
part.input.value = value + part.maxValue * Math.ceil(-value / part.maxValue);
|
||||||
|
parts[part.next].input.value = parseInt(parts[part.next].input.value) + Math.floor(value / part.maxValue);
|
||||||
parts[part.next].input.dispatchEvent(new FocusEvent("blur"));
|
parts[part.next].input.dispatchEvent(new FocusEvent("blur"));
|
||||||
} else {
|
} else {
|
||||||
part.input.value = part.maxValue;
|
part.input.value = part.maxValue;
|
||||||
}
|
}
|
||||||
} else if (value < 0) {
|
|
||||||
part.input.value = 0;
|
|
||||||
} else {
|
} else {
|
||||||
part.input.value = value;
|
part.input.value = value;
|
||||||
}
|
}
|
||||||
|
part.value = parseInt(part.input.value);
|
||||||
|
});
|
||||||
|
|
||||||
|
element.getElementsByClassName("up")[0].addEventListener("click", function(event) {
|
||||||
|
part.input.value = parseInt(part.input.value) + 1;
|
||||||
|
part.input.dispatchEvent(new FocusEvent("blur"));
|
||||||
|
});
|
||||||
|
|
||||||
|
element.getElementsByClassName("down")[0].addEventListener("click", function(event) {
|
||||||
|
part.input.value = parseInt(part.input.value) - 1;
|
||||||
|
part.input.dispatchEvent(new FocusEvent("blur"));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue