-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdigitalClock.htm
58 lines (51 loc) · 1.78 KB
/
digitalClock.htm
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<!--
- Full screen clock (24-hour)
- Copyright (c) 2020 Project Nayuki
-
- https://www.nayuki.io/page/full-screen-clock-javascript
-->
<!DOCTYPE html>
<html style="height:80%; margin:0; padding:0">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>Clock</title>
<link rel="preconnect" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css2?family=Cormorant+Garamond&display=swap" rel="stylesheet">
<style type="text/css">
/* Customizable font and colors */
html {
background: #000000;
font-family: 'Cormorant Garamond', serif;
/* font-weight: bold; */
color: #FFFFFF;
}
</style>
</head>
<body style="display:flex; height:80%; margin:0; padding:0; justify-content:center; align-items:top">
<span id="clocktext" style="font-kerning:none"></span>
<script>
"use strict";
var textElem = document.getElementById("clocktext");
var targetWidth = 0.7; // Proportion of full screen width
var curFontSize = 20; // Do not change
function updateClock() {
var d = new Date();
var s = "";
s += (10 > d.getHours () ? "0" : "") + d.getHours () + "";
s += (10 > d.getMinutes() ? "0" : "") + d.getMinutes();
textElem.textContent = s;
//listElement.innerHTML = s;
setTimeout(updateClock, 60000 - d.getTime() % 60000 + 100);
}
function updateTextSize() {
for (var i = 0; 3 > i; i++) { // Iterate for better better convergence
curFontSize *= targetWidth / (textElem.offsetWidth / textElem.parentNode.offsetWidth);
textElem.style.fontSize = curFontSize + "pt";
}
}
updateClock();
updateTextSize();
window.addEventListener("resize", updateTextSize);
</script>
</body>
</html>