Created
August 16, 2019 17:21
-
-
Save neonphog/48664387ce45d88c65fbcf6f43734513 to your computer and use it in GitHub Desktop.
cdown.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <html> | |
| <head> | |
| <style> | |
| #cdown .cdown { | |
| display: inline-block; | |
| margin: 2px; | |
| padding: 2px; | |
| border: solid 1px #888; | |
| border-radius: 2px; | |
| text-align: center; | |
| } | |
| #cdown .cdown .num { | |
| font-family: monospace; | |
| font-size: 200%; | |
| } | |
| #cdown .cdown .title { | |
| color: #888; | |
| margin: 2px; | |
| } | |
| </style> | |
| </head> | |
| <body> | |
| <div id="cdown"><script> | |
| var TARGET_DATE = new Date(2019, /*month is zero based*/ 7, 23) | |
| function cdown_set_text(e, t) { | |
| var r = [] | |
| for (var i = 0; i < e.childNodes.length; ++i) { | |
| if (e.childNodes[i].nodeType === document.TEXT_NODE) { | |
| r.push(e.childNodes[i]) | |
| } | |
| } | |
| for (var i = 0; i < r.length; ++i) { | |
| e.removeChild(r[i]) | |
| } | |
| e.appendChild(document.createTextNode(t)) | |
| } | |
| var d = document.getElementById('cdown') | |
| function cdown_make(n) { | |
| var e = document.createElement('div') | |
| e.className = "cdown n" | |
| d.appendChild(e) | |
| var c = document.createElement('div') | |
| c.className = "num" | |
| e.appendChild(c) | |
| cdown_set_text(c, '0') | |
| var t = document.createElement('div') | |
| t.className = "title" | |
| e.appendChild(t) | |
| cdown_set_text(t, n) | |
| return c | |
| } | |
| var eDays = cdown_make('days') | |
| var eHours = cdown_make('hrs') | |
| var eMinutes = cdown_make('min') | |
| var eSeconds = cdown_make('sec') | |
| function cdown_pad(t) { | |
| if (t.length === 1) { | |
| return '0' + t | |
| } | |
| return t | |
| } | |
| function cdown_set_time() { | |
| var time = TARGET_DATE - Date.now() | |
| var days = parseInt(time / 1000 / 60 / 60 / 24) | |
| time -= days * 24 * 60 * 60 * 1000 | |
| var hours = parseInt(time / 1000 / 60 / 60) | |
| time -= hours * 60 * 60 * 1000 | |
| var minutes = parseInt(time / 1000 / 60) | |
| time -= minutes * 60 * 1000 | |
| var seconds = parseInt(time / 1000) | |
| cdown_set_text(eDays, cdown_pad('' + days)) | |
| cdown_set_text(eHours, cdown_pad('' + hours)) | |
| cdown_set_text(eMinutes, cdown_pad('' + minutes)) | |
| cdown_set_text(eSeconds, cdown_pad('' + seconds)) | |
| } | |
| cdown_set_time() | |
| setInterval(cdown_set_time, 1000) | |
| </script></div> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment