<?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/"
	xmlns:series="http://unfoldingneurons.com/"
	>

<channel>
	<title>Ovalpixels Blog about Web-Building &#187; animation</title>
	<atom:link href="http://www.ovalpixels.com/blog/tag/animation/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ovalpixels.com/blog</link>
	<description>Tips &#38; Tricks on Web Design and Development</description>
	<lastBuildDate>Fri, 28 Jan 2011 09:17:42 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Making fancy websites without Flash 2: Animating background image</title>
		<link>http://www.ovalpixels.com/blog/2009/02/21/making-fancy-websites-without-flash-animating-background-image/</link>
		<comments>http://www.ovalpixels.com/blog/2009/02/21/making-fancy-websites-without-flash-animating-background-image/#comments</comments>
		<pubDate>Sat, 21 Feb 2009 18:48:43 +0000</pubDate>
		<dc:creator>georgi</dc:creator>
				<category><![CDATA[Design]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[animation]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://www.ovalpixels.com/blog/?p=87</guid>
		<description><![CDATA[This is a continuation of the Making fancy website without Flash entry from a few days ago. To make the story short &#8211; I will try and show you some jQuery alernatives for popular Flash animation. We will start with a Smooth background image swap &#8211; jQuery Background-Image Transition Plugin I will show you an [...]]]></description>
			<content:encoded><![CDATA[<p>This is a continuation of the <a  href="http://www.ovalpixels.com/blog/2009/02/20/making-fancy-websites-without-flash-introduction/" target="_blank">Making fancy website without Flash</a> entry from a few days ago. To make the story short &#8211; I will try and show you some jQuery alernatives for popular Flash animation. <span id="more-87"></span>We will start with a</p>
<h3>Smooth background image swap &#8211; jQuery Background-Image Transition Plugin</h3>
<p>I will show you an example right now, so you know what I am talking about.</p>
<p><a  title="background-image-transition-example" href="http://www.ovalpixels.com/bgImageTransition/">Here is a working example</a></p>
<p>What we basically do is:</p>
<ol>
<li>Create an additional hidden &lt;div&gt; element on top ( using z-index ) of the element we want to animate</li>
<li>Load the new image in the in the cache in the background, so that the effect is smooth</li>
<li>Set the new src to the new &lt;div&gt; element</li>
<li>fadeIn() the new &lt;div&gt; element so that it creates the illusion that the background image of our initial div is smoothly changing</li>
<li>Optional step &#8211; if we need to change the image once again, go from 2 to 5 but setting the new src to our <em>initial </em>&lt;div&gt; and then using <em>fadeOut()</em> on the new element, so that it disappears and the new image is set as background to the old &lt;div&gt;. This way we won&#8217;t have an infinitive increase of the z-index and won&#8217;t actually change the z-index of the initial &lt;div&gt;</li>
</ol>
<p>OK, let&#8217;s get to work, we will start with the HTML markup:</p>
<p>&lt;div id=&#8221;backImage&#8221;&gt;&lt;/div&gt;</p>
<p>Well, that was pretty easy: we have a simple &lt;div&gt; element with some demo text and just next to it we add that additional &lt;div&gt; which we will need for the animation.</p>
<p>So, here is the CSS:</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #cc00cc;">#backImage</span> <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">z-index</span><span style="color: #00AA00;">:</span> -<span style="color: #cc66cc;">2</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">600px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">800px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">background-image</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">'path/to/initial/img'</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>We just set a height and width of the element so that we are sure the image will actually be shown. It is generally a good idea to have the z-index set to a negative number while other elements have a greater z-index value.</p>
<p>We will use <a  href="http://plugins.jquery.com/project/bgImageTransition/" target="_blank">jQuery&#8217;s Background-Image Transition Plugin</a> for our example.</p>
<p>First, add jQuery and the plugin</p>
<p>&lt;script lang=&#8221;Javascript&#8221; src=&#8221;path/to/jQuery.js&#8221; type=&#8221;text/javascript&#8221;&gt; &lt;/script&gt;<br />
&lt;script lang=&#8221;Javascript&#8221; src=&#8221;path/to/jQuery.bgImageTransition.js&#8221; type=&#8221;text/javascript&#8221;&gt; &lt;/script&gt;</p>
<p>Then, at the end of the document, add the following lines:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">jQuery<span style="color: #009900;">&#40;</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#backImage'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">bgImageTransition</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">'path/to/new/image'</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>
        duration<span style="color: #339933;">:</span> <span style="color: #3366CC;">'slow'</span><span style="color: #339933;">,</span>
        easing<span style="color: #339933;">:</span> <span style="color: #3366CC;">'linear'</span><span style="color: #339933;">,</span>
        helperElementId<span style="color: #339933;">:</span> <span style="color: #3366CC;">'backImage2'</span><span style="color: #339933;">,</span>
        zindex<span style="color: #339933;">:</span> <span style="color: #339933;">-</span><span style="color: #CC0000;">1</span>
        callback<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
           <span style="color: #006600; font-style: italic;">//do sth</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>The only mandatory argument is the path to the new image. The optional second argument is an object holding some tweaks. You can set the desired duration, easing, helperElementId ( which is generated by the plugin ), z-index of the helperElement ( by default it will take the selected element&#8217;s zindex and increment by 1 ) and a callback function in case you want to execute some functionality when the transition is over.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ovalpixels.com/blog/2009/02/21/making-fancy-websites-without-flash-animating-background-image/feed/</wfw:commentRss>
		<slash:comments>33</slash:comments>
		</item>
	</channel>
</rss>

