<?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>Erik Lopez .net &#187; Web Development</title>
	<atom:link href="http://www.eriklopez.net/category/web-development/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.eriklopez.net</link>
	<description></description>
	<lastBuildDate>Wed, 21 Oct 2009 16:06:51 +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>Pipes? I got your Pipes right here.</title>
		<link>http://www.eriklopez.net/web-development/pipes-i-got-your-pipes-right-here/</link>
		<comments>http://www.eriklopez.net/web-development/pipes-i-got-your-pipes-right-here/#comments</comments>
		<pubDate>Wed, 21 Jan 2009 18:33:22 +0000</pubDate>
		<dc:creator>Erik</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[feeds]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[json]]></category>
		<category><![CDATA[pipes]]></category>
		<category><![CDATA[yahoo]]></category>

		<guid isPermaLink="false">http://www.eriklopez.net/?p=191</guid>
		<description><![CDATA[So I recently found myself using Yahoo! Pipes.  I wanted to aggregate all the RSS feeds from local newspapers, filter the articles for those that mentioned the Company (which is what I will henceforth call the place at which I hold a steady job), and consume it in the Company&#8217;s new web app I&#8217;m working [...]]]></description>
			<content:encoded><![CDATA[<p>So I recently found myself using <a title="Yahoo! Pipes" href="http://pipes.yahoo.com/pipes/" target="_blank">Yahoo! Pipes</a>.  I wanted to aggregate all the RSS feeds from local newspapers, filter the articles for those that mentioned the Company (which is what I will henceforth call the place at which I hold a steady job), and consume it in the Company&#8217;s new web app I&#8217;m working on.  I&#8217;d heard of Pipes a few years back, but I never had the reason to use it.  It&#8217;s a great tool and dead simple to use.  We could probably use it to replace the (what I&#8217;m sure is expensive) news aggregator service that culls industry news and articles that mention the Company from publications across the country.  Well, maybe eventually.</p>
<p>Anyway, creating the pipe was easy and using the interface was actually quite fun.  I&#8217;m pulling from almost 40 different feeds, filtering for mentions of the Company&#8217;s name in both the title, and the articles themselves, and now have one single feed I can now use.  On the web app end I&#8217;m using the ever-powerful and omnipotent jQuery to consume the feed in the JSON format.  Now, I&#8217;m not going to go in-depth in how this is accomplished, but rather I want to throw out this &#8220;gotcha&#8221; moment I experienced and hopefully, help at least one of the two people who will ever see this post avoid my mistake.</p>
<p><span id="more-191"></span></p>
<p>The JSON link I received from Pipes looked like this: <a href="#">http://pipes.yahoo.com/pipes/pipe.run?_id=[Some_ID]&amp;_render=json</a>.  Now in the jQuery documentation for the <a title="jQuery's getJSON function" href="http://docs.jquery.com/Ajax/jQuery.getJSON" target="_blank">getJSON </a>function, it says that in order for cross-domain JSON requests, you must use a JSONP callback by appending a variable to the url&#8217;s querystring, which is &#8220;callback=?&#8221;.  jQuery will then replace the question mark with the correct callback function that will then wrap the JSON object that comes back to your app.  So I created a link that looks like this: <a href="#">http://pipes.yahoo.com/pipes/pipe.run?_id=[Some_ID]&amp;_render=json&amp;callback=?</a>.  That should work right?  Well, at least I thought it should.  (Others with more experience with JSONP callbacks will probably already see where I went wrong.)  Instead of my new aggregated feed in my web app, I got an error from Firebug instead.  The message said &#8220;INVALID LABEL&#8221;, followed by the JSON string.  Well, I can see that I&#8217;m making a JSONP call, or else the error from Firebug would have been &#8220;ACCESS TO RESTRICTED URI DENIED&#8221; and I wouldn&#8217;t be able to see the JSON data.  So the cross-domain call works.  So, then, what&#8217;s wrong?  Well, jQuery is trying to parse JSON data as JSONP.  Looking back at the Firebug error, the JSON data that&#8217;s returned isn&#8217;t wrapped in the JSONP callback, but I know that the callback is being appended to the Pipe&#8217;s JSON URL querystring.  What gives?!</p>
<p>Insert an hour or so of misery and woe, as I Google every possible combination of &#8220;jQuery&#8221;, &#8220;JSONP&#8221;, &#8220;callback&#8221;, and &#8220;JSONP is teh suxxorz&#8221;.  I never found the answer.  Instead, I ended up staring at the Pipe&#8217;s JSON URL and I notice something.  Each variable declaration in the Pipe&#8217;s URL querystring is prefixed with an underscore.  Could it be that easy?</p>
<p>Yes. <span style="text-decoration: line-through;">We.</span> It. Can.</p>
<p>Enter the new JSON request URL: <a href="#">http://pipes.yahoo.com/pipes/pipe.run?_id=[Some_ID]&amp;_render=json&amp;_callback=?</a>.  Now the request works perfectly.  Why does the callback variable need to be prefixed with an underscore?  Who knows?  Something to do with Yahoo&#8217;s processing of the requests I&#8217;d guess.</p>
<p>Hopefully, this can help you avoid the sheer frustration this caused me.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.eriklopez.net/web-development/pipes-i-got-your-pipes-right-here/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>I &lt;3 Twitter</title>
		<link>http://www.eriklopez.net/web-development/i-heart-twitter/</link>
		<comments>http://www.eriklopez.net/web-development/i-heart-twitter/#comments</comments>
		<pubDate>Fri, 16 Jan 2009 23:33:31 +0000</pubDate>
		<dc:creator>Erik</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[aea08]]></category>
		<category><![CDATA[dashboard]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[macintosh]]></category>
		<category><![CDATA[twitter]]></category>
		<category><![CDATA[widget]]></category>

		<guid isPermaLink="false">http://www.eriklopez.net/?p=165</guid>
		<description><![CDATA[I don&#8217;t remember what I was doing or where I was when I heard about Twitter, but I certainly remember the impressions I had. What is a &#8220;microblog&#8221; and how on earth could that ever be useful?  As a web developer I certainly thought of myself as embracing new web technologies and platforms (I [...]]]></description>
			<content:encoded><![CDATA[<p>I don&#8217;t remember what I was doing or where I was when I heard about <a title="Twitter" href="http://twitter.com/" target="_blank">Twitter</a>, but I certainly remember the impressions I had. What is a &#8220;microblog&#8221; and how on earth could that ever be useful?  As a web developer I certainly thought of myself as embracing new web technologies and platforms (I cringe to use the term &#8220;Web 2.0&#8243; because of the buzz-wordy, hype status it has now obtained), but this Twitter&#8230;  Why would I ever want to send the internet-at-large a sparse 140-character message on what I was up to.  I mean, what the heck?  I&#8217;m not even interested in what I&#8217;m doing at times.  Now this web app comes along and expects me to remember to stop what I&#8217;m doing and compose a message devoid of most vowels like: &#8220;In bdrm thnkng abt wht 2 do on satrdy.&#8221;  Pass.</p>
<p><span id="more-165"></span></p>
<p>It wasn&#8217;t until I attended An Event Apart in San Francisco last August that I decided to break down and join though I still didn&#8217;t make my first update until September.  One day I decided there had to be more to this web app phenomenon and delved a little deeper into the inner-workings of Twitter.  I found that Twitter is <em>definitely</em> more than meets the eye. [Insert Transformer sound.]  As soon as I read about the API, I absolutely wanted to feed my most recent update to my blog.  It was hardly an original idea, but for me it was a perfect extension to my blog!  Many things often prompt me to complain with never a computer in sight, but my cellphone is my ever constant companion.  With Twitter, my web-based mind-dump is only a few key presses away.  And both of my readers get to see up-to-the-minute updates as I send them.</p>
<p>Twitter&#8217;s allure doesn&#8217;t stop there however.  In my readings I&#8217;ve seen Twitter referred to as &#8220;the command line of the internet&#8221; by multiple sources.  That is a powerful thing.  It kicked off so many ideas in my head and hopefully I&#8217;ll get to make them at some point.  Who wouldn&#8217;t want to change their site stylesheet with just a text message?  I&#8217;ve also mapped out a mashup between Twitter and Google Charts.  It sounds weird, but really, it&#8217;s a good idea, trust me.  I&#8217;m also currently working on a Twitter widget for Dashboard, and it&#8217;s not exactly focused on the messages.  Stay tuned for that one.</p>
<p>In writing this post, I just wanted to share my love for this humble app.  I get mocked for my devotion to Twitter by my less-than-internet-savvy friends, but I don&#8217;t care.  Especially when I used the term &#8220;tweet&#8221; the other day.  Although now that I think of it, I almost made fun of myself for that one.  Not sure if I was ready for that.  Baby steps.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.eriklopez.net/web-development/i-heart-twitter/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Parallax navigation</title>
		<link>http://www.eriklopez.net/web-development/parallax-navigation/</link>
		<comments>http://www.eriklopez.net/web-development/parallax-navigation/#comments</comments>
		<pubDate>Mon, 12 Jan 2009 17:03:37 +0000</pubDate>
		<dc:creator>Erik</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[aea08]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[navigation]]></category>
		<category><![CDATA[parallax]]></category>

		<guid isPermaLink="false">http://www.eriklopez.net/?p=33</guid>
		<description><![CDATA[My first major web design conference experience was last August at An Event Apart 2008 in San Francisco.  It was an awesome conference and if travel restrictions are lifted at my day job anytime soon I&#8217;m hoping to go back in &#8216;09.  During the conference, or more specifically, during Dan Cederholm&#8217;s presentation, Implementing Design: Bulletproof [...]]]></description>
			<content:encoded><![CDATA[<p>My first major web design conference experience was last August at An Event Apart 2008 in San Francisco.  It was an awesome conference and if travel restrictions are lifted at my day job anytime soon I&#8217;m hoping to go back in &#8216;09.  During the conference, or more specifically, during <a title="SimpleBits" href="http://simplebits.com/" target="_blank">Dan Cederholm&#8217;s</a> presentation, <em>Implementing Design: Bulletproof A-Z</em>, many of us were first introduced to <a title="Clearleft" href="http://clearleft.com/" target="_blank">Clearleft&#8217;s</a> <a title="Clearleft's Silverback" href="http://www.silverbackapp.com/" target="_blank">Silverback</a> application&#8217;s website and it&#8217;s clever use of CSS to mimic an animation technique called &#8220;parallax scrolling&#8221;.  <a title="Paul Annett" href="http://paulannett.co.uk/" target="_blank">Paul Annett</a>, Clearleft&#8217;s designer, gives a great explanation of the effect and the underlying CSS over at <a title="How to recreate Silverback’s parallax effect" href="http://www.thinkvitamin.com/features/design/how-to-recreate-silverbacks-parallax" target="_blank">Vitamin</a>.</p>
<p>When I first saw the technique in action, I was blown away by both the simplicity of the technique, as well as the cleverness of it all.  Sometimes at the ol&#8217; 9 to 5, I don&#8217;t think I&#8217;ll ever have opportunity, let alone the time, to devise and implement such innovation.  While the artistry is not lost on me, I felt the parallax effect could be used somewhere more visible to the masses in order to give a page&#8217;s design some sense of motion.  In order to do that, I wouldn&#8217;t be able to rely on CSS alone, so I turned to the all-powerful <a title="jQuery: The write less, do more Javascript library" href="http://jquery.com/" target="_blank">jQuery</a>.</p>
<p><span id="more-33"></span></p>
<h3>The images</h3>
<p>The most important step to any parallax project is definitely the selection of the images.  Being a child of the 80&#8217;s with not much more than a Nintendo and big dreams, I had to go with a Super Mario Bros. scene.  Here are the three tranparent PNG images I used, starting with the &#8220;distant&#8221; sky and clouds, then moving to the &#8220;closer&#8221; hills and shrubs, and ending with the &#8220;nearer&#8221; ground, floating blocks and pipes.</p>
<p><img class="alignnone size-full wp-image-41" title="cloudscene" src="http://www.eriklopez.net/wp-content/uploads/2009/01/cloudscene.png" alt="cloudscene" width="400" height="50" /></p>
<p><img class="alignnone size-full wp-image-42" title="middlescene" src="http://www.eriklopez.net/wp-content/uploads/2009/01/middlescene.png" alt="middlescene" width="400" height="50" /></p>
<p><img class="alignnone size-full wp-image-43" title="groundscene" src="http://www.eriklopez.net/wp-content/uploads/2009/01/groundscene.png" alt="groundscene" width="400" height="50" /></p>
<h3>The HTML</h3>
<p>The HTML is straightforward.  I created a simple unordered list-based navigation with four items with the text of each navigation item being wrapped in a &lt;span&gt; tag.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">ul</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;navigation&quot;</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#1&quot;</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">span</span>&gt;</span>Home<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">span</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#2&quot;</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">span</span>&gt;</span>About<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">span</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#3&quot;</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">span</span>&gt;</span>Portfolio<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">span</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#4&quot;</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">span</span>&gt;</span>Contact<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">span</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">ul</span>&gt;</span></pre></td></tr></table></div>

<h3>The CSS</h3>
<p>We begin first by styling the list and list-items.  Each list item will have the same dimensions as the images, 200 x 500, and since the list item is the most &#8220;distant&#8221; element in our pseudo-three-dimensional environment it will use the scene that occurs &#8220;furthest&#8221; from the viewer, the cloud scene.  All of the backgrounds are also repeated along the X-axis in order to give us infinite &#8220;scrollability&#8221; and animation time.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="css" style="font-family:monospace;">ul<span style="color: #cc00cc;">#navigation</span> <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">list-style-type</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
ul<span style="color: #cc00cc;">#navigation</span> li <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">200px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">50px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">'CloudScene.png'</span><span style="color: #00AA00;">&#41;</span> <span style="color: #993333;">repeat-x</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>

<p>Next we style the next-closest element in our pseudo-three-dimensional environment, the link.  We&#8217;ll set the link to fill the entire list item, set the attributes for the link text, and finally, set the link background to the next closest scene, the hills and shrubbery.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td class="code"><pre class="css" style="font-family:monospace;">ul<span style="color: #cc00cc;">#navigation</span> li a<span style="color: #3333ff;">:link</span><span style="color: #00AA00;">,</span>
ul<span style="color: #cc00cc;">#navigation</span> li a<span style="color: #3333ff;"><span style="color: #00AA00;">:</span>visited
</span>ul<span style="color: #cc00cc;">#navigation</span> li a<span style="color: #3333ff;">:hover</span><span style="color: #00AA00;">,</span>
ul<span style="color: #cc00cc;">#navigation</span> li a<span style="color: #3333ff;">:focus</span><span style="color: #00AA00;">,</span>
ul<span style="color: #cc00cc;">#navigation</span> li a<span style="color: #3333ff;">:active </span><span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">block</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">200px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">50px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#1F1F1F</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span> <span style="color: #933;">20px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">font-weight</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">bold</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">text-decoration</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">'MiddleScene.png'</span><span style="color: #00AA00;">&#41;</span> <span style="color: #993333;">repeat-x</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>

<p>The final step in implementing the CSS is to style the span element that is nested within the link.  Here, we position the text within the link using padding, and adjust the size of the span to compensate for the padding in order to prevent the span from overstepping its boundaries.  Lastly, we apply the scene closest to the viewer to the background of the span, the ground, blocks, and pipes scene.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="css" style="font-family:monospace;">ul<span style="color: #cc00cc;">#navigation</span> li a span <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">block</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span> <span style="color: #933;">22px</span> <span style="color: #cc66cc;">0</span> <span style="color: #cc66cc;">0</span> <span style="color: #933;">30px</span><span style="color: #00AA00;">;</span>
    <span style="color: #808080; font-style: italic;">/* Correct sizing due to text placement */</span>
    <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">170px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">28px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">'GroundScene.png'</span><span style="color: #00AA00;">&#41;</span> <span style="color: #993333;">repeat-x</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>

<h3>So far&#8230;</h3>
<p>So far, all we have is a regular navigation block with what appears to be a single image in the background of each item.</p>
<p><img class="alignnone size-full wp-image-77" title="navillax" src="http://www.eriklopez.net/wp-content/uploads/2009/01/navillax.png" alt="navillax" width="200" height="200" /></p>
<h3>The Javascript, or Why I Love jQuery</h3>
<p>Here&#8217;s where the magic happens, the Javascript.  I probably wouldn&#8217;t have even attempted this concept if it wasn&#8217;t for jQuery.  If you&#8217;re not familiar with jQuery, head on over to the <a title="jquery Documentation" href="http://docs.jquery.com/Main_Page" target="_blank">documentation</a> and have a look around.  If you use much Javascript in your projects, I promise, it&#8217;ll make your life a whole lot easier.  Let&#8217;s take a look at the javascript block and break it down.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
   $<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><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>
     $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#navigation &gt; li &gt; a &gt; span&quot;</span><span style="color: #009900;">&#41;</span>
       .<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#123;</span>backgroundPosition<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;0 0&quot;</span><span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#41;</span>
       .<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">&quot;cursor&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;pointer&quot;</span> <span style="color: #009900;">&#41;</span>
       .<span style="color: #660066;">mouseover</span><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>
         $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #000066;">stop</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">animate</span><span style="color: #009900;">&#40;</span>
           <span style="color: #009900;">&#123;</span>backgroundPosition<span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;-1000px 0&quot;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">5000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
         $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#navigation &gt; li &gt; a:contains('&quot;</span> <span style="color: #339933;">+</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;')&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #000066;">stop</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">animate</span><span style="color: #009900;">&#40;</span>
           <span style="color: #009900;">&#123;</span>backgroundPosition<span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;-500px 0&quot;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">5000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
         $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#navigation &gt; li:contains('&quot;</span> <span style="color: #339933;">+</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;')&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #000066;">stop</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">animate</span><span style="color: #009900;">&#40;</span>
           <span style="color: #009900;">&#123;</span>backgroundPosition<span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;-200px 0&quot;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">5000</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: #660066;">mouseout</span><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>
         $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #000066;">stop</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">animate</span><span style="color: #009900;">&#40;</span>
           <span style="color: #009900;">&#123;</span>backgroundPosition<span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;0px 0&quot;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">3000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
         $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#navigation &gt; li &gt; a:contains('&quot;</span> <span style="color: #339933;">+</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;')&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #000066;">stop</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">animate</span><span style="color: #009900;">&#40;</span>
           <span style="color: #009900;">&#123;</span>backgroundPosition<span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;0px 0&quot;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">3000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
         $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#navigation &gt; li:contains('&quot;</span> <span style="color: #339933;">+</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;')&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #000066;">stop</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">animate</span><span style="color: #009900;">&#40;</span>
           <span style="color: #009900;">&#123;</span>backgroundPosition<span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;0px 0&quot;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">3000</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: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>So we start by setting the span&#8217;s background-position CSS property to the coordinates 0,0 just to make sure that the background is where it should be.  I also set the CSS cursor property to pointer, just to make it clear that it&#8217;s a link in browsers that still display the default cursor when hovering over our navigation items&#8230; I&#8217;m looking at you, IE7.  Next, we add the mouse over behavior of our navigation items that animates the backgrounds of each of our layers.</p>
<p>It starts by stopping any animations that may currently be running.  The closest layer, the ground, blocks, and pipes scene then is animated by sliding the background image to the left by 1,000 pixels over a duration of five seconds (5,000 milliseconds).</p>
<p>The second animation that will be running simultaneously is the hills and shrubs scene, that is attached to the link tag.  We&#8217;ll use jQuery to select only the link tag that contains the text of the element that is currently in the mouseover state.  This prevents every middle layer throughout our navigation block from animating at the same time.  The background of this element uses the same duration as the top most layer, five seconds, but the background ends up only traveling a distance of 500 pixels, rather than 1,000 pixels, like the span element&#8217;s background.  This is where we get the parallax effect.  jQuery animates both layers at the same time, for the same duration, yet the layer &#8220;furthest&#8221; from the viewer will go more slowly than the the &#8220;closest&#8221; layer, because it is traveling less distance in the same amount of time.</p>
<p>Finally, we animate the list item layer, or the cloud scene.  Again, we use jQuery selectors to choose the correct list item, give the animation a duration of five seconds, and cause the background image to travel only 200 pixels.</p>
<p>To end the fun, once the mouse has left the navigation item, I&#8217;ve added a mouseout function that again ends any animation currently running on each of the navigation items and scrolls the background to it&#8217;s starting coordinates of 0,0 over three seconds.  Since they are all offset a different amount of pixels, scrolling back will also have the parallax effect.</p>
<h3>Wrapping up</h3>
<p>Here&#8217;s the final product:<br />
<script type="text/javascript">
        jQuery(document).ready(function(){
            jQuery("#navigation > li > a > span")
                .css( {backgroundPosition: "0 0"} )
                .css( "cursor","pointer" )
                .mouseover(function(){
                    jQuery(this).stop().animate(
                        {backgroundPosition:"-1000px 0"}, 5000);
                    jQuery("#navigation > li > a:contains('" + jQuery(this).text() + "')").stop().animate(
                        {backgroundPosition:"-500px 0"}, 5000);
                    jQuery("#navigation > li:contains('" + jQuery(this).text() + "')").stop().animate(
                        {backgroundPosition:"-200px 0"}, 5000);
                })
                .mouseout(function(){
                    jQuery(this).stop().animate(
                        {backgroundPosition:"0px 0"}, 3000);
                    jQuery("#navigation > li > a:contains('" + jQuery(this).text() + "')").stop().animate(
                        {backgroundPosition:"0px 0"}, 3000);
                    jQuery("#navigation > li:contains('" + jQuery(this).text() + "')").stop().animate(
                        {backgroundPosition:"0px 0"}, 3000);
                })
        });
    </script></p>
<style type="text/css">
ul#navigation
{
    margin: 0 0 25px;
    padding: 0;
    list-style-type: none;
}
ul#navigation li
{
    list-style-type: none;
    width: 200px;
    height: 50px;
    background: transparent url('http://www.eriklopez.net/wp-content/uploads/2009/01/cloudscene.png') repeat-x;
}
ul#navigation li a:link,
ul#navigation li a:visited
ul#navigation li a:hover,
ul#navigation li a:focus,
ul#navigation li a:active
{
    display: block;
    width: 200px;
    height: 50px;
    color: #1F1F1F;
    font-size: 20px;
    font-weight: bold;
    text-decoration: none;
    border: none;
    background: transparent url('http://www.eriklopez.net/wp-content/uploads/2009/01/middlescene.png') repeat-x;
}
ul#navigation li a span
{
    display: block;
    padding: 22px 0 0 30px;
    /* Correct sizing due to text placement */
    width: 170px;
    height: 28px;
    background: transparent url('http://www.eriklopez.net/wp-content/uploads/2009/01/groundscene.png') repeat-x;
}
</style>
<ul id="navigation">
<li><a href="#1"><span>Home</span></a></li>
<li><a href="#2"><span>About</span></a></li>
<li><a href="#3"><span>Portfolio</span></a></li>
<li><a href="#4"><span>Contact</span></a></li>
</ul>
<p>Does anyone think this effect is useful or necessary?  Or does it just add page bloat that doesn&#8217;t serve any useful purpose?  I&#8217;m interested to hear what you think, as there was quite the heated discussion over at Paul Annett&#8217;s Vitamin article.  At any rate, I think I&#8217;ve accomplished my goal of bringing the parallax effect out of the &#8220;shadows&#8221;, so to speak.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.eriklopez.net/web-development/parallax-navigation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
