<?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>Paul Bennett - User Interface Developer &#187; Animation</title>
	<atom:link href="http://pmbennett.net/tag/animation/feed/" rel="self" type="application/rss+xml" />
	<link>http://pmbennett.net</link>
	<description></description>
	<lastBuildDate>Thu, 27 Oct 2011 15:10:11 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>CSS3 Animated Photo Stack with jQuery</title>
		<link>http://pmbennett.net/2010/05/28/css3-animated-photo-stack-with-jquery/</link>
		<comments>http://pmbennett.net/2010/05/28/css3-animated-photo-stack-with-jquery/#comments</comments>
		<pubDate>Fri, 28 May 2010 11:51:42 +0000</pubDate>
		<dc:creator>paul</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[Animation]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Transitions Webkit]]></category>

		<guid isPermaLink="false">http://pmbennett.net/?p=377</guid>
		<description><![CDATA[CSS3 transitions and animations are rightly attracting a lot of attention. With support in most modern browsers, there is a lot of scope for creating rich user experiences using only CSS. In this post, I will walk through how to create a stack of photos using CSS keyframe animations and a dash of jQuery to achieve a pretty awesome effect.]]></description>
			<content:encoded><![CDATA[<p>So, lets dive straight in! The markup is pretty straightforward, you just need a container filled with the images for the stack of photos:</p>
<pre><code>&lt;div id="photo_stack"&gt;
	&lt;img id="photo1" src="images/photostack1.jpg" alt="Alt text goes here..." /&gt;
	&lt;img id="photo2" src="images/photostack2.jpg" alt="Alt text goes here..." /&gt;
	&lt;img id="photo3" src="images/photostack3.jpg" alt="Alt text goes here..." /&gt;
&lt;/div&gt;</code></pre>
<p>You will then need some simple CSS to style and position the images in a stack. We will be using jQuery to alter the z-index values of each image once the animation has completed, so we will start by giving each image a high z-index value. You will also need to setup the speed and easing functions for the transitions. </p>
<pre><code>#photo_stack img {
	position: absolute;
	border: 10px solid #FFF;
	box-shadow: 2px 2px 8px rgba(0,0,0,0.5);
	-moz-box-shadow: 2px 2px 8px rgba(0,0,0,0.5);
	-webkit-box-shadow: 2px 2px 8px rgba(0,0,0,0.5);
	z-index: 9999;

	/* setup transition speed and easing */
	-moz-transition: all 0.2s ease; /* Firefox */
	-webkit-transition: all 0.2s ease; /* WebKit */
	-o-transition: all 0.2s ease; /* Opera */
	transition: all 0.2s ease; /* Standard */

}
#photo_stack #photo1 {
	top: 0;
	left: 100px;
}
#photo_stack #photo2 {
	top: 12px;
	left: 55px;
}
#photo_stack #photo3 {
	top: 27px;
	left: 50px;
}</code></pre>
<p>Once this is complete you can add the CSS to create the keyframe animation, which will take the image at the top of the stack and place it at the bottom of the photo stack.</p>
<pre><code>@-webkit-keyframes shuffle {
	0% {
		margin-left: 0px;
	}
	50% {
		margin-left: 450px;
		-webkit-transform: scale(0.9);
		-moz-transform: scale(0.9);
		transform: scale(0.9);
	}
	100% {
		margin-left: 0px;
		-webkit-transform: scale(1);
		-moz-transform: scale(1);
		transform: scale(1);
	}
}
#photo_stack .animate {
	-webkit-animation-name: shuffle;
	-webkit-animation-duration: 1s;
	-webkit-animation-iteration-count: 1;
}</code></pre>
<p>What this is basically doing, is running the keyframe animation called &#8217;shuffle&#8217; once and for a duration of 1 second. The animation itself is moving the image 450px to the right of the stack, scaling down to give an impression of depth, and then moving it back to where it&#8217;s original position. Note that this will only happen when the image is assigned the &#8216;animate&#8217; class.</p>
<p>Okay, so you now have a cool animation effect, but nothing triggers it and the image does not go to the bottom of the stack: Enter jquery. What jquery will do, is trigger the animation by assigning the &#8216;animate&#8217; class to the image on the top of the stack, removing it once the animation is complete. </p>
<pre><code>$imgs = $("#photo_stack img");
$imgCount = $imgs.length;
$curr_index = 0;
$imgs.last().addClass('current'); /* Set the image at top of stack to current */

$("#photo_stack")
	.delegate('img', 'click', function() {
		$this = $(this);

		/* If the image is at the top of the stack */
		if ($this.hasClass('current')) {
			/* Work out new z-index value */
			$zi = $this.css('zIndex') - $imgCount;

			/* Trigger animation */
			$this.addClass('animate');

			/* Assign new z-index value then stop animation after complete */
			setTimeout(function() { $this.css('zIndex', $zi); }, 200);
			setTimeout(function() { $this.removeClass('animate'); }, 1000);

			/* Set next image to current */
			$this.removeClass('current');
			if ($this.index() == 0) {
				$imgs.last().addClass('current');
			} else {
				$imgs.eq($this.index()-1).addClass('current');
			}
		}
	})</code></pre>
<p>You will now have some images in a stack that you can click on and they will be animated and placed to the bottom of the stack. Now it is time to use the rotation transition to make the photo stack look a little more realistic. I used CSS classes to rotate the images somewhere between -4 and 4 degrees and used jQuery to randomly assign one of those classes to each image when the DOM has loaded. Then I just added a CSS rule to rotate the image to 0 degrees on hover. </p>
<pre><code>#photo_stack .deg1 {
	-webkit-transform: rotate(1deg);
   	-moz-transform: rotate(1deg);
   	transform: rotate(1deg);
}
#photo_stack .deg2 {
	-webkit-transform: rotate(2deg);
   	-moz-transform: rotate(2deg);
   	transform: rotate(2deg);
}
#photo_stack .deg3 {
	-webkit-transform: rotate(3deg);
   	-moz-transform: rotate(3deg);
   	transform: rotate(3deg);
}
#photo_stack .deg4 {
	-webkit-transform: rotate(4deg);
   	-moz-transform: rotate(4deg);
   	transform: rotate(4deg);
}
#photo_stack .deg1neg {
	-webkit-transform: rotate(-1deg);
   	-moz-transform: rotate(-1deg);
   	transform: rotate(-1deg);
}
#photo_stack .deg2neg {
	-webkit-transform: rotate(-2deg);
   	-moz-transform: rotate(-2deg);
   	transform: rotate(-2deg);
}
#photo_stack .deg3neg {
	-webkit-transform: rotate(-3deg);
   	-moz-transform: rotate(-3deg);
   	transform: rotate(-3deg);
}
#photo_stack .deg4neg {
	-webkit-transform: rotate(-4deg);
   	-moz-transform: rotate(-4deg);
   	transform: rotate(-4deg);
}
#photo_stack .hover {
	-webkit-transform: rotate(0deg);
   	-moz-transform: rotate(0deg);
   	transform: rotate(0deg);
	cursor: pointer;
}</code></pre>
<p>I chose to use this approach, as it means that you can have any number of images in the stack, and they will be randomly rotated. If you wanted, you could just assign a specific angle to each photo in the stack using each images ID for complete control.</p>
<p>The full code for the animated photo stack can be found on the <a href="/demos/css3-animated-photo-stack.html">demo page</a>. It works best in the latest version of Chrome or Safari. Firefox works but without the animation and I did not even bother checking Internet Explorer &#8211; it always spoils the party!</p>
]]></content:encoded>
			<wfw:commentRss>http://pmbennett.net/2010/05/28/css3-animated-photo-stack-with-jquery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rotating Globe with jQuery</title>
		<link>http://pmbennett.net/2010/04/20/rotating-globe-with-jquery/</link>
		<comments>http://pmbennett.net/2010/04/20/rotating-globe-with-jquery/#comments</comments>
		<pubDate>Tue, 20 Apr 2010 21:11:55 +0000</pubDate>
		<dc:creator>paul</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[Animation]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://pmbennett.net/?p=288</guid>
		<description><![CDATA[<p>This is basically another take on moving backgrounds using jQuery, but I was inspired to create a rotating globe by <a href="http://www.romancortes.com/blog/pure-css-coke-can/">Rom&#225;n Cort&#233;s Pure CSS Coke Can</a>. Sure, this has nothing to do with displacement, and it uses JavaScript, but it was fun none-the-less!</p>]]></description>
			<content:encoded><![CDATA[<p>As I mentioned above, this is yet another moving background example, there is nothing new here, I just thought it might be fun to try!</p>
]]></content:encoded>
			<wfw:commentRss>http://pmbennett.net/2010/04/20/rotating-globe-with-jquery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jQuery Picture Board</title>
		<link>http://pmbennett.net/2010/04/13/jquery-picture-board/</link>
		<comments>http://pmbennett.net/2010/04/13/jquery-picture-board/#comments</comments>
		<pubDate>Tue, 13 Apr 2010 21:25:22 +0000</pubDate>
		<dc:creator>paul</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[Animation]]></category>
		<category><![CDATA[Flip]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://pmbennett.net/?p=299</guid>
		<description><![CDATA[<p>I'm very much looking forward to the World Cup this year, which reminded me of the fun I had during the last one four years ago. I remember organising a Question of Sport style quiz for my fellow colleagues, which gave me a great chance to try out some JavaScript that I had learned. One round involved the creation of a picture board, which is divided up into squares, and users can click on the numbers to reveal a portion of an image underneath, similar to the Picture board on Question of Sport, but more like a game of Catchphrase. It got me thinking: what would I do now I am armoured with all this jQuery goodness?</p>
]]></description>
			<content:encoded><![CDATA[<p>Inspired by <a href="http://webmuch.com/image-flip-using-jquery/">Aayush Shastri&#8217;s image flip</a>, I decided to re-create the picture board using some cool animation. My approach was to use a simple list of links, which would each take the form of a square on top of the background image. The HTML and CSS are very straight forard, so I will not list that here. Instead, I will walk through my solution using jQuery.</p>
<p>Before I begin, it is worth highlighting that I am using an ordered list of links, and the hidden image is a background image on the <code>&lt;ol&gt;</code> element. I will take the following approach:</p>
<ol>
<li>Store the url of the hidden image</li>
<li>Add an element to each list item, which will be used to display the hidden portion of the image</li>
<li>then add the click events to the numbered square and the reveal element</li>
</ol>
<p>So the first few lines set a few variables, allowing us to cache some jQuery objects for later use.</p>
<pre><code>$gridWrap = $('#reveal_grid');
$revealImg = $gridWrap.css('background-image');
$gridWrap.css('background', 'transparent')
$sqrs = $('#reveal_grid li');</code></pre>
<p>We then loop through the links in the list and add the <code><span></code> elements, add some CSS rules to setup the hide/reveal.</p>
<pre><code>$('#reveal_grid li a').each(function() {
	$num = $(this);
	$bgPos = $num.css('backgroundPosition');
	$num.parent('li').append(
		$('<span class="reveal"></span>').css({
			backgroundImage: $revealImg,
			backgroundPosition: $bgPos,
			height:'0',
			marginTop: ($num.height()/2) + 'px',
			opacity:'0.2'
		})
	);
});</code></pre>
<p>Next we need to add the click events, which just adds the flip animation that was based upon the <a href="http://webmuch.com/image-flip-using-jquery/">original by Aayush Shastri</a>:</p>
<pre><code>$sqrs.delegate('a', 'click', function() {
	$sqr = $(this);
	$height = $sqr.height();
	$width = $sqr.width();
	$sqr.stop()
	.animate({
		width: $width + 'px',
		height: '0',
		marginTop: ($height/2) + 'px',
		opacity: '0.2'
	}, 500, function() {
	$sqr.next('.reveal')
		.stop()
		.animate({
			width: $width + 'px',
			height: $height + 'px',
			marginTop: '0',
			opacity: '1'
		}, 500);
	});
	return false;
});
$sqrs.delegate('span', 'click', function() {
	$sqr = $(this);
	$height = $sqr.height();
	$width = $sqr.width();
	$sqr.stop()
	.animate({
		width: $width + 'px',
		height: '0',
		marginTop: ($height/2) + 'px',
		opacity: '0.2'
	}, 500, function() {
		$sqr.prev('a')
		.stop()
		.animate({
			width: $width + 'px',
			height: $height + 'px',
			marginTop: '0',
			opacity: '1'
		}, 500);
	});
	return false;
});</code></pre>
<p>I am aware that this code could be streamlined somewhat, but it made sense to structure it like this for demonstration purposes. In terms of performance, it seems fine, so I will leave as is for the time being.</p>
]]></content:encoded>
			<wfw:commentRss>http://pmbennett.net/2010/04/13/jquery-picture-board/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Animated Backgrounds with jQuery</title>
		<link>http://pmbennett.net/2010/01/12/animated-backgrounds-with-jquery/</link>
		<comments>http://pmbennett.net/2010/01/12/animated-backgrounds-with-jquery/#comments</comments>
		<pubDate>Tue, 12 Jan 2010 18:37:40 +0000</pubDate>
		<dc:creator>paul</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[Animation]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://pmbennett.net/?p=230</guid>
		<description><![CDATA[<p>I apologise in advance, a this is a very old technique, but it's something I have wanted to try out since last year. A while ago, I stumbled upon <a href="http://www.sunrisedesign.com/" target="_blank">Sunrise Design</a>, and absolutely loved the subtle background animation!</p>]]></description>
			<content:encoded><![CDATA[<p>Of course, this has been done many times before, but not in such an ethereal manner. So I have put together a not-so-subtle demo to have a go at this myself. I am not going to post the code here as this is very simple to achieve and hardly ground-breaking! If you want to see how this effect is achieved, you can view the source code of the demo.</p>
]]></content:encoded>
			<wfw:commentRss>http://pmbennett.net/2010/01/12/animated-backgrounds-with-jquery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

