{"id":222,"date":"2013-01-22T15:11:16","date_gmt":"2013-01-22T15:11:16","guid":{"rendered":"http:\/\/a1webdesignteam.com\/blog\/?p=222"},"modified":"2013-01-22T15:11:16","modified_gmt":"2013-01-22T15:11:16","slug":"create-countdown-clock-css3","status":"publish","type":"post","link":"https:\/\/a1webdesignteam.com\/blog\/create-countdown-clock-css3\/","title":{"rendered":"How To Create A Countdown Clock With CSS3"},"content":{"rendered":"<p>Below is the HTML markup for the clock and the explanation for my methods.<\/p>\n<p>&nbsp;<\/p>\n<pre>&lt;div&gt;\r\n\t&lt;ol&gt;\r\n\t\t&lt;li&gt;6&lt;\/li&gt;\r\n\t\t&lt;li&gt;5&lt;\/li&gt;\r\n\t\t&lt;li&gt;4&lt;\/li&gt;\r\n\t\t&lt;li&gt;3&lt;\/li&gt;\r\n\t\t&lt;li&gt;2&lt;\/li&gt;\r\n\t\t&lt;li&gt;1&lt;\/li&gt;\r\n\t&lt;\/ol&gt;\r\n\t&lt;ol&gt;\r\n\t\t&lt;li&gt;0&lt;\/li&gt;\r\n\t\t&lt;li&gt;9&lt;\/li&gt;\r\n\t\t&lt;li&gt;8&lt;\/li&gt;\r\n\t\t&lt;li&gt;7&lt;\/li&gt;\r\n\t\t&lt;li&gt;6&lt;\/li&gt;\r\n\t\t&lt;li&gt;5&lt;\/li&gt;\r\n\t\t&lt;li&gt;4&lt;\/li&gt;\r\n\t\t&lt;li&gt;3&lt;\/li&gt;\r\n\t\t&lt;li&gt;2&lt;\/li&gt;\r\n\t\t&lt;li&gt;1&lt;\/li&gt;\r\n\t&lt;\/ol&gt;\r\n\t&lt;ol&gt;\r\n\t\t&lt;li&gt;0&lt;\/li&gt;\r\n\t&lt;\/ol&gt;\r\n&lt;\/div&gt;<\/pre>\n<p>There are three ordered lists that the countdown walks through. I could probably take this one step further and automate the numbers using counter-increments, but for this example, I included all numbers in the HTML. The first ordered list contains all of the numbers for the tens decimal place, the second contains the ones, and the last contains the zero we\u2019ll flash repeatedly to indicate that the countdown has completed.<\/p>\n<p>First, I had to figure out how to rotate through each set of numbers. With the exception of the initial \u201c6\u2033, our tens would need to change every ten seconds. That first \u201c6\u2033 which would only flash for one second at the beginning of the countdown, which we\u2019ll get to in a second.<\/p>\n<pre>.tens li:nth-of-type(2) {\r\n\t-webkit-animation: tencount 60s ease-in-out 1s 1;\r\n\t-moz-animation:\t   tencount 60s ease-in-out 1s 1; \r\n\t-o-animation: \t   tencount 60s ease-in-out 1s 1; \r\n\t-ms-animation:\t   tencount 60s ease-in-out 1s 1; \r\n}\r\n.tens li:nth-of-type(3) {\r\n\t-webkit-animation: tencount 60s ease-in-out 11s 1;\r\n\t-moz-animation:\t   tencount 60s ease-in-out 11s 1; \r\n\t-o-animation: \t   tencount 60s ease-in-out 11s 1; \r\n\t-ms-animation:\t   tencount 60s ease-in-out 11s 1; \r\n}\r\n...<\/pre>\n<p>\u2026 and so on and so forth for each list item in the first ordered list. The above says that the element will use the \u201ctencount\u201d animation for 60 seconds, an \u201cease-in-out\u201d timing function for the keyframes\u2019 animation that will start at a particular second of the animation (1 seconds, 11 seconds, etc.) and only animate once. Here are the keyframes for my \u201ctencount\u201d animation:<\/p>\n<pre>@keyframes tencount {\r\n\t0% { opacity: 1 }\r\n\t16.6% { opacity: 1 }\r\n\t16.7% { opacity: 0 }\r\n\t100% { opacity: 0 }\r\n}<\/pre>\n<p>At the beginning of the animation, the digit will be at 100% opacity. At 16.6% (10 seconds), it will remain at 100% opacity, but a moment later will be invisible through the end of the animation (60 seconds). The only odd part of the CSS animations for this first ordered list is that the first digit \u201c6\u2033 only gets shown for one second, so I used our next animation style \u201cdigitcount\u201d to show it for one second.<\/p>\n<pre>.tens li:nth-of-type(1) {\r\n \t-webkit-animation: digitcount 10s ease-in-out 0s 1;\r\n\t-moz-animation:\t   digitcount 10s ease-in-out 0s 1; \r\n\t-o-animation: \t   digitcount 10s ease-in-out 0s 1; \r\n\t-ms-animation:\t   digitcount 10s ease-in-out 0s 1; \r\n}<\/pre>\n<p>I use the same animation for the next ordered list, but changed the number of times the animation will occur (6 instead of 1).<\/p>\n<pre>.digits li:nth-of-type(1) {\r\n\t-webkit-animation: digitcount 10s ease-in-out 0s 6; \r\n\t-moz-animation:\t   digitcount 10s ease-in-out 0s 6; \r\n\t-o-animation: \t   digitcount 10s ease-in-out 0s 6; \r\n\t-ms-animation:\t   digitcount 10s ease-in-out 0s 6; \r\n}\r\n.digits li:nth-of-type(2) {\r\n\t-webkit-animation: digitcount 10s ease-in-out 1s 6; \r\n\t-moz-animation:\t   digitcount 10s ease-in-out 1s 6; \r\n\t-o-animation: \t   digitcount 10s ease-in-out 1s 6; \r\n\t-ms-animation:\t   digitcount 10s ease-in-out 1s 6; \r\n}\r\n...<\/pre>\n<p>\u2026 and so on for each item in this ordered list. These list items will be repeating over and over until all of the tens have run out. The \u201cdigitcount\u201d CSS animation has a similar set of keyframes to the \u201ctencount\u201d animation, but \u201cdigitcount\u201d is only 10 seconds long instead of 60, so we change opacity at the 1 second mark (10% of the total animation time).<\/p>\n<pre>@keyframes digitcount {\r\n\t0% { opacity: 1 }\r\n\t9.9% { opacity: 1 }\r\n\t10% { opacity: 0 }\r\n\t100% { opacity: 0 }\r\n}<\/pre>\n<p>This leaves us with one more ordered list to animate: the zero that flashes when the countdown ends!<\/p>\n<pre>.done li {\r\n\t-webkit-animation: zero 1s ease-in-out 60s infinite; \r\n\t-moz-animation:\t   zero 1s ease-in-out 60s infinite; \r\n\t-o-animation:\t   zero 1s ease-in-out 60s infinite; \r\n\t-ms-animation:\t   zero 1s ease-in-out 60s infinite; \r\n}\r\n\r\n@keyframes zero {\r\n\t0% { opacity: 1 }\r\n\t90% { opacity: 1 }\r\n\t100% { opacity: 0 }\r\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Below is the HTML markup for the clock and the explanation for my methods. &nbsp; &lt;div&gt; &lt;ol&gt; &lt;li&gt;6&lt;\/li&gt; &lt;li&gt;5&lt;\/li&gt; &lt;li&gt;4&lt;\/li&gt; &lt;li&gt;3&lt;\/li&gt; &lt;li&gt;2&lt;\/li&gt; &lt;li&gt;1&lt;\/li&gt; &lt;\/ol&gt; &lt;ol&gt; &lt;li&gt;0&lt;\/li&gt; &lt;li&gt;9&lt;\/li&gt; &lt;li&gt;8&lt;\/li&gt; &lt;li&gt;7&lt;\/li&gt; &lt;li&gt;6&lt;\/li&gt; &lt;li&gt;5&lt;\/li&gt; &lt;li&gt;4&lt;\/li&gt; &lt;li&gt;3&lt;\/li&gt; &lt;li&gt;2&lt;\/li&gt; &lt;li&gt;1&lt;\/li&gt; &lt;\/ol&gt; &lt;ol&gt; &lt;li&gt;0&lt;\/li&gt; &lt;\/ol&gt; &lt;\/div&gt; There are three ordered lists that the countdown walks through. I could probably take this [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0},"categories":[5,7],"tags":[],"_links":{"self":[{"href":"https:\/\/a1webdesignteam.com\/blog\/wp-json\/wp\/v2\/posts\/222"}],"collection":[{"href":"https:\/\/a1webdesignteam.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/a1webdesignteam.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/a1webdesignteam.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/a1webdesignteam.com\/blog\/wp-json\/wp\/v2\/comments?post=222"}],"version-history":[{"count":0,"href":"https:\/\/a1webdesignteam.com\/blog\/wp-json\/wp\/v2\/posts\/222\/revisions"}],"wp:attachment":[{"href":"https:\/\/a1webdesignteam.com\/blog\/wp-json\/wp\/v2\/media?parent=222"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/a1webdesignteam.com\/blog\/wp-json\/wp\/v2\/categories?post=222"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/a1webdesignteam.com\/blog\/wp-json\/wp\/v2\/tags?post=222"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}