feat: Update clock
Add switch for 12/24-hour format.
This commit is contained in:
parent
1e874c4ac8
commit
847c4a9f6b
2 changed files with 20 additions and 2 deletions
|
|
@ -10,6 +10,9 @@ tags:
|
||||||
{% block body %}
|
{% block body %}
|
||||||
<main>
|
<main>
|
||||||
<canvas id="clock" width="512" height="512"></canvas>
|
<canvas id="clock" width="512" height="512"></canvas>
|
||||||
|
<p>
|
||||||
|
<button id="toggleFormat">12-Stunden-Format</button>
|
||||||
|
</p>
|
||||||
</main>
|
</main>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
|
@ -19,6 +22,12 @@ tags:
|
||||||
// Page script
|
// Page script
|
||||||
const canvas = document.getElementById('clock');
|
const canvas = document.getElementById('clock');
|
||||||
const ctx = canvas.getContext('2d');
|
const ctx = canvas.getContext('2d');
|
||||||
|
let is24HourFormat = true;
|
||||||
|
|
||||||
|
document.getElementById('toggleFormat').addEventListener('click', () => {
|
||||||
|
is24HourFormat = !is24HourFormat;
|
||||||
|
document.getElementById('toggleFormat').textContent = is24HourFormat ? '12-Stunden-Format' : '24-Stunden-Format';
|
||||||
|
});
|
||||||
|
|
||||||
function drawCircle(seconds, minutes, hours) {
|
function drawCircle(seconds, minutes, hours) {
|
||||||
const centerX = canvas.width / 2;
|
const centerX = canvas.width / 2;
|
||||||
|
|
@ -40,8 +49,12 @@ tags:
|
||||||
|
|
||||||
drawArc(seconds, 60, radius, 'black');
|
drawArc(seconds, 60, radius, 'black');
|
||||||
drawArc(minutes, 60, radius - 20, 'lightgrey');
|
drawArc(minutes, 60, radius - 20, 'lightgrey');
|
||||||
// drawArc(hours % 12, 12, radius - 40, 'white');
|
drawArc(
|
||||||
drawArc(hours, 24, radius - 40, 'white');
|
is24HourFormat ? hours : hours % 12,
|
||||||
|
is24HourFormat ? 24 : 12,
|
||||||
|
radius - 40,
|
||||||
|
'white'
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateCircle() {
|
function updateCircle() {
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,11 @@
|
||||||
main {
|
main {
|
||||||
@extend .sec_main_center;
|
@extend .sec_main_center;
|
||||||
display: flex;
|
display: flex;
|
||||||
|
flex-flow: column nowrap;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
p {
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue