<?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>stchur-BLOG &#187; Animation</title>
	<atom:link href="http://blog.stchur.com/category/animation/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.stchur.com</link>
	<description>web / programming / javascript / css / html</description>
	<lastBuildDate>Sat, 16 Jan 2010 01:09:03 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Fresh Nuggets of Gimme Awesomeness</title>
		<link>http://blog.stchur.com/2008/04/01/fresh-nuggets-of-gimme-awesomeness/</link>
		<comments>http://blog.stchur.com/2008/04/01/fresh-nuggets-of-gimme-awesomeness/#comments</comments>
		<pubDate>Tue, 01 Apr 2008 20:58:45 +0000</pubDate>
		<dc:creator>sstchur</dc:creator>
				<category><![CDATA[Advanced Javascript]]></category>
		<category><![CDATA[Animation]]></category>
		<category><![CDATA[Gimme]]></category>

		<guid isPermaLink="false">http://blog.stchur.com/2008/04/01/fresh-nuggets-of-gimme-awesomeness/</guid>
		<description><![CDATA[	Some really cool stuff happening with Gimme lately, especially with regards to its animation capabilities.
	I whipped together something that started off (in my head anyway) as a sort of copy of CoverFlow on Mac OS.  However, before I was finished, it had morphed into a general purpose animation-along-an-arbitrary-path-type-routine.
	This code isn't yet checked into the [...]]]></description>
			<content:encoded><![CDATA[	<p>Some really cool stuff happening with Gimme lately, especially with regards to its animation capabilities.</p>
	<p>I whipped together something that started off (in my head anyway) as a sort of copy of CoverFlow on Mac OS.  However, before I was finished, it had morphed into a general purpose animation-along-an-arbitrary-path-type-routine.</p>
	<p>This code isn't yet checked into the repository, but for anyone who is interested in taking a look, here are two different demo pages to see the "bleeding edge" of what is going on with Gimme:</p>
	<ul>
	<li><a href = "http://gimme.stchur.com/gimmeflow4.html" title = "Animation along an arbitrary path using Gimme">Animation along an arbitrary path using Gimme</a></li>
	<li><a href = "http://gimme.stchur.com/animationdemo.html" title = "Gimme Animation Demo Page">Gimme Animation Demo Page</a></li>
	</ul>
	<p>There are a few things worth nothing.  The first link is a really quick-n-dirty prototype, so there are bound to be bugs.  The page takes a few seconds to load as it is pulling remote photos from my Spaces photo album.  You'll have to wait until everything is loaded and in place to try out the demo.  Just click on any image and you'll get the idea.  You can also change the shape of the curve that the images follow by clicking on the "S Shape" button.</p>
	<p>The second link is a general animation demo page.  By providing a set of Bezier control points (comma separated coordinates / spaces separated points), you can instruct the script to plot any curve and then have the red block follow that curve.  You can also chose the AccelerationLine you want to use with the animation (note that Linear is a bad name, and should really be None -- I will fix this one day).</p>
	<p>You can even use the text area on the right side of the page to execute arbitrary custom code.  I've provided a sample that animates the red block counter-clockwise around an ellipse 2 and 1/2 times.</p>
	<p>As you can see, it doesn't take much code at all to achieve some fairly sophisticated animation with Gimme.</p>
	<p>In a future blog entry, I hope to polish up this code and provide a deeper explanation of the samples (as well as get this code checked into the repository).</p>
	<p>Comments welcome</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.stchur.com/2008/04/01/fresh-nuggets-of-gimme-awesomeness/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Managing animations with Gimme (a fade demo)</title>
		<link>http://blog.stchur.com/2007/07/22/managing-animations-with-gimme-a-fade-demo/</link>
		<comments>http://blog.stchur.com/2007/07/22/managing-animations-with-gimme-a-fade-demo/#comments</comments>
		<pubDate>Mon, 23 Jul 2007 05:09:26 +0000</pubDate>
		<dc:creator>sstchur</dc:creator>
				<category><![CDATA[Animation]]></category>
		<category><![CDATA[Gimme]]></category>

		<guid isPermaLink="false">http://stchur.com/blog2/2007/07/22/managing-animations-with-gimme-a-fade-demo/</guid>
		<description><![CDATA[	Animation can be a tricky business in Javascript, particularly if the animation is invoked by some user action (such as moving the mouse over an element).  Users cannot be trusted to behave in a calm, rational manner.  For instance, instead of clicking the mouse button just once, they'll click it 25 times.  [...]]]></description>
			<content:encoded><![CDATA[	<p>Animation can be a tricky business in Javascript, particularly if the animation is invoked by some user action (such as moving the mouse over an element).  Users cannot be trusted to behave in a calm, rational manner.  For instance, instead of clicking the mouse button just once, they'll click it 25 times.  Instead of pressing a key just once, they'll mash the key a dozen times in a row.  Instead of smoothly mousing from one element to the next, they'll frantically move the mouse around as though it's being chased by a hungry cat.</p>
	<p>If your animation is invoked by a user action like those described above, then there is good chance that the animation may come off looking sort of silly (at best) or even causing seizures (at worst).  I've written animations before, that didn't account for unpredictable user behavior, and the result was a chaotic mess of flickering DOM elements.  An animation to be sure, but not the one I was aiming for.</p>
	<p>No, users should not be trusted, and we should never fall into the trap of letting ourselves believe they can.  Of course, this makes our job as UI designers more difficult, but that's no reason to whimp out!</p>
	<h3>Gimme to the rescue</h3>
	<p>Gimme has an extension called Gimme Effects which, when combined with the Gimme Animation Module offers a sophisticated set of tools for creating and managing Javascript-based animations.  Besides several, useful, stock effects, Gimme also offers developers the ability to create custom animations quickly and easily (but that's another blog entry).</p>
	<h3>Focus on the fade!</h3>
	<p>One of the stock effects available in Gimme Effects is the fade (in, out, or to/from arbitrary values).  It's super easy to invoke a fade too.  Take the following:</p>
	<div class="dean_ch" style="white-space: nowrap;">g<span class="br0">&#40;</span><span class="st0">'#nav &gt; a'</span><span class="br0">&#41;</span>.<span class="me1">fadeOut</span><span class="br0">&#40;</span><span class="st0">'quickly'</span><span class="br0">&#41;</span>;</div>
	<p>This snippet quickly fades out all <code>&lt;a&gt;</code> elements that are direct children of the <code>#nav</code> element.  How quick is 'quickly'?  750 milliseconds to be precise, but you're not limited.  Pass in a keyword like 'quickly' or 'slowly', pass in a numeric value in milliseconds, or even pass in nothing at all (default is 'quickly'); Gimme will handle it all just fine.</p>
	<h3>Specifying more parameters</h3>
	<p>All animation effects in Gimme take at least 3 parameters (some take more).  These 3 parameters, which are all always optional are:</p>
	<ol>
	<li>duration: positive integer value indicating the duration of the animation in milliseconds.</li>
	<li>guid: a string value that uniquely identifies this animation (you'll see later, why this can be useful).  Note that this value can be null.</li>
	<li>callback: a function to be executed when the animation completes.</li>
	</ol>
	<p>Suppose I wanted to alert a message that the fade operation was done.  I could do the following:</p>
	<div class="dean_ch" style="white-space: nowrap;">g<span class="br0">&#40;</span><span class="st0">'#nav &gt; a'</span><span class="br0">&#41;</span>.<span class="me1">fadeOut</span><span class="br0">&#40;</span><span class="nu0">2000</span>, <span class="kw2">null</span>, <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span> <span class="kw3">alert</span><span class="br0">&#40;</span><span class="st0">'all done!'</span><span class="br0">&#41;</span>; <span class="br0">&#125;</span><span class="br0">&#41;</span>;</div>
	<p>There is a problem here though.  Remember back at the beginning of this post, I said that users could not be trusted to behave in calm and predictable ways?  Well, suppose the above code snippet is executed whenever the users clicks on a button that says "Fade the navigation."  What happens if the user clicks on that button 15 times in a rows?  The animation takes 2 full seconds to complete, so if the user invokes it 15 times, that's 15 <em>different</em> animation requests, all on the same DOM elements.</p>
	<p>The result will be a night-club-strobe-light-flickering effect that might give your users a seizure (or a head-ache at the very least).</p>
	<h3>Unique Animations with Gimme</h3>
	<p>With Gimme, it's pretty easy to avoid this kind of flickering.  You simply specify a GUID when invoking the animation, and this instructs  Gimme to make sure that an animation with the specified GUID is not already running.  If it is, the request to start the animation will be ignored until the animation is no longer running.  Take the following example:</p>
	<div class="dean_ch" style="white-space: nowrap;">
g<span class="br0">&#40;</span><span class="st0">'body'</span><span class="br0">&#41;</span>.<span class="me1">fadeOut</span><span class="br0">&#40;</span><span class="nu0">1000</span><span class="br0">&#41;</span>;<br />
g<span class="br0">&#40;</span><span class="st0">'body'</span><span class="br0">&#41;</span>.<span class="me1">fadeOut</span><span class="br0">&#40;</span><span class="nu0">500</span><span class="br0">&#41;</span>;</div>
	<p>The code above doesn't specify any GUID; the animations are not uniquely identified and therefore Gimme will happily attempt to execute both of them, even though they operate on the same element (the <code>&lt;body&gt;</code> element) and will cause flickering.</p>
	<p>One solution, is to give both animations the same GUID, as in:</p>
	<div class="dean_ch" style="white-space: nowrap;">
g<span class="br0">&#40;</span><span class="st0">'body'</span><span class="br0">&#41;</span>.<span class="me1">fadeOut</span><span class="br0">&#40;</span><span class="nu0">1000</span>, <span class="st0">'FADE'</span><span class="br0">&#41;</span>;<br />
g<span class="br0">&#40;</span><span class="st0">'body'</span><span class="br0">&#41;</span>.<span class="me1">fadeOut</span><span class="br0">&#40;</span><span class="nu0">500</span>, <span class="st0">'FADE'</span><span class="br0">&#41;</span>;</div>
	<p>When Gimme encounters the second <code>.fadeOut(..)</code> call, it will ignore it since an animation with the GUID "FADE" is already running.  Once the animation finishes though, it will once again be eligible for invocation.</p>
	<p> Of course, you wouldn't ever write code like what I've written above -- that was just to illustrate a point.  But think again about the possibility of a user repeatedly clicking a button to invoke some animation, and you'll see how the GUID can help.</p>
	<h3>Stopping an animation</h3>
	<p>The fact that Gimme can ignore subsequent requests to start an animation that already started is nice, but it begs the question: "what if I don't <em>want</em> to ignore subsequent requests?  What if I want subsequent requests to cause the currently running animation to abort in favor of the new request?"</p>
	<p>Gimme can do this too; it's just not the default behavior, so it take a couple extra lines of code on your part.  Nothing major though, and it's still super easy:</p>
	<div class="dean_ch" style="white-space: nowrap;">Gimme.<span class="me1">Animation</span>.<span class="me1">end</span><span class="br0">&#40;</span><span class="st0">'GUID'</span><span class="br0">&#41;</span>;</div>
	<p>This instructs Gimme to abruptly stop the animation uniquely identified by the GUID, "GUID" (not a very good name for a GUID by the way), provided it exists and is running.  Need to stop more than one animation at a time?  No problem; just pass in a comma delimited list of GUIDS as in:</p>
	<div class="dean_ch" style="white-space: nowrap;">Gimme.<span class="me1">Animation</span>.<span class="me1">end</span><span class="br0">&#40;</span><span class="st0">'FADEIN'</span>, <span class="st0">'FADEOUT'</span><span class="br0">&#41;</span>;</div>
	<p>Gimme will stop any animations that are uniquely identified by either "FADEIN" or "FADEOUT."</p>
	<p>It's worth noting that all animations have a GUID, even if you don't specify one.  For animations where you fail to specify a GUID, one is auto generated for you.  It's a good idea to specify your own though, as this allows you to manually stop the animation at will.</p>
	<h3>.fadeTo(startOpacity, endOpacity, duration, guid, callback)</h3>
	<p>Besides <code>.fadeIn(..)</code> and <code>.fadeOut(..)</code> (which are somewhat restrictive since they're "all or nothing"), Gimme also offer <code>.fadeTo(..)</code>.  This function works like its in/out couterparts, but it allows you to specify the starting and ending opacity for the fade.  As an added bonus, you can pass in <code>null</code> for either value. A <code>null</code> value for startOpacity indicates that you want the starting opacity to be the object's current opacity, while a <code>null</code> value for endOpacity means zero.</p>
	<p>For example:</p>
	<div class="dean_ch" style="white-space: nowrap;">g<span class="br0">&#40;</span><span class="st0">'#btn1'</span><span class="br0">&#41;</span>.<span class="me1">fadeTo</span><span class="br0">&#40;</span><span class="kw2">null</span>, .<span class="nu0">5</span>, <span class="st0">'slowly'</span>, <span class="st0">'PARTIAL_FADE'</span><span class="br0">&#41;</span>;</div>
	<p>This code snippet will fade the element, <code>#btn1</code> starting at its current opacity (which is most likely 1, but doesn't have to be) and decreasing to .5 (or 50%) opacity.</p>
	<h3>A working Gimme demo involving fade</h3>
	<p>To help tie everything I've been writing about together, I've created a snazzy little fade demo for all to enjoy.  In it there is a <code>#navigation</code> <code>&lt;div&gt;</code> with a few <code>&lt;button&gt;</code> elements inside of it.  Whenever the user mouses over a button, all <em>other</em> buttons should partially fade out.  When the user mouses out of the <code>#navigation</code> <code>&lt;div&gt;</code> completely, all buttons should return to their full opacity.</p>
	<p>With Gimme, this turned out to be pretty darn easy.  It's only about 12 lines of code in all:</p>
	<p>View the <a href = "/blogcode/gimme-fade-demo/" target = "_new">Gimme Fade Demo</a> (source is visible on the page)</p>
	<h3>New to Gimme?</h3>
	<p>If you're new to Gimme, you should know that it's free and open source!  Check out these links for more information:</p>
	<ul>
	<li><a href = "http://gimme.stchur.com">The Gimme Home Page</a></li>
	<li><a href = "http://codeplex.com/gimme/release/projectreleases.aspx">Official Gimme Releases on CodePlex</a></li>
	<li><a href = "http://codeplex.com/gimme/Wiki/View.aspx?title=Complete%20API%20Reference">The Gimme API Reference</a></li>
	</ul>
	<p>Comment welcome.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.stchur.com/2007/07/22/managing-animations-with-gimme-a-fade-demo/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
