{"id":575,"date":"2012-09-19T14:27:28","date_gmt":"2012-09-19T14:27:28","guid":{"rendered":"http:\/\/a.parsons.edu\/~dejongo\/12-fall\/?p=575"},"modified":"2012-09-19T14:27:28","modified_gmt":"2012-09-19T14:27:28","slug":"10-css3-animation","status":"publish","type":"post","link":"https:\/\/b.parsons.edu\/~dejongo\/10-css3-animation\/","title":{"rendered":"10 CSS3 Animation"},"content":{"rendered":"<p>Apple&#8217;s Webkit team has introduced a number of technologies, one of which is <a href=\"http:\/\/www.w3.org\/TR\/css3-animations\/\">CSS Animations<\/a>, which allow an author to modify CSS property values over time. This is an evolving specification. Expect lots of changes as time goes by.\n<\/p>\n<p>The good news is that animations are hardware accelerated. The computer&#8217;s graphic chip will be doing the heavy lifting, and not the CPU. This should speed animations up from the start.\n<\/p>\n<p>Involved animations are complicated, and I&#8217;m sure that the future will develop all kinds of tools that will help facilitate building more complicated animations. To that end, there are several programs targeting the creation of CSS animations, primarily targeting the building of ads without using Flash, including <a href=\"http:\/\/www.sencha.com\/blog\/sencha-animator-released\">Sencha&#8217;s Animator<\/a>, Adobe&#8217;s <a href=\"http:\/\/labs.adobe.com\/technologies\/edge\/?sdid=JAXXJ&#038;skwcid=TC|23230|adobe%20edge||S|b|9263245986\">Edge<\/a> and <a href=\"http:\/\/animatable.com\/\">andy<\/a> <a href=\"http:\/\/animatable.com\/demos\/madmanimation\/\">clarke<\/a>.  Be aware that most of these solutions rely on javascript for their animations, but since the program is writing the code, all you need to deal with is a timeline interface. <\/p>\n<h2>@Keyframe<\/h2>\n<\/p>\n<p>You have seen these @ rules used before, in @media, @font-face and @import. At-rules are instructions or directives to the CSS parser. The <code>@keyframe<\/code> contains the keyframes of the animation. The way to write it is: <\/p>\n<pre>\r\n@-webkit-keyframes name-for-animation {\r\n  \/* RULE SETS *\/\r\n}\r\n<\/pre>\n<\/p>\n<p>In between the brackets are the rule sets, which always start with the start and stop keyframes: <code>from<\/code> or 0% and <code>to<\/code> or 100%. The entire keyframe at rule looks like:<\/p>\n<pre>\r\n@-webkit-keyframes name-for-animation {\r\n   0% \/* from *\/{\r\n   }\r\n   100% \/* to *\/ {\r\n   }\r\n}\r\n<\/pre>\n<\/p>\n<p>All other reframes come between the start and end, and you can use <code>from<\/code> and <code>to<\/code>, or <code>0%<\/code> and <code>100%<\/code> keyframes. To make it work, however, you also need to include the animation name as a quality of the animation property.\n<\/p>\n<p>In the demo below, the div with and id of &#8220;ani-1&#8221; contains the animation property shorthand that calls up the keyframe at rule. Within this property we\u2019re specifying the name of the animation <code>animation-name: name-for-animation<\/code>,  to specify which keyframes to use, the duration, <code>animation-duration: 10s<\/code>,  the timing function: <code>animation-timing-function: linear<\/code> and the number of times to repeat the keyframes <code>animation-iteration-count: infinite<\/code>. There is also a direction property <code>animation-direction: normal<\/code>, and the possibility to set a delay <code>animation-delay: 0<\/code>. \u00a0\n<\/p>\n<p> You can change the animation, but to get the demo to register the changes, you need to temporarily change the keyframe name in the animation property, and then change it back, and it will recognize any changes you&#8217;ve made to the keyframes, otherwise it will continue on its previously determined course. The animation is set up for webkit only.<\/p>\n<div class=\"handson_demo\">\n<h3>CSS Code View<\/h3>\n<pre>\r\n<style contenteditable=\"true\">\r\n@-webkit-keyframes name-for-animation {\r\n\t0%  {  top: 30px; left: 100%; }\r\n\t10% { top: 100px; left: 90%;   }\r\n\t20% { top: \u2212200px; left: 80%;   }\r\n\t30% { top: 100px; left: 70%;   \r\n\twidth: 20px; height: 20px;\r\n\tborder-width: 100px; \r\n}\r\n\t40% { top: \u2212200px; left: 60%;  \r\n\twidth: 200px; height: 200px;\r\n\tborder-radius: 100%;\r\n\tborder-width: 0px; \r\n}\r\n\t50% { top: 50px; left: 50%;   \r\n\twidth: 20px; height: 20px;\r\n\tborder-radius: 0%;\r\n\tborder-width: 100px; \r\n}\r\n\t60% { top: \u2212200px; left: 40%;   }\r\n\t70% { top: 200px; left: 30%;   }\r\n\t80% { top: -200px; left: 20%;   }\r\n\t90% { top: 500px; left: 10%;   }\r\n\t100% { top: 30px; left: -10%; }\r\n}\r\n#ani-1 {\t\r\n-webkit-animation: name-for-animation 10s linear infinite;\r\nposition: absolute;\r\ntop: 30px;\r\nleft: 100%;\r\nz-index: 50;\r\nwidth: 20px;\r\nheight: 20px;\r\nbackground: red;\r\nborder: 4px solid yellow;\r\ntext-overflow: hidden;\r\ntext-align: center;\r\n}\r\n<\/style><\/pre>\n<\/div>\n<div style=\"position: relative\">\n<div id=\"ani-1\"><\/div>\n<\/div>\n<p>Animation is in its infancy, and the specification will evolve and probably change several times before it settles down, but it&#8217;s actively being implemented by all major browsers, so its here to stay. If you want to pursue CSS animations, check out <a href=\"http:\/\/css3animator.com\/\">CSS3 Animator<\/a> for a great resource.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Apple&#8217;s Webkit team has introduced a number of technologies, one of which is CSS Animations, which allow an author to modify CSS property values over time. This is an evolving specification. Expect lots of changes as time goes by. The &hellip; <a href=\"https:\/\/b.parsons.edu\/~dejongo\/10-css3-animation\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[15],"tags":[],"_links":{"self":[{"href":"https:\/\/b.parsons.edu\/~dejongo\/wp-json\/wp\/v2\/posts\/575"}],"collection":[{"href":"https:\/\/b.parsons.edu\/~dejongo\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/b.parsons.edu\/~dejongo\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/b.parsons.edu\/~dejongo\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/b.parsons.edu\/~dejongo\/wp-json\/wp\/v2\/comments?post=575"}],"version-history":[{"count":1,"href":"https:\/\/b.parsons.edu\/~dejongo\/wp-json\/wp\/v2\/posts\/575\/revisions"}],"predecessor-version":[{"id":576,"href":"https:\/\/b.parsons.edu\/~dejongo\/wp-json\/wp\/v2\/posts\/575\/revisions\/576"}],"wp:attachment":[{"href":"https:\/\/b.parsons.edu\/~dejongo\/wp-json\/wp\/v2\/media?parent=575"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/b.parsons.edu\/~dejongo\/wp-json\/wp\/v2\/categories?post=575"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/b.parsons.edu\/~dejongo\/wp-json\/wp\/v2\/tags?post=575"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}