<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Wayne Pan &#187; css animations</title>
	<atom:link href="http://waynepan.com/tag/css-animations/feed/" rel="self" type="application/rss+xml" />
	<link>http://waynepan.com</link>
	<description>tech &#124; js &#124; ui &#124; ajax &#124; mobile</description>
	<lastBuildDate>Fri, 03 Sep 2010 22:16:55 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Dissecting Safari 4&#8242;s Welcome Screen</title>
		<link>http://waynepan.com/2009/03/11/dissecting-safari-4s-welcome-screen/</link>
		<comments>http://waynepan.com/2009/03/11/dissecting-safari-4s-welcome-screen/#comments</comments>
		<pubDate>Thu, 12 Mar 2009 06:53:49 +0000</pubDate>
		<dc:creator>Wayne</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[css animations]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[safari]]></category>

		<guid isPermaLink="false">http://waynepan.com/?p=340</guid>
		<description><![CDATA[If you&#8217;ve downloaded Safari 4 Beta then you&#8217;ve seen a very cool welcome screen. If you haven&#8217;t seen it click the video above (or if you&#8217;re running Safari 4 you can view it again here). I was curious as to &#8230; <a href="http://waynepan.com/2009/03/11/dissecting-safari-4s-welcome-screen/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><object width="476" height="235"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=3591822&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=00ADEF&amp;fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=3591822&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=00ADEF&amp;fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="476" height="235"></embed></object></p>
<p>If you&#8217;ve downloaded <a href="http://www.apple.com/safari/">Safari 4 Beta</a> then you&#8217;ve seen a very cool welcome screen. If you haven&#8217;t seen it click the video above (or if you&#8217;re running Safari 4 you can view it again <a href="http://www.apple.com/safari/welcome/">here</a>). I was curious as to how this page was put together so I did some dissecting&#8230; </p>
<p><b>HTML 5</b> &#8211; Cleverly, Apple decided to use HTML5 and the &lt;audio&gt; and &lt;video&gt; tags for the sound effects and part of the animation. The only part that is a full blown .mov is the ending compass sequence. <a href="http://images.apple.com/safari/welcome/media/compass.mov">Here is the .mov.</a></p>
<p><b>CSS Animation</b> &#8211; The first 2 animations, the Apple logo (plus lens flare) and the <i>Welcome to Safari 4</i> are achieved by a combination of CSS animations (<a href="http://images.apple.com/safari/welcome/styles/safari.css">stylesheet</a>) and a series of images. </p>
<p>The <i>Welcome to Safari 4</i>, is the simplest of the 2. It uses this image:<br />
<a href="http://images.apple.com/safari/welcome/images/header.jpg"> <img src="http://waynepan.com/wp-content/uploads/2009/03/header.jpg" alt="header" title="header" width="300" height="30" class="alignnone size-full wp-image-351" /></a><br />
&#8230; and this scaling animation rule:</p>
<pre class='brush:css'>@-webkit-keyframes header {
	from {
		opacity: 0;
		-webkit-transform: scale(2.6);
		-webkit-animation-timing-function: linear;
	}
	20% {
		opacity: 1;
		-webkit-transform: scale(1);
		-webkit-animation-timing-function: linear;
	}
	77% {
		opacity: 1;
		-webkit-transform: scale(0.9);
		-webkit-animation-timing-function: linear;
	}
	to {
		opacity: 0;
		-webkit-transform: scale(0.1);
		-webkit-animation-timing-function: linear;
	}
}
</pre>
<p>The Apple logo animation is bit more tricky and is achieved with these four images:<br />
<a href="http://images.apple.com/safari/welcome/images/apple_icon.png"><img src="http://waynepan.com/wp-content/uploads/2009/03/apple_icon.png" alt="apple_icon" title="apple_icon" width="50" height="78" class="alignnone size-full wp-image-348" /></a> <a href="http://images.apple.com/safari/welcome/images/apple_flare.jpg"><img src="http://waynepan.com/wp-content/uploads/2009/03/apple_flare.jpg" alt="apple_flare" title="apple_flare" width="50" height="50" class="alignnone size-full wp-image-350" /></a> <a href="http://images.apple.com/safari/welcome/images/apple_spots.png"><img src="http://waynepan.com/wp-content/uploads/2009/03/apple_spots.png" alt="apple_spots" title="apple_spots" width="50" height="55" class="alignnone size-full wp-image-349" /></a> <a href="http://images.apple.com/safari/welcome/images/apple_flare_icon.png"><img src="http://waynepan.com/wp-content/uploads/2009/03/apple_flare_icon.png" alt="apple_flare_icon" title="apple_flare_icon" width="50" height="62" class="alignnone size-full wp-image-347" /></a><br />
&#8230; plus 4 different css animation rules that are similar to the rule above but each image&#8217;s opacity is changed from 0 to 1 at the appropriate time. </p>
<p><b>Works on an iPhone</b> &#8211; What&#8217;s more impressive is that this page more or less works on an iPhone! The .mov and audio do not play, but everything animations properly. I removed the javascript that disables the page for non-Safari 4 browsers and put it here <a href="http://waynepan.com/s/safari4">http://waynepan.com/s/safari4</a>.</p>
<p><b>Bonus!</b> &#8211; At the end of all the animation, the page redirects you to <a href="topsites://">topsites://</a>, which of course takes you to Top Sites.</p>
<p>The Safari Welcome screen is a peak into the future. It shows us what&#8217;s possible when you get to throw all backwards compatibility concerns out the window&#8230; (no pun intended.)</p>
]]></content:encoded>
			<wfw:commentRss>http://waynepan.com/2009/03/11/dissecting-safari-4s-welcome-screen/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
