{"id":170,"date":"2015-10-07T21:36:37","date_gmt":"2015-10-08T04:36:37","guid":{"rendered":"http:\/\/courses.haigarmen.com\/desn315\/?p=170"},"modified":"2015-10-07T21:43:17","modified_gmt":"2015-10-08T04:43:17","slug":"css-animations","status":"publish","type":"post","link":"https:\/\/courses.haigarmen.com\/desn315\/css-animations\/","title":{"rendered":"CSS Transitions &#038; Animations"},"content":{"rendered":"<p>There are a number of ways of achieving animations with CSS3:<br \/>\n1. Transitions<br \/>\n2. Animations<\/p>\n<p><strong>Similarities<\/strong><br \/>\nIf you&#8217;re not looking too closely both transitions and animations look similar. They both allow you to:<\/p>\n<ul>\n<li>Specify which CSS properties to listen for changes on<\/li>\n<li>Set timing (easing) functions to alter the rate of going from a one property value to another<\/li>\n<li>Specify a duration to control how long the animation or transition will take<\/li>\n<li>Programmatically listen to animation and transition-specific events that you can then do with as you wish<\/li>\n<li>Visualize CSS property changes.<\/li>\n<\/ul>\n<h3>Differences<\/h3>\n<p>Once you understand the differences it becomes easier to decide which technique to use as each excels at different things.<\/p>\n<h4>Triggering<\/h4>\n<p>One of the major differences between animations and transitions can be seen in how you trigger them to start playing.<\/p>\n<p>A transition only plays as a reaction to a CSS property that has changed. A common scenario is one where you use the :hover pseudo class to change the value of a CSS property:<\/p>\n<p>example of hovering to make something larger<\/p>\n<p>To use the example visualized here, if a transition is defined, you would be able to see the circle growing from its normal size to its hover size. Another way of triggering a transition is to use JavaScript to programmatically add or remove CSS classes to simulate a CSS property change. Rounding out our ways of making a property change, you can use JavaScript to set an inline style that changes a property your transition is listening for.<\/p>\n<p>Animations, on the other hand, don&#8217;t require any explicit triggering. Once you define the animation, it will start playing automatically. Yep, that&#8217;s how animations roll!<\/p>\n<h4>Looping<\/h4>\n<p>This is pretty simple. Animations can be easily made to loop by setting the animation-iteration-count property. You can specify a fixed number of times you want your animation to repeat:<\/p>\n<p>animation-iteration-count: 5;<br \/>\nIf you just want your animation to loop forever, you can do that as well:<\/p>\n<p>animation-iteration-count: infinite;<br \/>\nTransitions, on the other hand, don&#8217;t have a property that specifies how many times they can run. When triggered, a transition runs only once. You can make a transition loop by fiddling with the transitionEnd event, but that isn&#8217;t particularly straightforward &#8211; especially when compared with animations.<\/p>\n<p>Defining Intermediate Points \/ Keyframes<br \/>\nWith an animation, you have the ability to define keyframes which give you more control over your CSS property values beyond just the start and the end:<\/p>\n<h4>animations FTW<\/h4>\n<p>You can set as many keyframes as you want, and when your animation plays, each keyframe will be hit with the specified property changes reflected. This allows you to create the kinds of involved animations that help HTML5 compete with more established animation technologies like Flash more effectively.<\/p>\n<p>With a transition, you don&#8217;t have much control over anything beyond the end result:<\/p>\n<h4>transitions are linear<\/h4>\n<p>A transition simply goes from an initial state to the final state. You cannot specify any points in-between like you can with an animation, so a transition might not be a good choice if you are trying to create the next Teen Girl Squad sensation or a complex animation.<\/p>\n<h4>Specifying Properties Up-Front<\/h4>\n<p>The next thing I will describe is how formal animations and transitions are when it comes to defining a transition between CSS property values.<\/p>\n<p>On the formal side, you have transitions. Every CSS property you want recognized by your transition must be explicitly represented.<\/p>\n<p>For example, let&#8217;s say you have something like the following:<\/p>\n<p>#mainContent {<br \/>\nbackground-color: #CC0000;<br \/>\ntransition:background-color .5s ease-in;<br \/>\n}<br \/>\n#mainContent:hover {<br \/>\ncursor: pointer;<br \/>\nbackground-color: #000000;<br \/>\nwidth:500px;<br \/>\n}<br \/>\nUpon hover, I specify a different value for both background-color as well as width. My transition specifies only background-color though. This means your browser is only listening for changes on the background-color property.<\/p>\n<p>If I wanted my transition to affect both the background-color and width properties, I will need to explicitly add another transition entry for width:<\/p>\n<p>#mainContent {<br \/>\nbackground-color: #CC0000;<br \/>\ntransition:background-color .5s ease-in, width .5s ease-in<br \/>\n}<br \/>\n#mainContent:hover {<br \/>\ncursor: pointer;<br \/>\nbackground-color: #000000;<br \/>\nwidth: 500px;<br \/>\n}<\/p>\n<h3>Resources<\/h3>\n<p>Here&#8217;s some examples we went over:<\/p>\n<p><a href=\"http:\/\/www.webdesignerdepot.com\/2014\/05\/8-simple-css3-transitions-that-will-wow-your-users\/\">\u00a08 Simple Transitions<br \/>\n<\/a><a href=\"http:\/\/learn.shayhowe.com\/advanced-html-css\/transitions-animations\/\">Transitions vs Animations<br \/>\n<\/a><a href=\"http:\/\/www.webanddesigners.com\/25-best-css3-animation-tutorials-to-enhance-the-look-of-a-website\/\">25 CSS3 Animation techniques<\/a><\/p>\n<p><a title=\"CSS Animation\" href=\"http:\/\/courses.haigarmen.com\/wp-content\/uploads\/2014\/09\/index.html\">Kathleen&#8217;s CSS Animation Click Here<\/a><\/p>\n<p><a title=\"Animatable\" href=\"http:\/\/leaverou.github.io\/animatable\/\">CSS Animatable<\/a><br \/>\n<a title=\"http:\/\/www.cssanimate.com\/\" href=\"http:\/\/www.cssanimate.com\/\">http:\/\/www.cssanimate.com\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>There are a number of ways of achieving animations with CSS3: 1. Transitions 2. Animations Similarities If you&#8217;re not looking too closely both transitions and animations look similar. They both allow you to: Specify which CSS properties to listen for changes on Set timing (easing) functions to alter the rate of going from a one [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-170","post","type-post","status-publish","format-standard","hentry","category-exercises"],"_links":{"self":[{"href":"https:\/\/courses.haigarmen.com\/desn315\/wp-json\/wp\/v2\/posts\/170","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/courses.haigarmen.com\/desn315\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/courses.haigarmen.com\/desn315\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/courses.haigarmen.com\/desn315\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/courses.haigarmen.com\/desn315\/wp-json\/wp\/v2\/comments?post=170"}],"version-history":[{"count":8,"href":"https:\/\/courses.haigarmen.com\/desn315\/wp-json\/wp\/v2\/posts\/170\/revisions"}],"predecessor-version":[{"id":211,"href":"https:\/\/courses.haigarmen.com\/desn315\/wp-json\/wp\/v2\/posts\/170\/revisions\/211"}],"wp:attachment":[{"href":"https:\/\/courses.haigarmen.com\/desn315\/wp-json\/wp\/v2\/media?parent=170"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/courses.haigarmen.com\/desn315\/wp-json\/wp\/v2\/categories?post=170"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/courses.haigarmen.com\/desn315\/wp-json\/wp\/v2\/tags?post=170"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}