generated from egmont11/ASP.Net-Core-MVC-Template
Přidání timeru
This commit is contained in:
1 parent
72a1019496
commit
e12161b733
2 files changed
+25
-3
No files matched your search
@@ -167,6 +167,9 @@
|
|||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
<div>
|
||||||
|
Do večírku zbývá: <span id="timer"></span>
|
||||||
|
</div>
|
||||||
<div class="map-container">
|
<div class="map-container">
|
||||||
<iframe style="border:none; display: block;" src="https://mapy.com/s/gobejunabe" width="400" height="280"></iframe>
|
<iframe style="border:none; display: block;" src="https://mapy.com/s/gobejunabe" width="400" height="280"></iframe>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,4 +1,23 @@
|
|||||||
// Please see documentation at https://learn.microsoft.com/aspnet/core/client-side/bundling-and-minification
|
const PARTY_DATE = new Date(2026, 9, 23, 16, 0);
|
||||||
// for details on configuring this project to bundle and minify static web assets.
|
|
||||||
|
|
||||||
// Write your JavaScript code.
|
function updateTimer() {
|
||||||
|
const timerEl = document.getElementById("timer");
|
||||||
|
const diff = PARTY_DATE - new Date();
|
||||||
|
|
||||||
|
if (diff <= 0) {
|
||||||
|
timerEl.textContent = "Večírek již začal!";
|
||||||
|
clearInterval(intervalId);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const days = Math.floor(diff / (1000 * 60 * 60 * 24));
|
||||||
|
const hours = Math.floor(diff / (1000 * 60 * 60)) % 24;
|
||||||
|
const minutes = Math.floor(diff / (1000 * 60)) % 60;
|
||||||
|
const seconds = Math.floor(diff / 1000) % 60;
|
||||||
|
|
||||||
|
timerEl.textContent =
|
||||||
|
`${days} dní a ${String(hours)}:${String(minutes)}:${String(seconds).padStart(2, "0")}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
updateTimer(); // run immediately so the span isn't empty for the first second
|
||||||
|
const intervalId = setInterval(updateTimer, 1000);
|
||||||
Reference in new issue
Block a user