Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html style="display:block; height:100%; margin:0; padding:0">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
- <title>Clock</title>
- <style type="text/css">
- html {
- background: #000000;
- }
- #clocktext {
- padding: 100px;
- font-family: sans-serif;
- font-weight: bold;
- color: #FFFFFF;
- }
- </style>
- </head>
- <body style="display:table; width:100%; height:100%; margin:0; padding:0">
- <div style="display:table-cell; width:100%; height:100%; text-align:center; vertical-align:middle">
- <span id="clocktext" style="font-size:24pt; font-kerning:none"></span>
- </div>
- <script type="text/javascript">
- "use strict";
- var textElem = document.getElementById("clocktext");
- var textNode = document.createTextNode("");
- textElem.appendChild(textNode);
- var curFontSize = 24;
- function updateClock() {
- var d = new Date();
- var s = "";
- s += ((d.getHours() + 11) % 12 + 1) + ":";
- s += (10 > d.getMinutes() ? "0" : "") + d.getMinutes() + " ";
- s += d.getHours() >= 12 ? "pm" : "am";
- textNode.data = s;
- setTimeout(updateClock, 1000 - d.getTime() % 1000 + 20);
- }
- function updateTextSize() {
- var targetWidth = 0.9; // Proportion of full screen width
- for (var i = 0; 3 > i; i++) {
- var newFontSize = textElem.parentNode.offsetWidth * targetWidth / textElem.offsetWidth * curFontSize;
- textElem.style.fontSize = newFontSize.toFixed(3) + "pt";
- curFontSize = newFontSize;
- }
- }
- updateClock();
- updateTextSize();
- window.addEventListener("resize", updateTextSize);
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement