<?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>nightdrops.com &#187; tutorial</title>
	<atom:link href="http://www.nightdrops.com/tag/tutorial/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.nightdrops.com</link>
	<description>like the color blue</description>
	<lastBuildDate>Thu, 01 Jul 2010 13:19:03 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Sealed and dynamic  classes</title>
		<link>http://www.nightdrops.com/2009/sealed-and-dynamic-classes/</link>
		<comments>http://www.nightdrops.com/2009/sealed-and-dynamic-classes/#comments</comments>
		<pubDate>Thu, 10 Dec 2009 11:07:48 +0000</pubDate>
		<dc:creator>kajyr</dc:creator>
				<category><![CDATA[Blog posts]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[classes]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.nightdrops.com/?p=284</guid>
		<description><![CDATA[Back in the days of actionscript 2, you could add any property to pretty much any object, just calling it and setting a value, like this: &#160;myMovieClip.thePropertyILikeWithAStrangeName = &#34;some string&#34; Actionscript 3.0 instead, being a more serious language, defines the basic class as sealed. That means that you can&#8217;t add any property on a object. [...]]]></description>
			<content:encoded><![CDATA[<p>Back in the days of actionscript 2, you could add any property to pretty much any object, just calling it and setting a value, like this:</p>
<p><code class="codecolorer actionscript default"><span class="actionscript">&nbsp;myMovieClip.<span style="color: #006600;">thePropertyILikeWithAStrangeName</span> = <span style="color: #ff0000;">&quot;some string&quot;</span></span></code></p>
<p>Actionscript 3.0 instead, being a more serious language, defines the basic class as sealed. That means that you can&#8217;t add any property on a object. You have to extends that class, and adding public properties.</p>
<div class="codecolorer-container actionscript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> MyClass <span style="color: #0066CC;">extends</span> <span style="color: #0066CC;">MovieClip</span> <span style="color: #66cc66;">&#123;</span><br />
<span style="color: #0066CC;">public</span> thePropertyILikeWithAStrangeName:<span style="color: #0066CC;">String</span><br />
<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> MyClass<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
<span style="color: #0066CC;">super</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #66cc66;">&#125;</span><br />
<span style="color: #66cc66;">&#125;</span></div></div>
<p>That class is sealed. You can&#8217;t</p>
<div class="codecolorer-container actionscript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">var</span> foo:MyClass = <span style="color: #000000; font-weight: bold;">new</span> MyClass<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
foo.<span style="color: #006600;">anotherProperty</span> = <span style="color: #cc66cc;">42</span>;</div></div>
<p>The <code class="codecolorer actionscript default"><span class="actionscript"><span style="color: #0066CC;">dynamic</span></span></code> keyword, permits to &#8216;unseal&#8217; a class, giving back the possibility to add any property on runtime.</p>
<div class="codecolorer-container actionscript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0066CC;">public</span> <span style="color: #0066CC;">dynamic</span> <span style="color: #000000; font-weight: bold;">class</span> MyClass <span style="color: #0066CC;">extends</span> <span style="color: #0066CC;">MovieClip</span> <span style="color: #66cc66;">&#123;</span><br />
<span style="color: #0066CC;">public</span> thePropertyILikeWithAStrangeName:<span style="color: #0066CC;">String</span><br />
<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> MyClass<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
<span style="color: #0066CC;">super</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #66cc66;">&#125;</span><br />
<span style="color: #66cc66;">&#125;</span></div></div>
<p>Now you can:</p>
<div class="codecolorer-container actionscript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">var</span> foo:MyClass = <span style="color: #000000; font-weight: bold;">new</span> MyClass<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
foo.<span style="color: #006600;">anotherProperty</span> = <span style="color: #cc66cc;">42</span>;</div></div>
<p>There are speed and cleaness drawbacks on using dynamic classes. The rule is that if you use it, you should be able to seriously motivate it.</p>
<p>Note that there are few dynamic classes in the default Actionscript framework; the most known is of course, <code class="codecolorer actionscript default"><span class="actionscript"><span style="color: #0066CC;">Object</span></span></code> .</p>
<p>Read more:<br />
<a href="http://livedocs.adobe.com/flash/9.0_it/ActionScriptLangRefV3/statements.html#dynamic" target="_blank">livedocs</a><br />
<a href="http://flexmusings.wordpress.com/2008/06/23/actionscript-3-dynamic-classes/" target="_blank">ActionScript 3: Dynamic Classes</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.nightdrops.com/2009/sealed-and-dynamic-classes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Saving preferences in Air Applications</title>
		<link>http://www.nightdrops.com/2009/saving-preferences-in-air-applications/</link>
		<comments>http://www.nightdrops.com/2009/saving-preferences-in-air-applications/#comments</comments>
		<pubDate>Wed, 15 Apr 2009 09:43:20 +0000</pubDate>
		<dc:creator>kajyr</dc:creator>
				<category><![CDATA[Blog posts]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[AIR]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.nightdrops.com/?p=185</guid>
		<description><![CDATA[Every now and then, while working on a AIR application, i feel the need to save or restore some config info, like the last window position, or the last opened files. Instead of embedding this login in every app, I thought about a PreferenceManager class that stores and restores values. How it should behave: It [...]]]></description>
			<content:encoded><![CDATA[<p>Every now and then, while working on a AIR application, i feel the need to save or restore some config info, like the last window position, or the last opened files.</p>
<p>Instead of embedding this login in every app, I thought about a PreferenceManager class that stores and restores values.</p>
<p>How it should behave:</p>
<ul>
<li>It must save data on a file.</li>
<li>It must save data on an open and editable format, so if something goes wrong..</li>
<li>It should be a static class, so i can access it in every other class of my application, whitout the need to have the reference to the instantiated object.</li>
<li>It should be really simple to use. And should not require any setup.</li>
</ul>
<p><span id="more-185"></span><br />
So having stated this, the public interface looks like this:</p>
<div class="codecolorer-container actionscript3 default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><br /><strong>GeSHi Error:</strong> GeSHi could not find the language actionscript3 (using path /nfs/c03/h01/mnt/85630/domains/nightdrops.com/html/wp-content/plugins/snipplr/geshi/geshi/) (code 2)<br /></div>
<p>Preferences will be saved in a file in File.applicationStorageDirectory called preferences.xml, so every Application will have his own preference file.</p>
<p>The usage comes easy, when I want to save a preference, let&#8217;s say the last user name entered I&#8217;ll</p>
<div class="codecolorer-container actionscript3 default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><br /><strong>GeSHi Error:</strong> GeSHi could not find the language actionscript3 (using path /nfs/c03/h01/mnt/85630/domains/nightdrops.com/html/wp-content/plugins/snipplr/geshi/geshi/) (code 2)<br /></div>
<p>and next time I open the application, to retrieve the data</p>
<div class="codecolorer-container actionscript3 default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><br /><strong>GeSHi Error:</strong> GeSHi could not find the language actionscript3 (using path /nfs/c03/h01/mnt/85630/domains/nightdrops.com/html/wp-content/plugins/snipplr/geshi/geshi/) (code 2)<br /></div>
<p>This implies two things: when i get a preference that hasn&#8217;t been set, the method will return null and I can only save string values.</p>
<p>Sooner or later I&#8217;ll talk about reflection and how to serialize any kind of object.</p>
<p><a href="http://www.nightdrops.com/wp-content/uploads/2009/04/preferences.zip">So now go download the Preferences.as class!</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.nightdrops.com/2009/saving-preferences-in-air-applications/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Navigating through a long page: part 1</title>
		<link>http://www.nightdrops.com/2009/navigating-through-a-long-page-part-1/</link>
		<comments>http://www.nightdrops.com/2009/navigating-through-a-long-page-part-1/#comments</comments>
		<pubDate>Thu, 19 Feb 2009 20:05:59 +0000</pubDate>
		<dc:creator>kajyr</dc:creator>
				<category><![CDATA[Blog posts]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.nightdrops.com/?p=143</guid>
		<description><![CDATA[Sometime i see around websites made just by one page. One really long page which contains all the information and offers some method to navigate up and down. There are many ways to accomplish this, flash or javascript based; i&#8217;m going to talk about the latter, because is kinda easy to learn, and permits me [...]]]></description>
			<content:encoded><![CDATA[<p>Sometime i see around websites made just by one page. One really long page which contains all the information and offers some method to navigate up and down.</p>
<p>There are many ways to accomplish this, flash or javascript based; i&#8217;m going to talk about the latter, because is kinda easy to learn, and permits me to use non destructive javascript.</p>
<p>Non destructive javascript it is a tecnique to use javascript which don&#8217;t rely on javascript for modifying the basic content and structure of the page (so that can be viewed also fully with javascript disabled). What we do, for example, is to use js to hook the anchor links and slightly redirect their behaviour; if you turn off js they remain working anchor links.</p>
<p>I&#8217;m going to use jQuery, i really love this little library :-)</p>
<p>So let&#8217;s start planning!</p>
<h3>The planning phase</h3>
<p>What we have is a really really long html page, on which we need to move up and down. Let&#8217;s say a lot of paragraphs filled with lorem ipsum. We want to scroll up and down really smootly from one link to another, and we want a menu that follow us while moving on the page.</p>
<p>In this tutorial i&#8217;ll explain the scroll aspects, in the next i&#8217;ll talk about the moving menu.</p>
<h3>The basic html structure</h3>
<p>What we expect to have is a menu with voices that leads to some specific areas in the page. In the simplest form we can use html link that points to some anchors, in the form</p>
<div class="codecolorer-container html4strict default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;"><a href="http://december.com/html/4/element/%26amp%3Blt%3CSEMI%3Ea.html"><span style="color: #000000; font-weight: bold;">&lt;a</span></a> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#someId&quot;</span><a href="http://december.com/html/4/element/%26amp%3Bgt%3CSEMI%3E.html"><span style="color: #000000; font-weight: bold;">&gt;</span></a></span>text<span style="color: #009900;"><a href="http://december.com/html/4/element/%26amp%3Blt%3CSEMI%3E%2Fa%26amp%3Bgt%3CSEMI%3E.html"><span style="color: #000000; font-weight: bold;">&lt;/a&gt;</span></a></span></div></div>
<p>that will bring you to somewhere in the page where is an emelent with that id.</p>
<p><a href="http://www.nightdrops.com/kj-includes/js-nav-tutorial/example0.html" target="_blank">This is an example of the basic html structure</a>.<br />
I&#8217;ve added some css rules to semplify what follow, but nothing special.</p>
<h3>Adding the fun</h3>
<p>But that page is boring, everybody wants a funny scroll!</p>
<p>So we introduce the jQuery library in the project. We include the jQuery javascript in the head tag, and at the bottom of the page we prepare a place for our script to go.</p>
<div class="codecolorer-container javascript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #3366CC;">&quot;js/jquery-1.3.1.js&quot;</span></div></div>
<p>Wait. At the bottom of the page? Yes. Just before the &lt;/body&gt; closing tab. Why? Because the <a href="http://developer.yahoo.com/performance/rules.html#js_bottom" target="_blank">Yahoo Exceptional Performance team said so</a>, to not block parallel downloads, and these are good practise to follow (also because IE6 sometimes tend to mess up with the $(document).ready() ).</p>
<p>Now googling around i foun that the html element to animate, to scroll the page, differs from firefox and explorer and safari. You&#8217;ll never guessed eh?<br />
We have to find which one is the right element. A rapid test consist to scroll down both &#8216;html&#8217; and &#8216;body&#8217; and then find out which one has moved. (Of course this goes in the $(document).ready() handler);<br />
Let&#8217;s see:</p>
<div class="codecolorer-container javascript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #3366CC;">'html, body'</span><span style="color: #3366CC;">'html, body'</span><span style="color: #3366CC;">'html'</span><span style="color: #3366CC;">'html'</span><span style="color: #3366CC;">'body'</span><span style="color: #3366CC;">'body'</span><span style="color: #3366CC;">'html, body'</span></div></div>
<p>So now we have to override the default link behaviour. But only in the case links are to id in the page. We can easily select them with the *= operator (that means &#8216;contains&#8217; ).<br />
We also need to know where to scroll:  for an &lt;a&gt; element, the &#8216;hash&#8217; property tells the references element; $(this.hash) is the jQuery wrap to that element in the page. We can easily find his y position by reading the offset() method.</p>
<p>The event.preventDefault() method inhibits the default link behaviour.</p>
<div class="codecolorer-container javascript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #3366CC;">&quot;a[href*=#]&quot;</span></div></div>
<p>Tadaaa! Every link to an id now scrolls smoothly. Notice that i&#8217;ve subtracted 200 pixel from the y position, because i don&#8217;t like the linked element on the top of the browser viewport (so i scroll 200pixel before).</p>
<p><a href="http://www.nightdrops.com/kj-includes/js-nav-tutorial/example1.html" target="_blank">This the example</a>. Soon the following part, where we will animate the menu!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nightdrops.com/2009/navigating-through-a-long-page-part-1/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Creating a Carousel using jQuery</title>
		<link>http://www.nightdrops.com/2009/creating-a-carousel-using-jquery/</link>
		<comments>http://www.nightdrops.com/2009/creating-a-carousel-using-jquery/#comments</comments>
		<pubDate>Mon, 26 Jan 2009 20:22:05 +0000</pubDate>
		<dc:creator>kajyr</dc:creator>
				<category><![CDATA[Blog posts]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.nightdrops.com/?p=103</guid>
		<description><![CDATA[A Carousel is a component used to preview images, a little inline slideshow of thumbnails. There are quite a lot premade carousels ready to be copied and pasted if you don&#8217;t mind about, but i think that this is a nice example to start working with jQuery. Step zero: planning For the structural aspects of [...]]]></description>
			<content:encoded><![CDATA[<p>A Carousel is a component used to preview images, a little inline slideshow of thumbnails. There are quite a lot premade carousels ready to be copied and pasted if you don&#8217;t mind about, but i think that this is a nice example to start working with jQuery.</p>
<h3>Step zero: planning</h3>
<p>For the structural aspects of the carousel we will use a unordered list, masked by a fixed &#8211; width div. The list doesn&#8217;t have a maximum number of elements, we will count the and count their width with the Javascript; obiously the list should now be a traditional vertical list: we&#8217;ll handle this with css.</p>
<p>There&#8217;ll be also two clickable elements, outside the mask, to gently move the list left or right.</p>
<h3>The HTML</h3>
<p>The html is really simple: is just a list wrapped by a div. The div acts like a mask, hiding the images.</p>
<div class="codecolorer-container html4strict default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #ddbb00;">&amp;lt;</span>div id=&quot;carousel&quot;<span style="color: #ddbb00;">&amp;gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><a href="http://december.com/html/4/element/%26amp%3Blt%3CSEMI%3Eul%26amp%3Bgt%3CSEMI%3E.html"><span style="color: #000000; font-weight: bold;">&lt;ul&gt;</span></a></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><a href="http://december.com/html/4/element/%26amp%3Blt%3CSEMI%3Eli%26amp%3Bgt%3CSEMI%3E.html"><span style="color: #000000; font-weight: bold;">&lt;li&gt;</span></a></span> <span style="color: #009900;"><a href="http://december.com/html/4/element/%26amp%3Blt%3CSEMI%3Eimg.html"><span style="color: #000000; font-weight: bold;">&lt;img</span></a> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;...&quot;</span> <span style="color: #000066;">width</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;200&quot;</span> <span style="color: #000066;">height</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;150&quot;</span> <span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/%26amp%3Bgt%3CSEMI%3E.html"><span style="color: #000000; font-weight: bold;">&gt;</span></a></span> <span style="color: #009900;"><a href="http://december.com/html/4/element/%26amp%3Blt%3CSEMI%3E%2Fli%26amp%3Bgt%3CSEMI%3E.html"><span style="color: #000000; font-weight: bold;">&lt;/li&gt;</span></a></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><a href="http://december.com/html/4/element/%26amp%3Blt%3CSEMI%3Eli%26amp%3Bgt%3CSEMI%3E.html"><span style="color: #000000; font-weight: bold;">&lt;li&gt;</span></a></span> <span style="color: #009900;"><a href="http://december.com/html/4/element/%26amp%3Blt%3CSEMI%3Eimg.html"><span style="color: #000000; font-weight: bold;">&lt;img</span></a> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;...&quot;</span> <span style="color: #000066;">width</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;200&quot;</span> <span style="color: #000066;">height</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;150&quot;</span> <span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/%26amp%3Bgt%3CSEMI%3E.html"><span style="color: #000000; font-weight: bold;">&gt;</span></a></span> <span style="color: #009900;"><a href="http://december.com/html/4/element/%26amp%3Blt%3CSEMI%3E%2Fli%26amp%3Bgt%3CSEMI%3E.html"><span style="color: #000000; font-weight: bold;">&lt;/li&gt;</span></a></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ...<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><a href="http://december.com/html/4/element/%26amp%3Blt%3CSEMI%3E%2Ful%26amp%3Bgt%3CSEMI%3E.html"><span style="color: #000000; font-weight: bold;">&lt;/ul&gt;</span></a></span><br />
<br />
<span style="color: #009900;"><a href="http://december.com/html/4/element/%26amp%3Blt%3CSEMI%3Espan.html"><span style="color: #000000; font-weight: bold;">&lt;span</span></a> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;left&quot;</span><a href="http://december.com/html/4/element/%26amp%3Bgt%3CSEMI%3E.html"><span style="color: #000000; font-weight: bold;">&gt;</span></a></span>left<span style="color: #009900;"><a href="http://december.com/html/4/element/%26amp%3Blt%3CSEMI%3E%2Fspan%26amp%3Bgt%3CSEMI%3E.html"><span style="color: #000000; font-weight: bold;">&lt;/span&gt;</span></a></span> | <span style="color: #009900;"><a href="http://december.com/html/4/element/%26amp%3Blt%3CSEMI%3Espan.html"><span style="color: #000000; font-weight: bold;">&lt;span</span></a> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;right&quot;</span><a href="http://december.com/html/4/element/%26amp%3Bgt%3CSEMI%3E.html"><span style="color: #000000; font-weight: bold;">&gt;</span></a></span>right<span style="color: #009900;"><a href="http://december.com/html/4/element/%26amp%3Blt%3CSEMI%3E%2Fspan%26amp%3Bgt%3CSEMI%3E.html"><span style="color: #000000; font-weight: bold;">&lt;/span&gt;</span></a></span></div></div>
<p>We also have the left and right elements. They can be pretty much anything, a good graphic should do the work.</p>
<p>It is important to specify the image width attribute, because the Javascript code will need it to calculate the carousel width.</p>
<h3>The CSS</h3>
<p>The css is in charge of horizontalizing the list, and masking with the div.</p>
<div class="codecolorer-container css default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="css codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #cc00cc;">#carousel <span style="color: #66cc66;">&#123;</span></span><br />
        <span style="color: #000000; font-weight: bold;">overflow</span><span style="color: #66cc66;">:</span> <span style="color: #993333;">hidden</span><span style="color: #66cc66;">;</span><br />
        <span style="color: #000000; font-weight: bold;">position</span><span style="color: #66cc66;">:</span><span style="color: #993333;">relative</span><span style="color: #66cc66;">;</span><br />
        <span style="color: #000000; font-weight: bold;">width</span><span style="color: #66cc66;">:</span> 500px<span style="color: #66cc66;">;</span><br />
        <span style="color: #000000; font-weight: bold;">height</span><span style="color: #66cc66;">:</span> 150px<span style="color: #66cc66;">;</span><br />
        <span style="color: #000000; font-weight: bold;">list-style</span><span style="color: #66cc66;">:</span> <span style="color: #993333;">none</span><span style="color: #66cc66;">;</span><br />
    <span style="color: #66cc66;">&#125;</span></div></div>
<p>Note that we specify the height and width of the component here; we also specify position:relative, which should have really no sense, but is here only to cover a bug in IE7, just like is explained <a href="http://www.davidonzo.com/post/801/ie7-bug-overflowhidden-e-positionrelative/">here</a> (in italian)</p>
<div class="codecolorer-container css default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="css codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">    #carousel ul <span style="color: #66cc66;">&#123;</span><br />
        <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #66cc66;">:</span> 0px<span style="color: #66cc66;">;</span><br />
        <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #66cc66;">:</span> 0px<span style="color: #66cc66;">;</span><br />
        <span style="color: #000000; font-weight: bold;">position</span><span style="color: #66cc66;">:</span><span style="color: #993333;">relative</span><span style="color: #66cc66;">;</span><br />
    <span style="color: #66cc66;">&#125;</span><br />
    #carousel li <span style="color: #66cc66;">&#123;</span><br />
        <span style="color: #000000; font-weight: bold;">display</span><span style="color: #66cc66;">:</span> <span style="color: #993333;">inline</span><span style="color: #66cc66;">;</span><br />
    <span style="color: #66cc66;">&#125;</span><br />
<br />
    #carousel img <span style="color: #66cc66;">&#123;</span><br />
        <span style="color: #000000; font-weight: bold;">border</span><span style="color: #66cc66;">:</span> 0px<span style="color: #66cc66;">;</span><br />
    <span style="color: #66cc66;">&#125;</span></div></div>
<p>This should explain by himself. The ul position is relative because we want to move it.</p>
<div id="attachment_119" class="wp-caption aligncenter" style="width: 410px"><a href="http://www.nightdrops.com/wp-content/uploads/2009/01/carousel_step2.png"  rel="lightbox[alpha]"><img class="size-full wp-image-119" title="carousel_step2" src="http://www.nightdrops.com/wp-content/uploads/2009/01/carousel_step2.png" alt="So now you should have a non - moving carousel. Funny. Ah." width="400" height="136" /></a><p class="wp-caption-text">So now you should have a non moving carousel. Funny. Ah.</p></div>
<h3>And finally.. Javascript!</h3>
<p>Here&#8217;s where the magic happens..</p>
<p>Fist thing: importing the right files: jquery.js and the easing plugin (we want a sexy movement, not a linear one!). Remember to do this in the &lt;head&gt; tag</p>
<div class="codecolorer-container javascript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #3366CC;">&quot;js/jquery-1.3.1.min.js&quot;</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #3366CC;">&quot;js/jquery.easing.1.2.js&quot;</span></div></div>
<p>Next, we will add some code (in a script tag, obiously):</p>
<div class="codecolorer-container javascript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #3366CC;">&quot;#carousel ul img&quot;</span><span style="color: #3366CC;">&quot;#carousel ul&quot;</span><span style="color: #3366CC;">&quot;width&quot;</span></div></div>
<p>What&#8217;s happening here?  We have a variable, called shift, which we will use to controll how much we want to slide the list each time; Next we bind a function to the document ready event &#8211; when all the page has finisched loading. We use the ulWidth variable to sum all the single thumbnail&#8217;s width. We initializa it to 0 and then, for each img tag in the list, we will sum the outerWidth() (and a little padding, to be nice); <a href="http://docs.jquery.com/CSS/outerWidth">outherWidth()</a> is a nice jQuery function that report the width of an element, including margins.</p>
<div class="codecolorer-container javascript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #3366CC;">&quot;#right&quot;</span><span style="color: #3366CC;">&quot;#carousel ul&quot;</span><span style="color: #3366CC;">&quot;#carousel ul&quot;</span><span style="color: #3366CC;">&quot;#carousel&quot;</span><span style="color: #3366CC;">&quot;#carousel&quot;</span><span style="color: #3366CC;">&quot;#carousel ul&quot;</span><span style="color: #3366CC;">&quot;#carousel ul&quot;</span><span style="color: #3366CC;">&quot;px&quot;</span><span style="color: #3366CC;">&quot;easeInExpo&quot;</span><span style="color: #3366CC;">&quot;#left&quot;</span><span style="color: #3366CC;">&quot;#carousel ul&quot;</span><span style="color: #3366CC;">&quot;#carousel ul&quot;</span><span style="color: #3366CC;">&quot;px&quot;</span><span style="color: #3366CC;">&quot;easeInExpo&quot;</span></div></div>
<p>Here, we setup the onClick handlers over the left and right elements. When you&#8217;ll click one of these, the magic should happen..<br />
For each handler we read the <a href="http://docs.jquery.com/CSS/position">position().left</a> property and sum the amount that we want to scroll( the shift variable).</p>
<p>It it important to check that the right edge of the list (the left edge + the width) should stay out (on the right) of the viewport, or else we will see the list background. We don&#8217;t want to scroll when there are no more images!<br />
The same thing for the left edge, when we scroll left, or else there be space on the left of the first image.</p>
<p><strong>And&#8230; it works!</strong> Try the <a href="http://www.nightdrops.com/kj-includes/jQueryCarousel">demo</a>, or<a href="http://www.nightdrops.com/wp-content/uploads/2009/01/carousel.zip"> download the examples</a></p>
<h3>Further readings:</h3>
<p>the Carousel Pattern on the <a href="http://developer.yahoo.com/ypatterns/pattern.php?pattern=carousel">Yahoo Design Pattern Library</a> and the really good <a href="http://docs.jquery.com/Main_Page">JQuery documentation</a><br />
Credits to <a href="http://www.webdevlounge.com/javascript/creating-a-carousel-with-mootools/">webdevlonge</a> which has a really nice tutorial on creating a carousel with mootools</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nightdrops.com/2009/creating-a-carousel-using-jquery/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