<enclosure url="http://images.apple.com/safari/welcome/media/compass.mov" length="129258" type="video/quicktime" />
		</item>
		<item>
		<title>iPhone CSS Animations Thoughts and Issues</title>
		<link>http://waynepan.com/2008/08/08/iphone-css-animations-thoughts-and-issues/</link>
		<comments>http://waynepan.com/2008/08/08/iphone-css-animations-thoughts-and-issues/#comments</comments>
		<pubDate>Sat, 09 Aug 2008 00:29:22 +0000</pubDate>
		<dc:creator>Wayne</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[css animations]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[safari]]></category>

		<guid isPermaLink="false">http://waynepan.com/?p=151</guid>
		<description><![CDATA[I&#8217;ve been doing a lot of work with the iPhone lately and I&#8217;ve been holding back on blogging about my experiences because I&#8217;m unclear as to the damn NDA stipulations. NDA be damn, here&#8217;s a first in a series of &#8230; <a href="http://waynepan.com/2008/08/08/iphone-css-animations-thoughts-and-issues/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been doing a lot of work with the iPhone lately and I&#8217;ve been holding back on blogging about my experiences because I&#8217;m unclear as to the damn NDA stipulations. NDA be damn, here&#8217;s a first in a series of posts!</p>
<p>If you aren&#8217;t familiar with the new animation framework that&#8217;s built into Mobile Safari you can read about the closest thing on WebKit, <a href="http://webkit.org/blog/138/css-animation/">CSS transitions</a>. Here is an example of a CSS transition:</p>
<pre>
&lt;div style="-webkit-transition: opacity 2s ease-in"
  onclick="this.style.opacity='0'"&gt;
This div will do a fade when clicked only Safari 3.1 or on the iPhone!
&lt;/div&gt;
</pre>
<div style="-webkit-transition: opacity 2s ease-in; border: 1px blue dashed" onclick="this.style.opacity='0'">This div will do a fade when clicked Safari 3.1 or on the iPhone</div>
<p>Essentially you tie a timing function and duration when a css property is changed. CSS animations allow for more complex rule transitions. For example, if you want to have a card flipping effect show in this video, you will need to use CSS animations.<br />
<object width="325" height="244"><param name="movie" value="http://www.youtube.com/v/hM07-L0C48A&#038;hl=en&#038;fs=1"></param><param name="allowFullScreen" value="true"></param><embed src="http://www.youtube.com/v/hM07-L0C48A&#038;hl=en&#038;fs=1" type="application/x-shockwave-flash" allowfullscreen="true" width="325" height="244"></embed></object><br />
<span id="more-151"></span><br />
CSS animations consist of a combination of 2 rules, one to define the animation timing, duration, and animation name. The second to define the actual animation.  </p>
<pre>
/* the following rules make something shrink from 50px */
/* to 10px then grow to 100px in 2 seconds */
.shrink-n-grow {
  -webkit-animation-name: 'shrink-n-grow-animation';
  -webkit-animation-timing-function: ease-in-out;
  -webkit-animation-duration: 2s;
}

@-webkit-keyframes shrink-n-grow-animation {
  from {
    height: 50px;
  }
  50% {
    height: 10px;
  }
  to {
    height: 100px;
  }
}
</pre>
<p>There are a few issues with the Mobile Safari CSS animation implementation and I urge Mozilla, the IE team, Opera, and W3C to consider these before writing their own spec.</p>
<h4>CSS means no syntax checking</h4>
<p><a href="http://snook.ca/archives/javascript/css_animations_in_safari/">Jonathan Snook</a> wrote about this last year and until I actually started using them I didn&#8217;t feel the pain. Since all the rules are written in CSS there is no error checking. Figuring out that you&#8217;re animation is broken because you misspelled -webkit-transition: is painful enough. When you start working with perspectives for translateZ, it will drive you utterly insane.</p>
<h4>Access through javascript problematic</h4>
<p>Also, because the rules live in CSS world, modifying existing rules on the fly in javascript requires you to use this ridiculous function to scan through CSS rules and find the one you want and then modifying a value.</p>
<pre>
  var findAnimation = function(name) {
      var ret_rule = null, sheets = document.styleSheets;
      for(var i = sheets.length - 1; i >= 0 ; i--) {
        var sheet = sheets[i];
          for(var j = sheet.cssRules.length - 1; j >= 0; j--) {
            var rule = sheet.cssRules[j];
              // 7 means the keyframe rule
              if(rule.type === 7 &#038;&#038; rule.name == name) {
                ret_rule = rule;
                break;
              }
            }
      }
      return ret_rule;
    }
  findAnimation('shrink-n-grow-animation').findRule(
     '50%').style.height = '25px'
</pre>
<h4>Needlessly complicated</h4>
<p>To use an animation, not only do you have to apply the final value of the animation if you want it to stick, but you have to perform some software olympics. </p>
<pre>
  // Add shrink-n-grow animation to a div
  var remove = function() { // we'll need this later
    // first, set final values
    theDiv.style.height = '100px';
    // then remove shrink-n-grow classname so that
    // it can be applied again animations are only
    // triggered when classnames are first applied
    theDiv.className = '';
    // remove this listener because webkitAnimationEnd
    // is triggered on every time ANY animation ends on theDiv
    theDiv.removeEventListener('webkitAnimationEnd', remove);
  };
  // listen for animation end
  theDiv.addEventListener('webkitAnimationEnd', remove);
  /// FINALLY, start the animation animation
  theDiv.className = 'shrink-n-grow';
</pre>
<p>That is just way too much code.</p>
<p>My personal preference is to have everything accessible in javascript so that the entire workflow of animation can live in javascript (instead of just modifying styles).</p>
]]></content:encoded>
			<wfw:commentRss>http://waynepan.com/2008/08/08/iphone-css-animations-thoughts-and-issues/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
