<?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>jc-designs.net &#187; Javascript</title>
	<atom:link href="http://jc-designs.net/blog/tag/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://jc-designs.net/blog</link>
	<description>jc-designs blog</description>
	<lastBuildDate>Mon, 16 Jan 2012 15:30:50 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>How to Build a Horizontal jQuery Accordion</title>
		<link>http://jc-designs.net/blog/2011/07/how-to-build-a-horizontal-jquery-accordion/</link>
		<comments>http://jc-designs.net/blog/2011/07/how-to-build-a-horizontal-jquery-accordion/#comments</comments>
		<pubDate>Thu, 21 Jul 2011 14:29:21 +0000</pubDate>
		<dc:creator>jcDesigns</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[accordion]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[slider]]></category>

		<guid isPermaLink="false">http://jc-designs.net/blog/?p=965</guid>
		<description><![CDATA[Sliders, accordions oh my! If you search for jQuery slider, you will find tons of posts and articles on how to do so. There are plenty of ways of building one, and I haven&#8217;t really seen any two that were exactly the same. Hell, even I wrote on how to build a jQuery slider, using [...]]]></description>
			<content:encoded><![CDATA[<h3>Sliders, accordions oh my!</h3>
<p>If you search for jQuery slider, you will find tons of posts and articles on how to do so. There are plenty of ways of building one, and I haven&#8217;t really seen any two that were exactly the same. Hell, even I wrote on <a href="http://jc-designs.net/blog/2010/03/jquery-slider-tutorial-for-beginners-how-i-did-mine/">how to build a jQuery slider</a>, using the slider on this blog as an example. You know what is quite difficult to find though? Tutorials on horizontal accordions. I had a hell of a time figuring out how, because most of the articles are about using a plugin. Which, if you have read any of my posts in the past, you will know that I like to do things myself most of the time. I only found one that was super helpful, and it was buried a few pages in. The only problem is that it was using an unordered list, and I needed it to use divs. Luckily for me it was easy to change, and if you care to view the original tutorial over at <a href="http://www.designchemical.com/blog/index.php/jquery/jquery-simple-horizontal-accordion/">Design Chemical</a> (written by a guy named Lee I believe), please do so and tell him he rocks. Take a look at the demo first so you can see what the end result looks like.</p>
<p><a class="viewDemo" href="http://www.jc-designs.net/demo/accordion.html" target="_blank">View Demo</a></p>
<p><span id="more-965"></span></p>
<h3>First things first &#8211; the HTML</h3>
<p>Let me first state that the there is an issue with IE7 with the HTML/CSS. The Javascript works fine, but the image is too far over. I will post the corrections for it later, I just wanted to get the post up for you since it has been a while since I have written anything.</p>
<p><strong>Note: I am only showing one panel below, but I am using 4. You can see the all of them if you view the source in the demo</strong></p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;color: #439AD0; font-weight: bold;">&lt;div id=&quot;accordion&quot;&gt;
    &lt;div class=&quot;panel&quot;&gt;
      &lt;div class=&quot;pink&quot;&gt;&lt;/div&gt;
      &lt;div class=&quot;panelContent p1&quot;&gt; &lt;strong&gt;Section 1 Header&lt;/strong&gt;&lt;br/&gt;
        Lorem ipsum dolor sit amet, consectetur adipiscing elit. In iaculis volutpat quam, non suscipit arcu accumsan at. Aliquam pellentesque.
      &lt;/div&gt;
&lt;/div&gt;</pre></div></div>

<p>As you can see, there is not much there. If you looked at the demo, you will see what is going on in the above HTML. A wrapper (&#8216;#accordion&#8217;), a div for each little pink section (.&#8217;pink&#8217;), a div for each individual panel (&#8216;.panel&#8217;), and the content within &#8211; pretty easy stuff.</p>
<h3>The styles</h3>
<p>Again, not much going on with the styles. Below is the important stuff, which doesn&#8217;t include the classes that call the individual pink bar images.</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;color: #439AD0; font-weight: bold;"><span style="color: #cc00cc;">#accordion</span> <span style="color: #00AA00;color: #439AD0;">&#123;</span>
	<span style="color: #000000; font-weight: bold;color: #439AD0;">list-style</span><span style="color: #00AA00;color: #439AD0;">:</span><span style="color: #993333;color: #439AD0;">none</span><span style="color: #00AA00;color: #439AD0;">;</span>
	<span style="color: #000000; font-weight: bold;color: #439AD0;">margin</span><span style="color: #00AA00;color: #439AD0;">:</span><span style="color: #933;">30px</span> <span style="color: #cc66cc;color: #439AD0;">0</span><span style="color: #00AA00;color: #439AD0;">;</span>
	<span style="color: #000000; font-weight: bold;color: #439AD0;">padding</span><span style="color: #00AA00;color: #439AD0;">:</span><span style="color: #cc66cc;color: #439AD0;">0</span><span style="color: #00AA00;color: #439AD0;">;</span>
	<span style="color: #000000; font-weight: bold;color: #439AD0;">height</span><span style="color: #00AA00;color: #439AD0;">:</span><span style="color: #933;">270px</span><span style="color: #00AA00;color: #439AD0;">;</span>
	<span style="color: #000000; font-weight: bold;color: #439AD0;">width</span><span style="color: #00AA00;color: #439AD0;">:</span><span style="color: #933;">980px</span><span style="color: #00AA00;color: #439AD0;">;</span>
	<span style="color: #000000; font-weight: bold;color: #439AD0;">margin</span><span style="color: #00AA00;color: #439AD0;">:</span><span style="color: #cc66cc;color: #439AD0;">0</span> <span style="color: #cc66cc;color: #439AD0;">0</span> <span style="color: #cc66cc;color: #439AD0;">0</span> <span style="color: #933;">11px</span><span style="color: #00AA00;color: #439AD0;">;</span>
	<span style="color: #000000; font-weight: bold;color: #439AD0;">border-top</span><span style="color: #00AA00;color: #439AD0;">:</span><span style="color: #933;">2px</span> <span style="color: #993333;color: #439AD0;">solid</span> <span style="color: #cc00cc;">#000000</span><span style="color: #00AA00;color: #439AD0;">;</span>
	<span style="color: #000000; font-weight: bold;color: #439AD0;">border-bottom</span><span style="color: #00AA00;color: #439AD0;">:</span><span style="color: #933;">2px</span> <span style="color: #993333;color: #439AD0;">solid</span> <span style="color: #cc00cc;">#000000</span><span style="color: #00AA00;color: #439AD0;">;</span>
	<span style="color: #000000; font-weight: bold;color: #439AD0;">overflow</span><span style="color: #00AA00;color: #439AD0;">:</span><span style="color: #993333;color: #439AD0;">hidden</span><span style="color: #00AA00;color: #439AD0;">;</span>
<span style="color: #00AA00;color: #439AD0;">&#125;</span>
<span style="color: #cc00cc;">#accordion</span> <span style="color: #6666ff;color: #439AD0;">.panel</span> <span style="color: #00AA00;color: #439AD0;">&#123;</span>
	<span style="color: #000000; font-weight: bold;color: #439AD0;">float</span><span style="color: #00AA00;color: #439AD0;">:</span><span style="color: #000000; font-weight: bold;color: #439AD0;">left</span><span style="color: #00AA00;color: #439AD0;">;</span>
	<span style="color: #000000; font-weight: bold;color: #439AD0;">display</span><span style="color: #00AA00;color: #439AD0;">:</span><span style="color: #993333;color: #439AD0;">block</span><span style="color: #00AA00;color: #439AD0;">;</span>
	<span style="color: #000000; font-weight: bold;color: #439AD0;">height</span><span style="color: #00AA00;color: #439AD0;">:</span><span style="color: #933;">270px</span><span style="color: #00AA00;color: #439AD0;">;</span>
	<span style="color: #000000; font-weight: bold;color: #439AD0;">width</span><span style="color: #00AA00;color: #439AD0;">:</span><span style="color: #933;">44px</span><span style="color: #00AA00;color: #439AD0;">;</span>
	<span style="color: #000000; font-weight: bold;color: #439AD0;">overflow</span><span style="color: #00AA00;color: #439AD0;">:</span><span style="color: #993333;color: #439AD0;">hidden</span><span style="color: #00AA00;color: #439AD0;">;</span>
	<span style="color: #000000; font-weight: bold;color: #439AD0;">color</span><span style="color: #00AA00;color: #439AD0;">:</span><span style="color: #cc00cc;">#666666</span><span style="color: #00AA00;color: #439AD0;">;</span>
	<span style="color: #000000; font-weight: bold;color: #439AD0;">text-decoration</span><span style="color: #00AA00;color: #439AD0;">:</span><span style="color: #993333;color: #439AD0;">none</span><span style="color: #00AA00;color: #439AD0;">;</span>
	<span style="color: #000000; font-weight: bold;color: #439AD0;">font-size</span><span style="color: #00AA00;color: #439AD0;">:</span><span style="color: #933;">16px</span><span style="color: #00AA00;color: #439AD0;">;</span>
	<span style="color: #000000; font-weight: bold;color: #439AD0;">line-height</span><span style="color: #00AA00;color: #439AD0;">:</span><span style="color: #933;">1.5em</span>
<span style="color: #00AA00;color: #439AD0;">&#125;</span>
<span style="color: #cc00cc;">#accordion</span> <span style="color: #6666ff;color: #439AD0;">.panel</span><span style="color: #6666ff;color: #439AD0;">.active</span> <span style="color: #00AA00;color: #439AD0;">&#123;</span>
	<span style="color: #000000; font-weight: bold;color: #439AD0;">width</span><span style="color: #00AA00;color: #439AD0;">:</span><span style="color: #933;">848px</span>
<span style="color: #00AA00;color: #439AD0;">&#125;</span>
<span style="color: #6666ff;color: #439AD0;">.panelContent</span> <span style="color: #00AA00;color: #439AD0;">&#123;</span>
	<span style="color: #000000; font-weight: bold;color: #439AD0;">padding</span><span style="color: #00AA00;color: #439AD0;">:</span><span style="color: #933;">15px</span> <span style="color: #933;">15px</span> <span style="color: #933;">15px</span> <span style="color: #933;">55px</span><span style="color: #00AA00;color: #439AD0;">;</span>
	<span style="color: #000000; font-weight: bold;color: #439AD0;">height</span><span style="color: #00AA00;color: #439AD0;">:</span><span style="color: #933;">240px</span><span style="color: #00AA00;color: #439AD0;">;</span>
	<span style="color: #000000; font-weight: bold;color: #439AD0;">width</span><span style="color: #00AA00;color: #439AD0;">:</span><span style="color: #933;">778px</span><span style="color: #00AA00;color: #439AD0;">;</span>
<span style="color: #00AA00;color: #439AD0;">&#125;</span>
<span style="color: #6666ff;color: #439AD0;">.pink</span> <span style="color: #00AA00;color: #439AD0;">&#123;</span>
	<span style="color: #000000; font-weight: bold;color: #439AD0;">width</span><span style="color: #00AA00;color: #439AD0;">:</span><span style="color: #933;">42px</span><span style="color: #00AA00;color: #439AD0;">;</span>
	<span style="color: #000000; font-weight: bold;color: #439AD0;">height</span><span style="color: #00AA00;color: #439AD0;">:</span><span style="color: #933;">270px</span><span style="color: #00AA00;color: #439AD0;">;</span>
	<span style="color: #000000; font-weight: bold;color: #439AD0;">float</span><span style="color: #00AA00;color: #439AD0;">:</span><span style="color: #000000; font-weight: bold;color: #439AD0;">left</span><span style="color: #00AA00;color: #439AD0;">;</span>
	<span style="color: #000000; font-weight: bold;color: #439AD0;">background</span><span style="color: #00AA00;color: #439AD0;">:</span><span style="color: #993333;color: #439AD0;">url</span><span style="color: #00AA00;color: #439AD0;">&#40;</span><span style="color: #ff0000; font-style: italic;">../images/accordionSprite.png</span><span style="color: #00AA00;color: #439AD0;">&#41;</span> <span style="color: #993333;color: #439AD0;">no-repeat</span> <span style="color: #933;">4px</span> <span style="color: #933;">85px</span> <span style="color: #cc00cc;">#f980a1</span><span style="color: #00AA00;color: #439AD0;">;</span>
	<span style="color: #000000; font-weight: bold;color: #439AD0;">border-right</span><span style="color: #00AA00;color: #439AD0;">:</span><span style="color: #933;">2px</span> <span style="color: #993333;color: #439AD0;">solid</span> <span style="color: #cc00cc;">#ffffff</span><span style="color: #00AA00;color: #439AD0;">;</span>
	<span style="color: #000000; font-weight: bold;color: #439AD0;">cursor</span><span style="color: #00AA00;color: #439AD0;">:</span><span style="color: #993333;color: #439AD0;">pointer</span>
<span style="color: #00AA00;color: #439AD0;">&#125;</span>
<span style="color: #6666ff;color: #439AD0;">.last</span> <span style="color: #00AA00;color: #439AD0;">&#123;</span>
	<span style="color: #000000; font-weight: bold;color: #439AD0;">border</span><span style="color: #00AA00;color: #439AD0;">:</span><span style="color: #993333;color: #439AD0;">none</span>
<span style="color: #00AA00;color: #439AD0;">&#125;</span></pre></div></div>

<p>Some things to note about the CSS. My total width is 980px. The reason the active panel (the one showing) is 848px is because there are 4 panels, 3 of which are closed and each of them have a total width of 44px. So 980 &#8211; (44 x 3) = 848px. It is 44px because the width is 42px plus a two pixel border. See, there is some math you have to do to get everything to fit correctly. Make sure you are paying attention to that when you are building your own.</p>
<h3>jQuery please!</h3>
<p>Now on to what you really wanted to see, right? I&#8217;ll explain what is happening below.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;color: #439AD0; font-weight: bold;">$<span style="color: #009900;color: #439AD0;">&#40;</span>document<span style="color: #009900;color: #439AD0;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #003366; font-weight: bold;color: #439AD0;">function</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #009900;color: #439AD0;">&#41;</span><span style="color: #009900;color: #439AD0;">&#123;</span>
&nbsp;
    activePanel <span style="color: #339933;color: #439AD0;">=</span> $<span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #3366CC;color: #439AD0;">&quot;#accordion div.panel:first&quot;</span><span style="color: #009900;color: #439AD0;">&#41;</span><span style="color: #339933;color: #439AD0;">;</span>
    $<span style="color: #009900;color: #439AD0;">&#40;</span>activePanel<span style="color: #009900;color: #439AD0;">&#41;</span>.<span style="color: #660066;">addClass</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #3366CC;color: #439AD0;">'active'</span><span style="color: #009900;color: #439AD0;">&#41;</span><span style="color: #339933;color: #439AD0;">;</span>
&nbsp;
    $<span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #3366CC;color: #439AD0;">&quot;#accordion&quot;</span><span style="color: #009900;color: #439AD0;">&#41;</span>.<span style="color: #660066;">delegate</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #3366CC;color: #439AD0;">'.panel'</span><span style="color: #339933;color: #439AD0;">,</span> <span style="color: #3366CC;color: #439AD0;">'click'</span><span style="color: #339933;color: #439AD0;">,</span> <span style="color: #003366; font-weight: bold;color: #439AD0;">function</span><span style="color: #009900;color: #439AD0;">&#40;</span>e<span style="color: #009900;color: #439AD0;">&#41;</span><span style="color: #009900;color: #439AD0;">&#123;</span>
        <span style="color: #000066; font-weight: bold;color: #439AD0;">if</span><span style="color: #009900;color: #439AD0;">&#40;</span> <span style="color: #339933;color: #439AD0;">!</span> $<span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #000066; font-weight: bold;color: #439AD0;">this</span><span style="color: #009900;color: #439AD0;">&#41;</span>.<span style="color: #000066; font-weight: bold;color: #439AD0;">is</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #3366CC;color: #439AD0;">'.active'</span><span style="color: #009900;color: #439AD0;">&#41;</span> <span style="color: #009900;color: #439AD0;">&#41;</span><span style="color: #009900;color: #439AD0;">&#123;</span>
			$<span style="color: #009900;color: #439AD0;">&#40;</span>activePanel<span style="color: #009900;color: #439AD0;">&#41;</span>.<span style="color: #660066;">animate</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #009900;color: #439AD0;">&#123;</span>width<span style="color: #339933;color: #439AD0;">:</span> <span style="color: #3366CC;color: #439AD0;">&quot;44px&quot;</span><span style="color: #009900;color: #439AD0;">&#125;</span><span style="color: #339933;color: #439AD0;">,</span> <span style="color: #CC0000;color: #439AD0;">300</span><span style="color: #009900;color: #439AD0;">&#41;</span><span style="color: #339933;color: #439AD0;">;</span>
			$<span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #000066; font-weight: bold;color: #439AD0;">this</span><span style="color: #009900;color: #439AD0;">&#41;</span>.<span style="color: #660066;">animate</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #009900;color: #439AD0;">&#123;</span>width<span style="color: #339933;color: #439AD0;">:</span> <span style="color: #3366CC;color: #439AD0;">&quot;848px&quot;</span><span style="color: #009900;color: #439AD0;">&#125;</span><span style="color: #339933;color: #439AD0;">,</span> <span style="color: #CC0000;color: #439AD0;">300</span><span style="color: #009900;color: #439AD0;">&#41;</span><span style="color: #339933;color: #439AD0;">;</span>
			$<span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #3366CC;color: #439AD0;">'#accordion .panel'</span><span style="color: #009900;color: #439AD0;">&#41;</span>.<span style="color: #660066;">removeClass</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #3366CC;color: #439AD0;">'active'</span><span style="color: #009900;color: #439AD0;">&#41;</span><span style="color: #339933;color: #439AD0;">;</span>
			$<span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #000066; font-weight: bold;color: #439AD0;">this</span><span style="color: #009900;color: #439AD0;">&#41;</span>.<span style="color: #660066;">addClass</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #3366CC;color: #439AD0;">'active'</span><span style="color: #009900;color: #439AD0;">&#41;</span><span style="color: #339933;color: #439AD0;">;</span>
			activePanel <span style="color: #339933;color: #439AD0;">=</span> <span style="color: #000066; font-weight: bold;color: #439AD0;">this</span><span style="color: #339933;color: #439AD0;">;</span>
		 <span style="color: #009900;color: #439AD0;">&#125;</span><span style="color: #339933;color: #439AD0;">;</span>
    <span style="color: #009900;color: #439AD0;">&#125;</span><span style="color: #009900;color: #439AD0;">&#41;</span><span style="color: #339933;color: #439AD0;">;</span>
<span style="color: #009900;color: #439AD0;">&#125;</span><span style="color: #009900;color: #439AD0;">&#41;</span><span style="color: #339933;color: #439AD0;">;</span></pre></div></div>

<p>Once again, not a heck of a lot of code to get this thing going. The first two lines, after the document ready thing of course, is for getting the first panel within the wrapper (&#8216;#accordion&#8217;), and giving it a class of &#8216;active&#8217;. All that class does is change the width from 44px to 848px. Whichever panel has the &#8216;active&#8217; class is the one that is showing.</p>
<p>Next comes the click function, which I am using delegate() for so that there is only one event handler, rather than one for each panel. Then the script checks to see if the panel click is NOT the active one, and if it isn&#8217;t, animate the active one&#8217;s width down to 44px, with the animation time set to 300. Then animate the panel that was clicked, so that it&#8217;s width becomes 848px, at the same speed.</p>
<p>After that, it removes the &#8216;active&#8217; class from all of the panels, and adds the class back to the one that was clicked. The last line then makes the &#8216;activePanel&#8217; variable be the panel that was clicked.</p>
<p>One last note. I did have the following in place of the 300 speed, but it didn&#8217;t seem to need it, so I took it out. It clears the animation queue, but I think the accordion moves so fast that it doesn&#8217;t seem to matter if it is in the script.</p>
<pre lang="javascript">
$(activePanel).animate({width: "44px"}, {duration:300, queue:false});<br />
$(this).animate({width: "848px"}, {duration:300, queue:false});
</pre</p>
<h3>Conclusion</h3>
<p>I am using this exact script in a freelance project I am working on (which I will show you guys when it's done), and I am pretty happy with it. Again, I have to change the HTML and CSS around because of IE7's issue, but the script itself works great in 7 or 8. Didn't check IE6 because I don't really care anymore unless someone specifically asks for it to be supported.</p>
<p>Let me know what you think, and leave a comment!</p>
<div class="gator">
<a  href="http://secure.hostgator.com/~affiliat/cgi-bin/affiliates/clickthru.cgi?id=jcDesigns-" rel="nofollow"><img src="http://tracking.hostgator.com/img/Shared/468x60.gif" border=0></a></p>
<p>Coupon Code: webmachine</p>
</div>
 <img src="http://jc-designs.net/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=965" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://jc-designs.net/blog/2011/07/how-to-build-a-horizontal-jquery-accordion/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tutorial On Using setInterval To Make A jQuery Rotator</title>
		<link>http://jc-designs.net/blog/2011/04/tutorial-on-using-setinterval-to-make-a-jquery-rotator/</link>
		<comments>http://jc-designs.net/blog/2011/04/tutorial-on-using-setinterval-to-make-a-jquery-rotator/#comments</comments>
		<pubDate>Thu, 21 Apr 2011 14:43:14 +0000</pubDate>
		<dc:creator>jcDesigns</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://jc-designs.net/blog/?p=888</guid>
		<description><![CDATA[A combination of things I was tasked last week with building&#8230;well, I don&#8217;t know what the hell to call it, but at work we named it &#8220;the wheel.&#8221; Basically, it is a circle with a bunch of gray icons around it. I needed to get them to change to blue, show a larger graphic with [...]]]></description>
			<content:encoded><![CDATA[<h3>A combination of things</h3>
<p>I was tasked last week with building&#8230;well, I don&#8217;t know what the hell to call it, but at work we named it &#8220;the wheel.&#8221; Basically, it is a circle with a bunch of gray icons around it. I needed to get them to change to blue, show a larger graphic with additional content, and change to the next icon after a certain amount of time. When one of the icons is clicked though, the animation has to stop, and show whatever content goes with that icon. I used setInterval to accomplish the rotation through the icons, and pretty much the same jQuery I used on the <a href="http://jc-designs.net/blog/2011/04/jquery-portfolio-content-gallery/">Portfolio Content Gallery</a> I wrote about. You&#8217;ll get a better idea of what I am talking about if you see it. I sped up the rotation so you don&#8217;t have to wait as long.</p>
<p><a class="viewDemo" href="http://www.jc-designs.net/demo/wheel/wheel.html" target="_blank">View Demo</a></p>
<p>I&#8217;m still learning Javascript/jQuery, and I have never used setInterval before, so this was a lesson for me as well. Turns out it is actually pretty easy, but I thought I would show you how to accomplish this so you don&#8217;t have to do any ridiculous searches like I did.</p>
<p><span id="more-888"></span></p>
<h3>The HTML you need</h3>
<p>There is not a lot to this, but seeing the structure will help. The only difference between this and the actual HTML I used is that there are eight content divs, where I am only showing one below. You can view all of the HTML in the demo.</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;color: #439AD0; font-weight: bold;">&lt;div id=&quot;wheelContainer&quot;&gt;
	&lt;div id=&quot;wheel&quot;&gt;
		&lt;div id=&quot;wheelOne&quot; class=&quot;wheelIcon&quot;&gt;&lt;a href=&quot;#&quot;&gt;&lt;/a&gt;&lt;/div&gt;
		&lt;div id=&quot;wheelTwo&quot; class=&quot;wheelIcon&quot;&gt;&lt;a href=&quot;#&quot;&gt;&lt;/a&gt;&lt;/div&gt;
		&lt;div id=&quot;wheelThree&quot; class=&quot;wheelIcon&quot;&gt;&lt;a href=&quot;#&quot;&gt;&lt;/a&gt;&lt;/div&gt;
		&lt;div id=&quot;wheelFour&quot; class=&quot;wheelIcon&quot;&gt;&lt;a href=&quot;#&quot;&gt;&lt;/a&gt;&lt;/div&gt;
		&lt;div id=&quot;wheelFive&quot; class=&quot;wheelIcon&quot;&gt;&lt;a href=&quot;#&quot;&gt;&lt;/a&gt;&lt;/div&gt;
		&lt;div id=&quot;wheelSix&quot; class=&quot;wheelIcon&quot;&gt;&lt;a href=&quot;#&quot;&gt;&lt;/a&gt;&lt;/div&gt;
		&lt;div id=&quot;wheelSeven&quot; class=&quot;wheelIcon&quot;&gt;&lt;a href=&quot;#&quot;&gt;&lt;/a&gt;&lt;/div&gt;
		&lt;div id=&quot;wheelEight&quot; class=&quot;wheelIcon&quot;&gt;&lt;a href=&quot;#&quot;&gt;&lt;/a&gt;&lt;/div&gt;
	&lt;/div&gt;
        &lt;div id=&quot;wheelContentContainer&quot;&gt;
		&lt;div id=&quot;wheelOneContent&quot; class=&quot;wheelContent&quot;&gt;
			&lt;div class=&quot;wheelLargeImage&quot; id=&quot;wheelImage1&quot;&gt;&lt;/div&gt;
			&lt;div class=&quot;wheelText&quot;&gt;
				&lt;p class=&quot;wheelHeading&quot;&gt;Websites&lt;/p&gt;
				&lt;p&gt;Content 1 goes here&lt;/p&gt;
			&lt;/div&gt;
		&lt;/div&gt;
         &lt;/div&gt;
&lt;/div&gt;</pre></div></div>

<h3>The jQuery using setInterval</h3>
<p>I&#8217;ll show you all of the jQuery I used, and then go through it line by line to explain what is going on.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;color: #439AD0; font-weight: bold;">$<span style="color: #009900;color: #439AD0;">&#40;</span>document<span style="color: #009900;color: #439AD0;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #003366; font-weight: bold;color: #439AD0;">function</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #009900;color: #439AD0;">&#41;</span> <span style="color: #009900;color: #439AD0;">&#123;</span>
	<span style="color: #003366; font-weight: bold;color: #439AD0;">var</span> wheels <span style="color: #339933;color: #439AD0;">=</span> $<span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #3366CC;color: #439AD0;">'.wheelIcon'</span><span style="color: #009900;color: #439AD0;">&#41;</span><span style="color: #339933;color: #439AD0;">;</span>
        <span style="color: #003366; font-weight: bold;color: #439AD0;">var</span> content <span style="color: #339933;color: #439AD0;">=</span> $<span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #3366CC;color: #439AD0;">'.wheelContent'</span><span style="color: #009900;color: #439AD0;">&#41;</span><span style="color: #339933;color: #439AD0;">;</span>
&nbsp;
	$<span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #3366CC;color: #439AD0;">'#wheel'</span><span style="color: #009900;color: #439AD0;">&#41;</span>.<span style="color: #660066;">delegate</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #3366CC;color: #439AD0;">'div'</span><span style="color: #339933;color: #439AD0;">,</span> <span style="color: #3366CC;color: #439AD0;">'click'</span><span style="color: #339933;color: #439AD0;">,</span> <span style="color: #003366; font-weight: bold;color: #439AD0;">function</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #009900;color: #439AD0;">&#41;</span><span style="color: #009900;color: #439AD0;">&#123;</span>
		stopRotation<span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #009900;color: #439AD0;">&#41;</span><span style="color: #339933;color: #439AD0;">;</span>
		<span style="color: #006600; font-style: italic;color: #439AD0;">//change the background-position on x-axis so that they become blue icons</span>
		wheels.<span style="color: #660066;">removeClass</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #3366CC;color: #439AD0;">'imageChange'</span><span style="color: #009900;color: #439AD0;">&#41;</span><span style="color: #339933;color: #439AD0;">;</span>
		$<span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #000066; font-weight: bold;color: #439AD0;">this</span><span style="color: #009900;color: #439AD0;">&#41;</span>.<span style="color: #660066;">addClass</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #3366CC;color: #439AD0;">'imageChange'</span><span style="color: #009900;color: #439AD0;">&#41;</span><span style="color: #339933;color: #439AD0;">;</span>
&nbsp;
&nbsp;
		<span style="color: #006600; font-style: italic;color: #439AD0;">//Show or hide the content divs based on which icon is clicked</span>
			$<span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #3366CC;color: #439AD0;">'.wheelContent'</span><span style="color: #009900;color: #439AD0;">&#41;</span>.<span style="color: #660066;">fadeOut</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #009900;color: #439AD0;">&#41;</span>.<span style="color: #660066;">delay</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #CC0000;color: #439AD0;">500</span><span style="color: #009900;color: #439AD0;">&#41;</span><span style="color: #339933;color: #439AD0;">;</span>
			$<span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #3366CC;color: #439AD0;">'.wheelContent'</span><span style="color: #009900;color: #439AD0;">&#41;</span>.<span style="color: #660066;">eq</span><span style="color: #009900;color: #439AD0;">&#40;</span>$<span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #000066; font-weight: bold;color: #439AD0;">this</span><span style="color: #009900;color: #439AD0;">&#41;</span>.<span style="color: #660066;">index</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #009900;color: #439AD0;">&#41;</span><span style="color: #009900;color: #439AD0;">&#41;</span>.<span style="color: #660066;">fadeIn</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #009900;color: #439AD0;">&#41;</span><span style="color: #339933;color: #439AD0;">;</span>	
	<span style="color: #009900;color: #439AD0;">&#125;</span><span style="color: #009900;color: #439AD0;">&#41;</span><span style="color: #339933;color: #439AD0;">;</span>
&nbsp;
	<span style="color: #003366; font-weight: bold;color: #439AD0;">function</span> rotation<span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #009900;color: #439AD0;">&#41;</span> <span style="color: #009900;color: #439AD0;">&#123;</span>
		rotateIcon <span style="color: #339933;color: #439AD0;">=</span> setInterval<span style="color: #009900;color: #439AD0;">&#40;</span>nextIcon<span style="color: #339933;color: #439AD0;">,</span> <span style="color: #CC0000;color: #439AD0;">4000</span><span style="color: #009900;color: #439AD0;">&#41;</span><span style="color: #339933;color: #439AD0;">;</span>
	<span style="color: #009900;color: #439AD0;">&#125;</span>
&nbsp;
	i <span style="color: #339933;color: #439AD0;">=</span> <span style="color: #CC0000;color: #439AD0;">0</span><span style="color: #339933;color: #439AD0;">;</span>
&nbsp;
	<span style="color: #003366; font-weight: bold;color: #439AD0;">function</span> nextIcon<span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #009900;color: #439AD0;">&#41;</span> <span style="color: #009900;color: #439AD0;">&#123;</span>
		wheels.<span style="color: #660066;">removeClass</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #3366CC;color: #439AD0;">'imageChange'</span><span style="color: #009900;color: #439AD0;">&#41;</span><span style="color: #339933;color: #439AD0;">;</span>
		$<span style="color: #009900;color: #439AD0;">&#40;</span>wheels<span style="color: #009900;color: #439AD0;">&#91;</span>i<span style="color: #009900;color: #439AD0;">&#93;</span><span style="color: #009900;color: #439AD0;">&#41;</span>.<span style="color: #660066;">addClass</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #3366CC;color: #439AD0;">'imageChange'</span><span style="color: #009900;color: #439AD0;">&#41;</span><span style="color: #339933;color: #439AD0;">;</span>
		$<span style="color: #009900;color: #439AD0;">&#40;</span>content<span style="color: #009900;color: #439AD0;">&#41;</span>.<span style="color: #660066;">fadeOut</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #CC0000;color: #439AD0;">1000</span><span style="color: #009900;color: #439AD0;">&#41;</span>.<span style="color: #660066;">hide</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #009900;color: #439AD0;">&#41;</span><span style="color: #339933;color: #439AD0;">;</span>
		$<span style="color: #009900;color: #439AD0;">&#40;</span>content<span style="color: #009900;color: #439AD0;">&#91;</span>i<span style="color: #009900;color: #439AD0;">&#93;</span><span style="color: #009900;color: #439AD0;">&#41;</span>.<span style="color: #660066;">fadeIn</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #009900;color: #439AD0;">&#41;</span><span style="color: #339933;color: #439AD0;">;</span>	
		<span style="color: #000066; font-weight: bold;color: #439AD0;">if</span> <span style="color: #009900;color: #439AD0;">&#40;</span>i<span style="color: #339933;color: #439AD0;">&lt;</span><span style="color: #CC0000;color: #439AD0;">7</span><span style="color: #009900;color: #439AD0;">&#41;</span> <span style="color: #009900;color: #439AD0;">&#123;</span>
			i<span style="color: #339933;color: #439AD0;">++;</span>	
		<span style="color: #009900;color: #439AD0;">&#125;</span> <span style="color: #000066; font-weight: bold;color: #439AD0;">else</span> <span style="color: #009900;color: #439AD0;">&#123;</span>
			i <span style="color: #339933;color: #439AD0;">=</span> <span style="color: #CC0000;color: #439AD0;">0</span><span style="color: #339933;color: #439AD0;">;</span>
		<span style="color: #009900;color: #439AD0;">&#125;</span>
	<span style="color: #009900;color: #439AD0;">&#125;</span><span style="color: #339933;color: #439AD0;">;</span>
&nbsp;
	<span style="color: #003366; font-weight: bold;color: #439AD0;">function</span> stopRotation<span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #009900;color: #439AD0;">&#41;</span> <span style="color: #009900;color: #439AD0;">&#123;</span>
		clearInterval<span style="color: #009900;color: #439AD0;">&#40;</span>rotateIcon<span style="color: #009900;color: #439AD0;">&#41;</span><span style="color: #339933;color: #439AD0;">;</span>
	<span style="color: #009900;color: #439AD0;">&#125;</span>
&nbsp;
	nextIcon<span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #009900;color: #439AD0;">&#41;</span><span style="color: #339933;color: #439AD0;">;</span>
	rotation<span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #009900;color: #439AD0;">&#41;</span><span style="color: #339933;color: #439AD0;">;</span>
<span style="color: #009900;color: #439AD0;">&#125;</span><span style="color: #009900;color: #439AD0;">&#41;</span><span style="color: #339933;color: #439AD0;">;</span></pre></div></div>

<p>Well, starting with the first line of the actual script, I&#8217;m declaring a variable for all the divs with the class &#8216;wheelIcon&#8217;. That way I am not typing so much later. Same thing with all the content divs. The next block deals with adding/removing a class, so that the icon changes from gray to blue when clicked. It is doing more than that of course.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;color: #439AD0; font-weight: bold;">$<span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #3366CC;color: #439AD0;">'#wheel'</span><span style="color: #009900;color: #439AD0;">&#41;</span>.<span style="color: #660066;">delegate</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #3366CC;color: #439AD0;">'div'</span><span style="color: #339933;color: #439AD0;">,</span> <span style="color: #3366CC;color: #439AD0;">'click'</span><span style="color: #339933;color: #439AD0;">,</span> <span style="color: #003366; font-weight: bold;color: #439AD0;">function</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #009900;color: #439AD0;">&#41;</span><span style="color: #009900;color: #439AD0;">&#123;</span>
		stopRotation<span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #009900;color: #439AD0;">&#41;</span><span style="color: #339933;color: #439AD0;">;</span>
		<span style="color: #006600; font-style: italic;color: #439AD0;">//change the background-position on x-axis so that they become blue icons</span>
		wheels.<span style="color: #660066;">removeClass</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #3366CC;color: #439AD0;">'imageChange'</span><span style="color: #009900;color: #439AD0;">&#41;</span><span style="color: #339933;color: #439AD0;">;</span>
		$<span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #000066; font-weight: bold;color: #439AD0;">this</span><span style="color: #009900;color: #439AD0;">&#41;</span>.<span style="color: #660066;">addClass</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #3366CC;color: #439AD0;">'imageChange'</span><span style="color: #009900;color: #439AD0;">&#41;</span><span style="color: #339933;color: #439AD0;">;</span>
&nbsp;
&nbsp;
		<span style="color: #006600; font-style: italic;color: #439AD0;">//Show or hide the content divs based on which icon is clicked</span>
			$<span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #3366CC;color: #439AD0;">'.wheelContent'</span><span style="color: #009900;color: #439AD0;">&#41;</span>.<span style="color: #660066;">fadeOut</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #009900;color: #439AD0;">&#41;</span>.<span style="color: #660066;">delay</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #CC0000;color: #439AD0;">500</span><span style="color: #009900;color: #439AD0;">&#41;</span><span style="color: #339933;color: #439AD0;">;</span>
			$<span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #3366CC;color: #439AD0;">'.wheelContent'</span><span style="color: #009900;color: #439AD0;">&#41;</span>.<span style="color: #660066;">eq</span><span style="color: #009900;color: #439AD0;">&#40;</span>$<span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #000066; font-weight: bold;color: #439AD0;">this</span><span style="color: #009900;color: #439AD0;">&#41;</span>.<span style="color: #660066;">index</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #009900;color: #439AD0;">&#41;</span><span style="color: #009900;color: #439AD0;">&#41;</span>.<span style="color: #660066;">fadeIn</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #009900;color: #439AD0;">&#41;</span><span style="color: #339933;color: #439AD0;">;</span>	
	<span style="color: #009900;color: #439AD0;">&#125;</span><span style="color: #009900;color: #439AD0;">&#41;</span><span style="color: #339933;color: #439AD0;">;</span></pre></div></div>

<p>I&#8217;m using delegate() so that there isn&#8217;t a ton of event handler&#8217;s flying around. It places the handler on the div with the id of &#8216;wheel&#8217;, and if any of the divs within it are clicked, it runs the function. One handler rather than eight. The next line is calling the function &#8216;stopRotation&#8217; which clears the interval, but I&#8217;ll get to that.</p>
<p>So an icon is clicked, stops the rotation, and we get to the next couple of lines. It removes the class &#8216;imageChange&#8217; from ALL of the icon divs, and adds it back on to the one that was clicked. The last piece in this section does kind of the same thing, but with the content divs. It fades out ALL the content divs, and fades in the one whose index value is equal to the index value of the icon that was clicked. Now on to the fun!</p>
<h3>The home stretch &#8211; setInterval</h3>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;color: #439AD0; font-weight: bold;"><span style="color: #003366; font-weight: bold;color: #439AD0;">function</span> rotation<span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #009900;color: #439AD0;">&#41;</span> <span style="color: #009900;color: #439AD0;">&#123;</span>
		rotateIcon <span style="color: #339933;color: #439AD0;">=</span> setInterval<span style="color: #009900;color: #439AD0;">&#40;</span>nextIcon<span style="color: #339933;color: #439AD0;">,</span> <span style="color: #CC0000;color: #439AD0;">4000</span><span style="color: #009900;color: #439AD0;">&#41;</span><span style="color: #339933;color: #439AD0;">;</span>
	<span style="color: #009900;color: #439AD0;">&#125;</span>
&nbsp;
	i <span style="color: #339933;color: #439AD0;">=</span> <span style="color: #CC0000;color: #439AD0;">0</span><span style="color: #339933;color: #439AD0;">;</span>
&nbsp;
	<span style="color: #003366; font-weight: bold;color: #439AD0;">function</span> nextIcon<span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #009900;color: #439AD0;">&#41;</span> <span style="color: #009900;color: #439AD0;">&#123;</span>
		wheels.<span style="color: #660066;">removeClass</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #3366CC;color: #439AD0;">'imageChange'</span><span style="color: #009900;color: #439AD0;">&#41;</span><span style="color: #339933;color: #439AD0;">;</span>
		$<span style="color: #009900;color: #439AD0;">&#40;</span>wheels<span style="color: #009900;color: #439AD0;">&#91;</span>i<span style="color: #009900;color: #439AD0;">&#93;</span><span style="color: #009900;color: #439AD0;">&#41;</span>.<span style="color: #660066;">addClass</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #3366CC;color: #439AD0;">'imageChange'</span><span style="color: #009900;color: #439AD0;">&#41;</span><span style="color: #339933;color: #439AD0;">;</span>
		$<span style="color: #009900;color: #439AD0;">&#40;</span>content<span style="color: #009900;color: #439AD0;">&#41;</span>.<span style="color: #660066;">fadeOut</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #CC0000;color: #439AD0;">1000</span><span style="color: #009900;color: #439AD0;">&#41;</span>.<span style="color: #660066;">hide</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #009900;color: #439AD0;">&#41;</span><span style="color: #339933;color: #439AD0;">;</span>
		$<span style="color: #009900;color: #439AD0;">&#40;</span>content<span style="color: #009900;color: #439AD0;">&#91;</span>i<span style="color: #009900;color: #439AD0;">&#93;</span><span style="color: #009900;color: #439AD0;">&#41;</span>.<span style="color: #660066;">fadeIn</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #009900;color: #439AD0;">&#41;</span><span style="color: #339933;color: #439AD0;">;</span>	
		<span style="color: #000066; font-weight: bold;color: #439AD0;">if</span> <span style="color: #009900;color: #439AD0;">&#40;</span>i<span style="color: #339933;color: #439AD0;">&lt;</span><span style="color: #CC0000;color: #439AD0;">7</span><span style="color: #009900;color: #439AD0;">&#41;</span> <span style="color: #009900;color: #439AD0;">&#123;</span>
			i<span style="color: #339933;color: #439AD0;">++;</span>	
		<span style="color: #009900;color: #439AD0;">&#125;</span> <span style="color: #000066; font-weight: bold;color: #439AD0;">else</span> <span style="color: #009900;color: #439AD0;">&#123;</span>
			i <span style="color: #339933;color: #439AD0;">=</span> <span style="color: #CC0000;color: #439AD0;">0</span><span style="color: #339933;color: #439AD0;">;</span>
		<span style="color: #009900;color: #439AD0;">&#125;</span>
	<span style="color: #009900;color: #439AD0;">&#125;</span><span style="color: #339933;color: #439AD0;">;</span>
&nbsp;
	<span style="color: #003366; font-weight: bold;color: #439AD0;">function</span> stopRotation<span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #009900;color: #439AD0;">&#41;</span> <span style="color: #009900;color: #439AD0;">&#123;</span>
		clearInterval<span style="color: #009900;color: #439AD0;">&#40;</span>rotateIcon<span style="color: #009900;color: #439AD0;">&#41;</span><span style="color: #339933;color: #439AD0;">;</span>
	<span style="color: #009900;color: #439AD0;">&#125;</span>
&nbsp;
	nextIcon<span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #009900;color: #439AD0;">&#41;</span><span style="color: #339933;color: #439AD0;">;</span>
	rotation<span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #009900;color: #439AD0;">&#41;</span><span style="color: #339933;color: #439AD0;">;</span></pre></div></div>

<p>I created three functions here. One to start the timed rotation, one to do what it should during the interval, and one to stop the rotation. The first starts it, and it is pretty simple. I gave it a name of &#8216;rotation&#8217;, and set a variable to setInterval with the parameters of another function, and a time period of 4 seconds. I set a variable of &#8216;i&#8217; to &#8217;0&#8242;, which I will use in the function I am passing into the setInterval.</p>
<p>The function &#8216;nextIcon&#8217; does a lot of what the click event does. I remove the class &#8216;imageChange&#8217; from every icon, the add it to the icon with an index value of &#8216;i&#8217;, which is zero the first time around. That means the first icon is blue right off the bat. I then fade out all the content divs, and fade in the one that has an index also equal to &#8216;i&#8217;, which at the start is again, zero.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;color: #439AD0; font-weight: bold;"><span style="color: #000066; font-weight: bold;color: #439AD0;">if</span> <span style="color: #009900;color: #439AD0;">&#40;</span>i<span style="color: #339933;color: #439AD0;">&lt;</span><span style="color: #CC0000;color: #439AD0;">7</span><span style="color: #009900;color: #439AD0;">&#41;</span> <span style="color: #009900;color: #439AD0;">&#123;</span>
i<span style="color: #339933;color: #439AD0;">++;</span>	
<span style="color: #009900;color: #439AD0;">&#125;</span> <span style="color: #000066; font-weight: bold;color: #439AD0;">else</span> <span style="color: #009900;color: #439AD0;">&#123;</span>
i <span style="color: #339933;color: #439AD0;">=</span> <span style="color: #CC0000;color: #439AD0;">0</span><span style="color: #339933;color: #439AD0;">;</span>
<span style="color: #009900;color: #439AD0;">&#125;</span></pre></div></div>

<p>The above says if i is less than zero, add 1 to it, otherwise set &#8216;i&#8217; back to zero. That keeps the rotation going after it gets finished. Just to note, I have eight content divs, but we are going by index value, which starts at 0, rather than 1.</p>
<p>The last section is the function that stops the rotation. All it does is clear the interval that is set in the rotation function.</p>
<p>Finally, I call the &#8216;nextIcon&#8217; function to get it going, and then the &#8216;rotation&#8217; function to set the interval.</p>
<h3>Final thoughts on setInterval</h3>
<p>I had always wanted to know how to do what I did with this little project, and it was cool to learn how to do it. I was surprised at how uncomplicated it actually is. The only hard part was doing a bit of &#8216;googling&#8217; to figure some things out. Hopefully this little tutorial saves you some time and taught you something.</p>
<p><strong>If you have used setInterval before, show us what you did!</strong></p>
<div class="gator">
<a  href="http://secure.hostgator.com/~affiliat/cgi-bin/affiliates/clickthru.cgi?id=jcDesigns-" rel="nofollow"><img src="http://tracking.hostgator.com/img/Shared/468x60.gif" border=0></a></p>
<p>Coupon Code: webmachine</p>
</div>
 <img src="http://jc-designs.net/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=888" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://jc-designs.net/blog/2011/04/tutorial-on-using-setinterval-to-make-a-jquery-rotator/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>jQuery Portfolio Content Gallery</title>
		<link>http://jc-designs.net/blog/2011/04/jquery-portfolio-content-gallery/</link>
		<comments>http://jc-designs.net/blog/2011/04/jquery-portfolio-content-gallery/#comments</comments>
		<pubDate>Fri, 01 Apr 2011 22:08:21 +0000</pubDate>
		<dc:creator>jcDesigns</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://jc-designs.net/blog/?p=852</guid>
		<description><![CDATA[Been very busy First, apologies to my subscribers for not writing a lot recently, but I have been working some overtime, and redesigning my website&#8217;s interior pages. But I was working on my portfolio page and thought I would share what I have done. All in all, it is not overly complicated, but I like [...]]]></description>
			<content:encoded><![CDATA[<h3>Been very busy</h3>
<p><img src="http://jc-designs.net/newimages/blogImages/portScreen.jpg" alt="Portfolio image" class="right"/>First, apologies to my subscribers for not writing a lot recently, but I have been working some overtime, and redesigning my website&#8217;s interior pages. But I was working on my portfolio page and thought I would share what I have done. All in all, it is not overly complicated, but I like that it is clean and simple. You&#8217;ll also get to see the beginnings of my redesign of my interior pages (just keep in mind that it is not finished yet). Take a look at my new portfolio page so far:</p>
<p><a class="viewDemo" href="http://jc-designs.net/portfolio" target="_blank">View Demo</a><br />
<span id="more-852"></span></p>
<h3>The nuts and bolts</h3>
<p>I wanted my portfolio page to be simple, and I think I achieved that. Content for the first port image is already loaded, and when you click on an image, the arrow slides and the content switches to match the image. Here is the HTML I used:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;color: #439AD0; font-weight: bold;">&lt;div id=&quot;portContainer&quot;&gt;
     &lt;div id=&quot;portArrow&quot;&gt;&lt;/div&gt;
     &lt;ul&gt;
          &lt;li id=&quot;portOne&quot; class=&quot;slide&quot;&gt;&lt;a href=&quot;#&quot;&gt;&lt;/a&gt;&lt;/li&gt;
          &lt;li id=&quot;portTwo&quot; class=&quot;slide&quot;&gt;&lt;a href=&quot;#&quot;&gt;&lt;/a&gt;&lt;/li&gt;
          &lt;li id=&quot;portThree&quot; class=&quot;slide&quot;&gt;&lt;a href=&quot;#&quot;&gt;&lt;/a&gt;&lt;/li&gt;
          &lt;li id=&quot;portFour&quot; class=&quot;slide&quot;&gt;&lt;a href=&quot;#&quot;&gt;&lt;/a&gt;&lt;/li&gt;
          &lt;li id=&quot;portFive&quot; class=&quot;slide&quot;&gt;&lt;a href=&quot;#&quot;&gt;&lt;/a&gt;&lt;/li&gt;
     &lt;/ul&gt;
&lt;/div&gt;
&lt;div id=&quot;portContentContainer&quot;&gt;
     &lt;div id=&quot;portOneContent&quot; class=&quot;portContent&quot;&gt;
          Test Content 1
     &lt;/div&gt;
 &lt;div id=&quot;portTwoContent&quot; class=&quot;portContent&quot;&gt;
          Test Content 2
     &lt;/div&gt;
 &lt;div id=&quot;portThreeContent&quot; class=&quot;portContent&quot;&gt;
          Test Content 3
     &lt;/div&gt;
 &lt;div id=&quot;portFourContent&quot; class=&quot;portContent&quot;&gt;
          Test Content 4
     &lt;/div&gt;
 &lt;div id=&quot;portFiveContent&quot; class=&quot;portContent&quot;&gt;
          Test Content 5
     &lt;/div&gt;
&lt;/div&gt;</pre></div></div>

<p>The CSS doesn&#8217;t really matter for this, other than the margin for the arrow is set to 0, because that is what I change using a jQuery animation. Let&#8217;s take a look at that, and then I&#8217;ll explain what I did to achieve it.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;color: #439AD0; font-weight: bold;"><span style="color: #003366; font-weight: bold;color: #439AD0;">var</span> slides <span style="color: #339933;color: #439AD0;">=</span> $<span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #3366CC;color: #439AD0;">'.slide'</span><span style="color: #009900;color: #439AD0;">&#41;</span><span style="color: #339933;color: #439AD0;">;</span>
<span style="color: #003366; font-weight: bold;color: #439AD0;">var</span> contentWidth <span style="color: #339933;color: #439AD0;">=</span> $<span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #3366CC;color: #439AD0;">'.slide'</span><span style="color: #009900;color: #439AD0;">&#41;</span>.<span style="color: #660066;">width</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #009900;color: #439AD0;">&#41;</span><span style="color: #339933;color: #439AD0;">;</span>
<span style="color: #003366; font-weight: bold;color: #439AD0;">var</span> currentPosition <span style="color: #339933;color: #439AD0;">=</span> <span style="color: #CC0000;color: #439AD0;">0</span><span style="color: #339933;color: #439AD0;">;</span>
&nbsp;
slides.<span style="color: #660066;">click</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #003366; font-weight: bold;color: #439AD0;">function</span> <span style="color: #009900;color: #439AD0;">&#40;</span>e<span style="color: #009900;color: #439AD0;">&#41;</span> <span style="color: #009900;color: #439AD0;">&#123;</span>
	currentPosition <span style="color: #339933;color: #439AD0;">=</span> $<span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #000066; font-weight: bold;color: #439AD0;">this</span><span style="color: #009900;color: #439AD0;">&#41;</span>.<span style="color: #660066;">index</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #009900;color: #439AD0;">&#41;</span><span style="color: #339933;color: #439AD0;">;</span>
&nbsp;
	<span style="color: #006600; font-style: italic;color: #439AD0;">//Move the arrow thing move to the right, the 42 is the margin between the slide divs</span>
	$<span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #3366CC;color: #439AD0;">'#portArrow'</span><span style="color: #009900;color: #439AD0;">&#41;</span>.<span style="color: #660066;">animate</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #009900;color: #439AD0;">&#123;</span>
		<span style="color: #3366CC;color: #439AD0;">'marginLeft'</span> <span style="color: #339933;color: #439AD0;">:</span>  <span style="color: #009900;color: #439AD0;">&#40;</span>contentWidth <span style="color: #339933;color: #439AD0;">+</span> <span style="color: #CC0000;color: #439AD0;">42</span> <span style="color: #009900;color: #439AD0;">&#41;</span> <span style="color: #339933;color: #439AD0;">*</span> <span style="color: #009900;color: #439AD0;">&#40;</span>currentPosition<span style="color: #009900;color: #439AD0;">&#41;</span>
		<span style="color: #009900;color: #439AD0;">&#125;</span><span style="color: #339933;color: #439AD0;">,</span> <span style="color: #CC0000;color: #439AD0;">200</span><span style="color: #009900;color: #439AD0;">&#41;</span><span style="color: #339933;color: #439AD0;">;</span>
&nbsp;
	<span style="color: #006600; font-style: italic;color: #439AD0;">//Show or hide the 4 items below based on which slide is clicked</span>
	$<span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #3366CC;color: #439AD0;">'.portContent'</span><span style="color: #009900;color: #439AD0;">&#41;</span>.<span style="color: #660066;">fadeOut</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #009900;color: #439AD0;">&#41;</span>.<span style="color: #660066;">delay</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #CC0000;color: #439AD0;">500</span><span style="color: #009900;color: #439AD0;">&#41;</span><span style="color: #339933;color: #439AD0;">;</span>
	$<span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #3366CC;color: #439AD0;">'.portContent'</span><span style="color: #009900;color: #439AD0;">&#41;</span>.<span style="color: #660066;">eq</span><span style="color: #009900;color: #439AD0;">&#40;</span>$<span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #000066; font-weight: bold;color: #439AD0;">this</span><span style="color: #009900;color: #439AD0;">&#41;</span>.<span style="color: #660066;">index</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #009900;color: #439AD0;">&#41;</span><span style="color: #009900;color: #439AD0;">&#41;</span>.<span style="color: #660066;">fadeIn</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #009900;color: #439AD0;">&#41;</span><span style="color: #339933;color: #439AD0;">;</span>	
<span style="color: #009900;color: #439AD0;">&#125;</span><span style="color: #009900;color: #439AD0;">&#41;</span><span style="color: #339933;color: #439AD0;">;</span></pre></div></div>

<h3>What is jQuery doing there?</h3>
<p>See? Very few lines of jQuery were needed to get this to work. The first line is just a variable to reference all the list-items with the class &#8220;slide&#8221;. Which technically you could ditch, because I only call it once. I left it in there because at the time, I didn&#8217;t really know what I was going to be doing. The second line is another variable used for the width of each individual
<li>. The final variable is to track the position of of the arrow, which is set to &#8217;0&#8242;.</p>
<p>Then we come to the click event attached to the li&#8217;s. The currentPosition variable&#8217;s value changes to be the index number of whatever
<li> is clicked. If you click on the second image it equals 1, if you click on the third image, it equals 2, and so on and so forth. Once an li is clicked, the animation kicks in.</p>
<p>The arrow (which is a div with an id of &#8216;portArrow&#8217;) is moved (left or right) a total of the li&#8217;s width, plus 42, which is the margin between each
<li>, and then multiplied by the current position. That number becomes the arrow&#8217;s left margin. If you click on the first image, you get (168 + 42) * 0, which is 0, so the arrow&#8217;s left margin is set to 0, and the arrow moves to the left. Unless of course the arrow was already on the first image.</p>
<p>The last part deals with the content underneath. This line just fades out whatever content is showing, and gives a delay of 1/2 a second, before going to the next part:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;color: #439AD0; font-weight: bold;">$<span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #3366CC;color: #439AD0;">'.portContent'</span><span style="color: #009900;color: #439AD0;">&#41;</span>.<span style="color: #660066;">fadeOut</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #009900;color: #439AD0;">&#41;</span>.<span style="color: #660066;">delay</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #CC0000;color: #439AD0;">500</span><span style="color: #009900;color: #439AD0;">&#41;</span><span style="color: #339933;color: #439AD0;">;</span></pre></div></div>

<p>The last line:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;color: #439AD0; font-weight: bold;">$<span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #3366CC;color: #439AD0;">'.portContent'</span><span style="color: #009900;color: #439AD0;">&#41;</span>.<span style="color: #660066;">eq</span><span style="color: #009900;color: #439AD0;">&#40;</span>$<span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #000066; font-weight: bold;color: #439AD0;">this</span><span style="color: #009900;color: #439AD0;">&#41;</span>.<span style="color: #660066;">index</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #009900;color: #439AD0;">&#41;</span><span style="color: #009900;color: #439AD0;">&#41;</span>.<span style="color: #660066;">fadeIn</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #009900;color: #439AD0;">&#41;</span><span style="color: #339933;color: #439AD0;">;</span></pre></div></div>

<p>This says, out of the div&#8217;s with a class of &#8216;portContent&#8217;, fade in the one that&#8217;s index matches the index of the
<li> that was clicked. Got it? Good.</p>
<h3>Extra credit question</h3>
<p>Now for a question for any experienced jQuery users. You will see that the little cog next to my logo is rotating. All that is, is an image sprite with 3 images, being shifted over. Unfortunately, I had to use a plugin for that. The plugin (<a href="http://www.spritely.net/">Spritely</a>) is cool, but I wanted to avoid it if possible, and do it myself. I came close by chaining multiple animations with very fast speeds, but I didn&#8217;t want it to go as fast as it was. I then tried chaining three .css() methods with delays in between inside a loop, but that didn&#8217;t work. Kind of looked like this (off the top of my head&#8230;not exact):</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;color: #439AD0; font-weight: bold;"><span style="color: #000066; font-weight: bold;color: #439AD0;">for</span> <span style="color: #009900;color: #439AD0;">&#40;</span>i<span style="color: #339933;color: #439AD0;">=</span><span style="color: #CC0000;color: #439AD0;">0</span><span style="color: #339933;color: #439AD0;">;</span>i<span style="color: #339933;color: #439AD0;">&lt;</span><span style="color: #CC0000;color: #439AD0;">50000</span><span style="color: #339933;color: #439AD0;">;</span>i<span style="color: #339933;color: #439AD0;">++</span><span style="color: #009900;color: #439AD0;">&#41;</span> <span style="color: #009900;color: #439AD0;">&#123;</span>
$<span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #3366CC;color: #439AD0;">'#intCog'</span><span style="color: #009900;color: #439AD0;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #3366CC;color: #439AD0;">'backgroundPosition'</span><span style="color: #339933;color: #439AD0;">,</span> <span style="color: #3366CC;color: #439AD0;">'-60px 0'</span><span style="color: #009900;color: #439AD0;">&#41;</span>.<span style="color: #660066;">delay</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #CC0000;color: #439AD0;">100</span><span style="color: #009900;color: #439AD0;">&#41;</span>
     .<span style="color: #660066;">css</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #3366CC;color: #439AD0;">'backgroundPosition'</span><span style="color: #339933;color: #439AD0;">,</span> <span style="color: #3366CC;color: #439AD0;">'-120px 0'</span><span style="color: #009900;color: #439AD0;">&#41;</span>.<span style="color: #660066;">delay</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #CC0000;color: #439AD0;">100</span><span style="color: #009900;color: #439AD0;">&#41;</span>
     .<span style="color: #660066;">css</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #3366CC;color: #439AD0;">'backgroundPosition'</span><span style="color: #339933;color: #439AD0;">,</span> <span style="color: #3366CC;color: #439AD0;">'0 0'</span><span style="color: #009900;color: #439AD0;">&#41;</span>.<span style="color: #660066;">delay</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #CC0000;color: #439AD0;">100</span><span style="color: #009900;color: #439AD0;">&#41;</span>
&nbsp;
<span style="color: #009900;color: #439AD0;">&#125;</span><span style="color: #339933;color: #439AD0;">;</span></pre></div></div>

<p>Obviously, this didn&#8217;t work, and I knew why right after I wrote it. It&#8217;s going to set to 0 0, but my thought was that it would step through it rather than slide through it like an animation would.</p>
<p><strong>The question:</strong> How do you change a value, like above, without the sliding like the animation has? I needed it to change to the value, not slide to the new position. I could have made 3 copies and faded them in and out, but that seemed ridiculous. All I can think of is maybe 3 chained animations and some hide/show methods like:</p>
<p>.hide().animation(background position change).show().hide().animation(background position change).show().hide() and so forth&#8230;really fast.</p>
<p>Help me out!</p>
<div class="gator">
<a  href="http://secure.hostgator.com/~affiliat/cgi-bin/affiliates/clickthru.cgi?id=jcDesigns-" rel="nofollow"><img src="http://tracking.hostgator.com/img/Shared/468x60.gif" border=0></a></p>
<p>Coupon Code: webmachine</p>
</div>
 <img src="http://jc-designs.net/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=852" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://jc-designs.net/blog/2011/04/jquery-portfolio-content-gallery/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>A Simple jQuery Fly-Out Menu</title>
		<link>http://jc-designs.net/blog/2011/01/a-simple-jquery-fly-out-menu/</link>
		<comments>http://jc-designs.net/blog/2011/01/a-simple-jquery-fly-out-menu/#comments</comments>
		<pubDate>Tue, 04 Jan 2011 23:25:25 +0000</pubDate>
		<dc:creator>jcDesigns</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://jc-designs.net/blog/?p=703</guid>
		<description><![CDATA[I haven&#8217;t made a post about jQuery in a while Which is what made me decide to write my first post of 2011 on it. First, thank you to the people who commented here on The Web Machine in 2010. Also thanks to the over 730 RSS subscribers I have and the 25 or so [...]]]></description>
			<content:encoded><![CDATA[<h3>I haven&#8217;t made a post about jQuery in a while</h3>
<p>Which is what made me decide to write my first post of 2011 on it. First, thank you to the people who commented here on The Web Machine in 2010. Also thanks to the over 730 RSS subscribers I have and the 25 or so followers on Twitter. This blog has been up for about a year now, and I look forward to this one. I hate all of you comment spammers though! So huge thanks to Akismet.</p>
<p>Anyway&#8230;a while ago I had thought about creating WordPress themes and try my hand at selling them, but it soon became apparent that the market was saturated. I don&#8217;t feel like wasting my time right now on putting effort into that. On one of those themes though, while I am not happy with the look, I created a fly-out menu using jQuery that I really liked. I thought I would share that with you since it takes less than 8 lines of code. So take a look at the demo, and then we&#8217;ll jump right in.</p>
<p><strong>UPDATE 5/17/11: Removed the position:relative from the li style. It now gets the position:relative in the hover function in jQuery by adding/removing a class &#8216;addPosition&#8217;. This fixes the submenu appearing underneath the main menu in IE7/8. This was only noticable if you started changing the position of the submenu to be overlapping the main menu. My code here assumes you don&#8217;t do that, but with the fix it works great in IE7/8.</strong></p>
<p><strong>NOTE: In IE6, only the first level of the fly-out works. The second is cut off, but since most of us our on our way to not supporting it, I didn&#8217;t care. If you have the simple solution to fix that, let me know.</strong></p>
<p>Original:<br />
<a href="http://jc-designs.net/demo/flyout.html" target="_blank" class="viewDemo">View Demo</a></p>
<p>More stripped down version (asked for in comments and the CSS now shown in sample code below):<br />
<a href="http://jc-designs.net/demo/flyout2.html" target="_blank" class="viewDemo">View Demo</a></p>
<p><span id="more-703"></span><br />
Now that you have seen what it is supposed to do, let&#8217;s jump in. The HTML first:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;color: #439AD0; font-weight: bold;">  &lt;div id=&quot;nav&quot;&gt;
    &lt;ul id=&quot;navList&quot;&gt;
      &lt;li&gt;&lt;a href=&quot;#&quot;&gt;Home&lt;/a&gt;
        &lt;!-- This is the sub nav --&gt;
        &lt;ul class=&quot;listTab&quot;&gt;
          &lt;li&gt;&lt;a href=&quot;#&quot;&gt;About This Template Here&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;#&quot;&gt;Flash&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;#&quot;&gt;jQuery&lt;/a&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#&quot;&gt;Blog&lt;/a&gt;
        &lt;!-- This is the sub nav --&gt;
        &lt;ul class=&quot;listTab&quot;&gt;
          &lt;li&gt;&lt;a href=&quot;#&quot;&gt;About This Template Here&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;#&quot;&gt;Flash&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;#&quot;&gt;jQuery&lt;/a&gt;
            &lt;ul class=&quot;listTab&quot;&gt;
              &lt;li&gt;&lt;a href=&quot;#&quot;&gt;About This Template Here&lt;/a&gt;&lt;/li&gt;
              &lt;li&gt;&lt;a href=&quot;#&quot;&gt;Flash&lt;/a&gt;&lt;/li&gt;
              &lt;li&gt;&lt;a href=&quot;#&quot;&gt;jQuery&lt;/a&gt;&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#&quot;&gt;About&lt;/a&gt;
        &lt;!-- This is the sub nav --&gt;
        &lt;ul class=&quot;listTab&quot;&gt;
          &lt;li&gt;&lt;a href=&quot;#&quot;&gt;About This Template Here&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;#&quot;&gt;Flash&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;#&quot;&gt;jQuery&lt;/a&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#&quot;&gt;Porfolio&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#&quot;&gt;Contact&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/div&gt;</pre></div></div>

<p>Fairly easy stuff there. It is a simple list with a byline under each item, and the first few list items have the fly out. Here is the CSS involved:</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;color: #439AD0; font-weight: bold;">ul <span style="color: #00AA00;color: #439AD0;">&#123;</span>
	<span style="color: #000000; font-weight: bold;color: #439AD0;">margin</span><span style="color: #00AA00;color: #439AD0;">:</span> <span style="color: #cc66cc;color: #439AD0;">0</span><span style="color: #00AA00;color: #439AD0;">;</span>
	<span style="color: #000000; font-weight: bold;color: #439AD0;">padding</span><span style="color: #00AA00;color: #439AD0;">:</span> <span style="color: #cc66cc;color: #439AD0;">0</span><span style="color: #00AA00;color: #439AD0;">;</span>
<span style="color: #00AA00;color: #439AD0;">&#125;</span>
<span style="color: #cc00cc;">#nav</span> <span style="color: #00AA00;color: #439AD0;">&#123;</span>
	<span style="color: #000000; font-weight: bold;color: #439AD0;">width</span><span style="color: #00AA00;color: #439AD0;">:</span> <span style="color: #933;">330px</span><span style="color: #00AA00;color: #439AD0;">;</span>
	<span style="color: #000000; font-weight: bold;color: #439AD0;">float</span><span style="color: #00AA00;color: #439AD0;">:</span> <span style="color: #000000; font-weight: bold;color: #439AD0;">left</span><span style="color: #00AA00;color: #439AD0;">;</span>
	<span style="color: #000000; font-weight: bold;color: #439AD0;">margin</span><span style="color: #00AA00;color: #439AD0;">:</span> <span style="color: #933;">50px</span> <span style="color: #cc66cc;color: #439AD0;">0</span> <span style="color: #cc66cc;color: #439AD0;">0</span><span style="color: #00AA00;color: #439AD0;">;</span>
<span style="color: #00AA00;color: #439AD0;">&#125;</span>
<span style="color: #cc00cc;">#navList</span> li <span style="color: #00AA00;color: #439AD0;">&#123;</span>
	<span style="color: #000000; font-weight: bold;color: #439AD0;">list-style</span><span style="color: #00AA00;color: #439AD0;">:</span> <span style="color: #993333;color: #439AD0;">none</span><span style="color: #00AA00;color: #439AD0;">;</span>
	<span style="color: #000000; font-weight: bold;color: #439AD0;">margin</span><span style="color: #00AA00;color: #439AD0;">:</span> <span style="color: #cc66cc;color: #439AD0;">0</span> <span style="color: #cc66cc;color: #439AD0;">0</span> <span style="color: #933;">10px</span><span style="color: #00AA00;color: #439AD0;">;</span>
	<span style="color: #000000; font-weight: bold;color: #439AD0;">float</span><span style="color: #00AA00;color: #439AD0;">:</span> <span style="color: #000000; font-weight: bold;color: #439AD0;">left</span><span style="color: #00AA00;color: #439AD0;">;</span>
<span style="color: #00AA00;color: #439AD0;">&#125;</span>
&nbsp;
<span style="color: #6666ff;color: #439AD0;">.addPosition</span> <span style="color: #00AA00;color: #439AD0;">&#123;</span>
<span style="color: #000000; font-weight: bold;color: #439AD0;">position</span><span style="color: #00AA00;color: #439AD0;">:</span><span style="color: #993333;color: #439AD0;">relative</span><span style="color: #00AA00;color: #439AD0;">;</span>
<span style="color: #00AA00;color: #439AD0;">&#125;</span>
&nbsp;
<span style="color: #cc00cc;">#navList</span> a <span style="color: #00AA00;color: #439AD0;">&#123;</span>
	<span style="color: #000000; font-weight: bold;color: #439AD0;">text-decoration</span><span style="color: #00AA00;color: #439AD0;">:</span> <span style="color: #993333;color: #439AD0;">none</span><span style="color: #00AA00;color: #439AD0;">;</span>
	<span style="color: #000000; font-weight: bold;color: #439AD0;">color</span><span style="color: #00AA00;color: #439AD0;">:</span> <span style="color: #cc00cc;">#ffffff</span><span style="color: #00AA00;color: #439AD0;">;</span>
	<span style="color: #000000; font-weight: bold;color: #439AD0;">background-color</span><span style="color: #00AA00;color: #439AD0;">:</span> <span style="color: #cc00cc;">#333</span><span style="color: #00AA00;color: #439AD0;">;</span>
	<span style="color: #000000; font-weight: bold;color: #439AD0;">padding</span><span style="color: #00AA00;color: #439AD0;">:</span> <span style="color: #933;">5px</span><span style="color: #00AA00;color: #439AD0;">;</span>
	<span style="color: #000000; font-weight: bold;color: #439AD0;">display</span><span style="color: #00AA00;color: #439AD0;">:</span> <span style="color: #993333;color: #439AD0;">block</span><span style="color: #00AA00;color: #439AD0;">;</span>
	<span style="color: #000000; font-weight: bold;color: #439AD0;">width</span><span style="color: #00AA00;color: #439AD0;">:</span> <span style="color: #933;">250px</span><span style="color: #00AA00;color: #439AD0;">;</span>
<span style="color: #00AA00;color: #439AD0;">&#125;</span>
<span style="color: #cc00cc;">#navList</span> a<span style="color: #3333ff;">:hover </span><span style="color: #00AA00;color: #439AD0;">&#123;</span>
	<span style="color: #000000; font-weight: bold;color: #439AD0;">background-color</span><span style="color: #00AA00;color: #439AD0;">:</span> <span style="color: #cc00cc;">#06F</span><span style="color: #00AA00;color: #439AD0;">;</span>
<span style="color: #00AA00;color: #439AD0;">&#125;</span>
<span style="color: #cc00cc;">#navList</span> ul<span style="color: #00AA00;color: #439AD0;">,</span> <span style="color: #cc00cc;">#navList</span> ul ul <span style="color: #00AA00;color: #439AD0;">&#123;</span>
	<span style="color: #000000; font-weight: bold;color: #439AD0;">display</span><span style="color: #00AA00;color: #439AD0;">:</span> <span style="color: #993333;color: #439AD0;">none</span><span style="color: #00AA00;color: #439AD0;">;</span>
	<span style="color: #000000; font-weight: bold;color: #439AD0;">position</span><span style="color: #00AA00;color: #439AD0;">:</span> <span style="color: #993333;color: #439AD0;">absolute</span><span style="color: #00AA00;color: #439AD0;">;</span>
	<span style="color: #000000; font-weight: bold;color: #439AD0;">top</span><span style="color: #00AA00;color: #439AD0;">:</span> <span style="color: #cc66cc;color: #439AD0;">0</span><span style="color: #00AA00;color: #439AD0;">;</span>
	<span style="color: #000000; font-weight: bold;color: #439AD0;">left</span><span style="color: #00AA00;color: #439AD0;">:</span> <span style="color: #933;">280px</span><span style="color: #00AA00;color: #439AD0;">;</span>
	<span style="color: #000000; font-weight: bold;color: #439AD0;">background-color</span><span style="color: #00AA00;color: #439AD0;">:</span> <span style="color: #cc00cc;">#333</span><span style="color: #00AA00;color: #439AD0;">;</span>
<span style="color: #00AA00;color: #439AD0;">&#125;</span>
<span style="color: #6666ff;color: #439AD0;">.listTab</span> <span style="color: #00AA00;color: #439AD0;">&#123;</span>
	<span style="color: #000000; font-weight: bold;color: #439AD0;">z-index</span><span style="color: #00AA00;color: #439AD0;">:</span> <span style="color: #cc66cc;color: #439AD0;">100</span><span style="color: #00AA00;color: #439AD0;">;</span>
<span style="color: #00AA00;color: #439AD0;">&#125;</span>
<span style="color: #cc00cc;">#navList</span> <span style="color: #6666ff;color: #439AD0;">.listTab</span> li <span style="color: #00AA00;color: #439AD0;">&#123;</span>
	<span style="color: #000000; font-weight: bold;color: #439AD0;">margin</span><span style="color: #00AA00;color: #439AD0;">:</span> <span style="color: #cc66cc;color: #439AD0;">0</span><span style="color: #00AA00;color: #439AD0;">;</span>
<span style="color: #00AA00;color: #439AD0;">&#125;</span>
<span style="color: #cc00cc;">#navList</span> <span style="color: #6666ff;color: #439AD0;">.listTab</span> a<span style="color: #00AA00;color: #439AD0;">,</span> <span style="color: #cc00cc;">#navList</span> <span style="color: #6666ff;color: #439AD0;">.listTab</span> a<span style="color: #3333ff;">:hover </span><span style="color: #00AA00;color: #439AD0;">&#123;</span>
	<span style="color: #000000; font-weight: bold;color: #439AD0;">width</span><span style="color: #00AA00;color: #439AD0;">:</span> <span style="color: #933;">250px</span><span style="color: #00AA00;color: #439AD0;">;</span>
<span style="color: #00AA00;color: #439AD0;">&#125;</span>
<span style="color: #cc00cc;">#navList</span> <span style="color: #6666ff;color: #439AD0;">.listTab</span> a <span style="color: #00AA00;color: #439AD0;">&#123;</span>
	<span style="color: #000000; font-weight: bold;color: #439AD0;">padding</span><span style="color: #00AA00;color: #439AD0;">:</span> <span style="color: #933;">5px</span> <span style="color: #933;">5px</span> <span style="color: #933;">5px</span> <span style="color: #933;">10px</span><span style="color: #00AA00;color: #439AD0;">;</span>
<span style="color: #00AA00;color: #439AD0;">&#125;</span>
<span style="color: #cc00cc;">#navList</span> li<span style="color: #3333ff;">:hover </span>ul ul<span style="color: #00AA00;color: #439AD0;">,</span> <span style="color: #cc00cc;">#navList</span> li<span style="color: #3333ff;">:hover </span>ul ul ul<span style="color: #00AA00;color: #439AD0;">,</span> <span style="color: #cc00cc;">#navList</span> li<span style="color: #3333ff;">:hover </span>ul ul ul ul <span style="color: #00AA00;color: #439AD0;">&#123;</span>
	<span style="color: #000000; font-weight: bold;color: #439AD0;">display</span><span style="color: #00AA00;color: #439AD0;">:</span> <span style="color: #993333;color: #439AD0;">none</span><span style="color: #00AA00;color: #439AD0;">;</span>
<span style="color: #00AA00;color: #439AD0;">&#125;</span>
<span style="color: #cc00cc;">#navList</span> li<span style="color: #3333ff;">:hover </span>ul<span style="color: #00AA00;color: #439AD0;">,</span> <span style="color: #cc00cc;">#navList</span> li li<span style="color: #3333ff;">:hover </span>ul<span style="color: #00AA00;color: #439AD0;">,</span> <span style="color: #cc00cc;">#navList</span> li li li<span style="color: #3333ff;">:hover </span>ul<span style="color: #00AA00;color: #439AD0;">,</span> <span style="color: #cc00cc;">#navList</span> li li li li<span style="color: #3333ff;">:hover </span>ul <span style="color: #00AA00;color: #439AD0;">&#123;</span>
	<span style="color: #000000; font-weight: bold;color: #439AD0;">display</span><span style="color: #00AA00;color: #439AD0;">:</span> <span style="color: #993333;color: #439AD0;">block</span><span style="color: #00AA00;color: #439AD0;">;</span>
<span style="color: #00AA00;color: #439AD0;">&#125;</span></pre></div></div>

<p>The really important stuff in the CSS is where position relative is being used (the li&#8217;s), because the fly-out &#8216;ul&#8217; is positioned absolutely to them. Other than that, the display none and block on the &#8216;uls&#8217;. Everything else is just CSS to make the menu look pretty.</p>
<p>Here is the jQuery:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;color: #439AD0; font-weight: bold;">$<span style="color: #009900;color: #439AD0;">&#40;</span>document<span style="color: #009900;color: #439AD0;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #003366; font-weight: bold;color: #439AD0;">function</span><span style="color: #009900;color: #439AD0;">&#40;</span>$<span style="color: #009900;color: #439AD0;">&#41;</span> <span style="color: #009900;color: #439AD0;">&#123;</span>
		<span style="color: #006600; font-style: italic;color: #439AD0;">//Menu animation						</span>
		$<span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #3366CC;color: #439AD0;">'#navList ul'</span><span style="color: #009900;color: #439AD0;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #009900;color: #439AD0;">&#123;</span>display<span style="color: #339933;color: #439AD0;">:</span> <span style="color: #3366CC;color: #439AD0;">&quot;none&quot;</span><span style="color: #009900;color: #439AD0;">&#125;</span><span style="color: #009900;color: #439AD0;">&#41;</span><span style="color: #339933;color: #439AD0;">;</span> <span style="color: #006600; font-style: italic;color: #439AD0;">//Fix Opera</span>
&nbsp;
		$<span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #3366CC;color: #439AD0;">'#navList li'</span><span style="color: #009900;color: #439AD0;">&#41;</span>.<span style="color: #660066;">hover</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #003366; font-weight: bold;color: #439AD0;">function</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #009900;color: #439AD0;">&#41;</span> <span style="color: #009900;color: #439AD0;">&#123;</span>  
                $<span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #000066; font-weight: bold;color: #439AD0;">this</span><span style="color: #009900;color: #439AD0;">&#41;</span>.<span style="color: #660066;">addClass</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #3366CC;color: #439AD0;">'addPosition'</span><span style="color: #009900;color: #439AD0;">&#41;</span><span style="color: #339933;color: #439AD0;">;</span>
		$<span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #000066; font-weight: bold;color: #439AD0;">this</span><span style="color: #009900;color: #439AD0;">&#41;</span>.<span style="color: #660066;">find</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #3366CC;color: #439AD0;">'a'</span><span style="color: #009900;color: #439AD0;">&#41;</span>.<span style="color: #000066;color: #439AD0;">stop</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #009900;color: #439AD0;">&#41;</span>.<span style="color: #660066;">animate</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #009900;color: #439AD0;">&#123;</span><span style="color: #3366CC;color: #439AD0;">'width'</span> <span style="color: #339933;color: #439AD0;">:</span> <span style="color: #3366CC;color: #439AD0;">&quot;280&quot;</span><span style="color: #009900;color: #439AD0;">&#125;</span><span style="color: #009900;color: #439AD0;">&#41;</span><span style="color: #339933;color: #439AD0;">;</span>
   		$<span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #000066; font-weight: bold;color: #439AD0;">this</span><span style="color: #009900;color: #439AD0;">&#41;</span>.<span style="color: #660066;">find</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #3366CC;color: #439AD0;">'ul:first'</span><span style="color: #009900;color: #439AD0;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #009900;color: #439AD0;">&#123;</span>visibility <span style="color: #339933;color: #439AD0;">:</span> <span style="color: #3366CC;color: #439AD0;">&quot;visible&quot;</span><span style="color: #339933;color: #439AD0;">,</span> display <span style="color: #339933;color: #439AD0;">:</span> <span style="color: #3366CC;color: #439AD0;">&quot;none&quot;</span><span style="color: #009900;color: #439AD0;">&#125;</span><span style="color: #009900;color: #439AD0;">&#41;</span>.<span style="color: #660066;">show</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #CC0000;color: #439AD0;">400</span><span style="color: #009900;color: #439AD0;">&#41;</span><span style="color: #339933;color: #439AD0;">;</span>
&nbsp;
  		<span style="color: #009900;color: #439AD0;">&#125;</span><span style="color: #339933;color: #439AD0;">,</span> <span style="color: #003366; font-weight: bold;color: #439AD0;">function</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #009900;color: #439AD0;">&#41;</span> <span style="color: #009900;color: #439AD0;">&#123;</span>
    		$<span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #000066; font-weight: bold;color: #439AD0;">this</span><span style="color: #009900;color: #439AD0;">&#41;</span>.<span style="color: #660066;">find</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #3366CC;color: #439AD0;">'ul:first'</span><span style="color: #009900;color: #439AD0;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #009900;color: #439AD0;">&#123;</span>visibility <span style="color: #339933;color: #439AD0;">:</span> <span style="color: #3366CC;color: #439AD0;">&quot;hidden&quot;</span><span style="color: #009900;color: #439AD0;">&#125;</span><span style="color: #009900;color: #439AD0;">&#41;</span>.<span style="color: #660066;">hide</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #CC0000;color: #439AD0;">400</span><span style="color: #009900;color: #439AD0;">&#41;</span><span style="color: #339933;color: #439AD0;">;</span>
   		$<span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #000066; font-weight: bold;color: #439AD0;">this</span><span style="color: #009900;color: #439AD0;">&#41;</span>.<span style="color: #660066;">find</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #3366CC;color: #439AD0;">'a'</span><span style="color: #009900;color: #439AD0;">&#41;</span>.<span style="color: #000066;color: #439AD0;">stop</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #009900;color: #439AD0;">&#41;</span>.<span style="color: #660066;">animate</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #009900;color: #439AD0;">&#123;</span><span style="color: #3366CC;color: #439AD0;">'width'</span> <span style="color: #339933;color: #439AD0;">:</span> <span style="color: #3366CC;color: #439AD0;">&quot;250&quot;</span><span style="color: #009900;color: #439AD0;">&#125;</span><span style="color: #009900;color: #439AD0;">&#41;</span><span style="color: #339933;color: #439AD0;">;</span>
                $<span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #000066; font-weight: bold;color: #439AD0;">this</span><span style="color: #009900;color: #439AD0;">&#41;</span>.<span style="color: #660066;">removeClass</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #3366CC;color: #439AD0;">'addPosition'</span><span style="color: #009900;color: #439AD0;">&#41;</span><span style="color: #339933;color: #439AD0;">;</span>
			<span style="color: #009900;color: #439AD0;">&#125;</span><span style="color: #009900;color: #439AD0;">&#41;</span><span style="color: #339933;color: #439AD0;">;</span>
		<span style="color: #009900;color: #439AD0;">&#125;</span><span style="color: #009900;color: #439AD0;">&#41;</span><span style="color: #339933;color: #439AD0;">;</span></pre></div></div>

<p>Ok, I will admit that the first line I got from someone else. I have no idea what the hell that fixes, as I am unfamiliar with Opera (along with 3 billion other developers). It seems odd to me because my first CSS puts it at display: none anyways, but I&#8217;ve seen this before so I left it in.</p>
<p>NOTE: Found out Opera doesn&#8217;t hide the menus fast enough, that is why that is there.</p>
<p>The second line is where it all starts. The fly-out is just a hover function in jQuery. Simple yet effective. That is what I live for. I babble&#8230;the li(s) of the main &#8216;ul&#8217; get the hover function. The third line says &#8220;Find the link of the &#8216;li&#8217; you hovered on, stop any animation if there is any, and animate it so that the width grows to 250 pixels.&#8221;</p>
<p>The next line says find the first ul of the rolled over li, make it visible and set the display to none, then show it (which sets the display to block) over 4 miliseconds. I know it seems nuts to have the visibility to visible and yet display it to none, but with out the visible part, the fly-out would only show the first time then never appear again. It will work without the display set to none, but it looks like the show() works better when it is written in. I believe this has to do with show() changing the display, not the visibility.</p>
<p>The off hover section, does the exact opposite. The visibility is set to hidden, and the hide, which takes place again over 4 miliseconds, sets the display back to none. The final line stops any animation on the link, and then shrinks the width back to 250 pixels.</p>
<h3>And there you have it!</h3>
<p>A few lines of jQuery and you have a fly out menu. Most of the CSS is for styling. I have used some CSS3 here that won&#8217;t work in IE obviously, but the actual menu functions except for IE6 (see note above).</p>
<div class="gator">
<a  href="http://secure.hostgator.com/~affiliat/cgi-bin/affiliates/clickthru.cgi?id=jcDesigns-" rel="nofollow"><img src="http://tracking.hostgator.com/img/Shared/468x60.gif" border=0></a></p>
<p>Coupon Code: webmachine</p>
</div>
 <img src="http://jc-designs.net/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=703" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://jc-designs.net/blog/2011/01/a-simple-jquery-fly-out-menu/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Wijmo And Headjs Reviews</title>
		<link>http://jc-designs.net/blog/2010/12/wijmo-and-headjs-reviews/</link>
		<comments>http://jc-designs.net/blog/2010/12/wijmo-and-headjs-reviews/#comments</comments>
		<pubDate>Mon, 13 Dec 2010 21:44:42 +0000</pubDate>
		<dc:creator>jcDesigns</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Product Reviews]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://jc-designs.net/blog/?p=669</guid>
		<description><![CDATA[Undiscovered frontier I love seeing new things being created to make web developers&#8217; lives easier. Some suck, and some rock. Of course I am not the final judge. Usually I find these either from receiving a tweet or a list that shows all the stuff we, in theory, should be aware of. Two that I [...]]]></description>
			<content:encoded><![CDATA[<h3>Undiscovered frontier</h3>
<p>I love seeing new things being created to make web developers&#8217; lives easier. Some suck, and some rock. Of course I am not the final judge. Usually I find these either from receiving a tweet or a list that shows all the stuff we, in theory, should be aware of. Two that I was intrigued by recently are <a href="http://wijmo.com/">Wijmo</a>, a jQuery UI Widgets kit, and <a href="http://headjs.com/">Head JS</a>, which claims that it will be the only script you need in your head tag. Let&#8217;s get started, shall we?</p>
<h3>Apparently Wijmo is from outer space</h3>
<p>Aside from an attempt at humor, Wijmo makes a really bold claim:</p>
<blockquote style="clear: both;"><p>There’s is a new highly volatile element for creating websites and web apps on earth. We call the new element “Wijmo”. Wijmo is a complete kit of over 30 jQuery UI Widgets. It is an extremely dangerous mixture of jQuery, CSS3, SVG, and HTML5 that when combined become an unstoppable force on the web.</p></blockquote>
<p><span id="more-669"></span><br />
<img src="http://www.jc-designs.net/newimages/blogImages/wijmo.jpg" alt="Wijmo - jQuery UI Widgets kit" class="left" />That last line is pretty good, because it grabbed my attention and made me think, &#8220;Ok, I&#8217;m willing to see if you can back that claim up.&#8221; I then started looking at their demo page and I&#8217;ll be damned if some of it wasn&#8217;t cool. I like their calendar and graphs, which would be something I would use. There are a ton of other widget thingies included, too, like a drop-down menu, accordion, form styling, a grid, and some other things that I didn&#8217;t really care about. What impressed me was how many things they were showing you can use.</p>
<p>I then downloaded it, and checked to see the size of the js file because I couldn&#8217;t find that anywhere. Usually things like this like to boast how light/small they are in the weight department. It was fairly easy to guess why they didn&#8217;t&#8230;it weighs in at a huge by large 215k! And that is the minified version! &#8220;Ok, let&#8217;s see what else is going on before you start judging,&#8221; I thought to myself.</p>
<p>I then check the docs page for starting your first Wijmo project, and opened up the sample index page. It doesn&#8217;t say what is specifically required, so I will assume it needs all of these scripts:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;color: #439AD0; font-weight: bold;"><span style="color: #339933;color: #439AD0;">&lt;</span>script type<span style="color: #339933;color: #439AD0;">=</span><span style="color: #3366CC;color: #439AD0;">&quot;text/javascript&quot;</span> src<span style="color: #339933;color: #439AD0;">=</span><span style="color: #3366CC;color: #439AD0;">&quot;../jQuery/jquery-1.4.2.js&quot;</span><span style="color: #339933;color: #439AD0;">&gt;&lt;/</span>script<span style="color: #339933;color: #439AD0;">&gt;</span>
<span style="color: #339933;color: #439AD0;">&lt;</span>script type<span style="color: #339933;color: #439AD0;">=</span><span style="color: #3366CC;color: #439AD0;">&quot;text/javascript&quot;</span> src<span style="color: #339933;color: #439AD0;">=</span><span style="color: #3366CC;color: #439AD0;">&quot;../jQuery/ui/jquery.ui.core.js&quot;</span><span style="color: #339933;color: #439AD0;">&gt;&lt;/</span>script<span style="color: #339933;color: #439AD0;">&gt;</span>
<span style="color: #339933;color: #439AD0;">&lt;</span>script type<span style="color: #339933;color: #439AD0;">=</span><span style="color: #3366CC;color: #439AD0;">&quot;text/javascript&quot;</span> src<span style="color: #339933;color: #439AD0;">=</span><span style="color: #3366CC;color: #439AD0;">&quot;../jQuery/ui/jquery.ui.widget.js&quot;</span><span style="color: #339933;color: #439AD0;">&gt;&lt;/</span>script<span style="color: #339933;color: #439AD0;">&gt;</span>
<span style="color: #339933;color: #439AD0;">&lt;</span>script type<span style="color: #339933;color: #439AD0;">=</span><span style="color: #3366CC;color: #439AD0;">&quot;text/javascript&quot;</span> src<span style="color: #339933;color: #439AD0;">=</span><span style="color: #3366CC;color: #439AD0;">&quot;../jQuery/ui/jquery.ui.position.js&quot;</span><span style="color: #339933;color: #439AD0;">&gt;&lt;/</span>script<span style="color: #339933;color: #439AD0;">&gt;</span>
<span style="color: #339933;color: #439AD0;">&lt;</span>script type<span style="color: #339933;color: #439AD0;">=</span><span style="color: #3366CC;color: #439AD0;">&quot;text/javascript&quot;</span> src<span style="color: #339933;color: #439AD0;">=</span><span style="color: #3366CC;color: #439AD0;">&quot;../jQuery/ui/jquery.effects.core.js&quot;</span><span style="color: #339933;color: #439AD0;">&gt;&lt;/</span>script<span style="color: #339933;color: #439AD0;">&gt;</span>
<span style="color: #339933;color: #439AD0;">&lt;</span>script type<span style="color: #339933;color: #439AD0;">=</span><span style="color: #3366CC;color: #439AD0;">&quot;text/javascript&quot;</span> src<span style="color: #339933;color: #439AD0;">=</span><span style="color: #3366CC;color: #439AD0;">&quot;../jQuery/ui/jquery.effects.blind.js&quot;</span><span style="color: #339933;color: #439AD0;">&gt;&lt;/</span>script<span style="color: #339933;color: #439AD0;">&gt;</span>
<span style="color: #339933;color: #439AD0;">&lt;</span>script type<span style="color: #339933;color: #439AD0;">=</span><span style="color: #3366CC;color: #439AD0;">&quot;text/javascript&quot;</span> src<span style="color: #339933;color: #439AD0;">=</span><span style="color: #3366CC;color: #439AD0;">&quot;../jQuery/ui/jquery.effects.slide.js&quot;</span><span style="color: #339933;color: #439AD0;">&gt;&lt;/</span>script<span style="color: #339933;color: #439AD0;">&gt;</span>
<span style="color: #339933;color: #439AD0;">&lt;</span>script type<span style="color: #339933;color: #439AD0;">=</span><span style="color: #3366CC;color: #439AD0;">&quot;text/javascript&quot;</span> src<span style="color: #339933;color: #439AD0;">=</span><span style="color: #3366CC;color: #439AD0;">&quot;../jQuery/ui/jquery.effects.scale.js&quot;</span><span style="color: #339933;color: #439AD0;">&gt;&lt;/</span>script<span style="color: #339933;color: #439AD0;">&gt;</span>
<span style="color: #339933;color: #439AD0;">&lt;</span>script type<span style="color: #339933;color: #439AD0;">=</span><span style="color: #3366CC;color: #439AD0;">&quot;text/javascript&quot;</span> src<span style="color: #339933;color: #439AD0;">=</span><span style="color: #3366CC;color: #439AD0;">&quot;../jQuery/glob/jquery.glob.js&quot;</span><span style="color: #339933;color: #439AD0;">&gt;&lt;/</span>script<span style="color: #339933;color: #439AD0;">&gt;</span>
<span style="color: #339933;color: #439AD0;">&lt;</span>script type<span style="color: #339933;color: #439AD0;">=</span><span style="color: #3366CC;color: #439AD0;">&quot;text/javascript&quot;</span> src<span style="color: #339933;color: #439AD0;">=</span><span style="color: #3366CC;color: #439AD0;">&quot;../jQuery/glob/globinfo/jquery.glob.all.js&quot;</span><span style="color: #339933;color: #439AD0;">&gt;&lt;/</span>script<span style="color: #339933;color: #439AD0;">&gt;</span>
<span style="color: #339933;color: #439AD0;">&lt;</span>script type<span style="color: #339933;color: #439AD0;">=</span><span style="color: #3366CC;color: #439AD0;">&quot;text/javascript&quot;</span> src<span style="color: #339933;color: #439AD0;">=</span><span style="color: #3366CC;color: #439AD0;">&quot;../../jquery.wijmo.wijpopup.js&quot;</span><span style="color: #339933;color: #439AD0;">&gt;&lt;/</span>script<span style="color: #339933;color: #439AD0;">&gt;</span>
<span style="color: #339933;color: #439AD0;">&lt;</span>script type<span style="color: #339933;color: #439AD0;">=</span><span style="color: #3366CC;color: #439AD0;">&quot;text/javascript&quot;</span> src<span style="color: #339933;color: #439AD0;">=</span><span style="color: #3366CC;color: #439AD0;">&quot;../../jquery.wijmo.wijcalendar.js&quot;</span><span style="color: #339933;color: #439AD0;">&gt;&lt;/</span>script<span style="color: #339933;color: #439AD0;">&gt;</span></pre></div></div>

<p>HOLY CRAP! That is 12 scripts! On the sample page included with the download there are 8! I did a swift calculation and we are looking at around 560k just for the one with 8. That seems too extreme, right? Well, I had to see what the test page was doing and ran it Firefox. Well, it is running all of the open widgets (you only get half the widgets in the open version, and all of them in the licensed one &#8211; couldn&#8217;t find price). I then started eliminating scripts to see what would happen.</p>
<p>Two things popped out at me. If you want to use the graphs, you need at least 6 of those scripts: jQuery, jQueryUI, jQuery.glob (whatever the &#8216;f&#8217; that is), rapheal.js, the open wijmo, and the complete wijmo scripts. On top of that, raphael.js is a separate library. Which seems totally odd to require two different libraries to get a widget to work. Then it looks like there are some required stylesheets. All in all, that is a ton of http requests.</p>
<p>It does look like you can use only the widget script that you need, but you will still have to have a few others included to get them to work. Just after browsing though all that, I can&#8217;t say that this is a good option at all. If I were going to use a widget like what Wijmo offers, I would use <a href="http://jc-designs.net/blog/2010/06/testing-out-jquery-tools-pure-awesome/" target="_blank">jQuery Tools</a> instead. Smaller and by the looks way easier to use.</p>
<p>Thoughts?</p>
<p><strong>UPDATE: Wijmo has officially been released. Wijmo Complete has an introductory price of $499.</strong></p>
<h3>It&#8217;s all in your head!</h3>
<p><img src="http://www.jc-designs.net/newimages/blogImages/headjs.jpg" alt="Head JS - The only script in your head" class="left" />I&#8217;ve seen Head JS mentioned a few times, and my supervisor was the one that actually sent me a link to see what I thought. While it is not ready to be used in production, it is close and very cool. Basically, it loads all of your scripts in parallel so there is no page blocking. They claim that this will make your page load 100-400% times faster, and if you look at their test page, it does seem to do that. It does a lot more than that, and only weighs 2.3k. One thing I don&#8217;t like is that it says  &#8220;the only script in your head,&#8221; which to me, is not true unless they want you to write all of your extra js into the head.js file itself. Which may be the case. Anyway, calling your other js files in head is easy:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;color: #439AD0; font-weight: bold;">head.<span style="color: #660066;">ready</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #3366CC;color: #439AD0;">&quot;jquery&quot;</span><span style="color: #339933;color: #439AD0;">,</span> <span style="color: #003366; font-weight: bold;color: #439AD0;">function</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #009900;color: #439AD0;">&#41;</span> <span style="color: #009900;color: #439AD0;">&#123;</span>
	$<span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #3366CC;color: #439AD0;">'#container'</span><span style="color: #009900;color: #439AD0;">&#41;</span>.<span style="color: #660066;">hide</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #009900;color: #439AD0;">&#41;</span>.<span style="color: #660066;">fadeIn</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #CC0000;color: #439AD0;">3000</span><span style="color: #009900;color: #439AD0;">&#41;</span><span style="color: #339933;color: #439AD0;">;</span>							  
<span style="color: #009900;color: #439AD0;">&#125;</span><span style="color: #009900;color: #439AD0;">&#41;</span><span style="color: #339933;color: #439AD0;">;</span>
&nbsp;
head.<span style="color: #660066;">js</span><span style="color: #009900;color: #439AD0;">&#40;</span>
	<span style="color: #009900;color: #439AD0;">&#123;</span>jquery<span style="color: #339933;color: #439AD0;">:</span> <span style="color: #3366CC;color: #439AD0;">&quot;http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js?ver=1.4.1&quot;</span><span style="color: #009900;color: #439AD0;">&#125;</span><span style="color: #339933;color: #439AD0;">,</span>
	<span style="color: #009900;color: #439AD0;">&#123;</span>ui<span style="color: #339933;color: #439AD0;">:</span> <span style="color: #3366CC;color: #439AD0;">&quot;https://github.com/headjs/www/raw/master/content/test/jquery-ui.js&quot;</span><span style="color: #009900;color: #439AD0;">&#125;</span>
<span style="color: #009900;color: #439AD0;">&#41;</span><span style="color: #339933;color: #439AD0;">;</span></pre></div></div>

<p>You will see two things going on above. The first part is just a stupid function using jQuery, and the second part is where you call the files. You&#8217;ll notice that the word jquery is in front of the first call. They allow you to give labels to the files so that instead of putting a url to the file itself, people in production will be able to just call &#8216;jquery&#8217; and it will use it. Obviously the labels can be anything, but it really makes it a lot easier to know which script to use. I am going to assume because of what they show on their website, that you can use multiple libraries without any worry about conflicts.</p>
<p>On top of that, Head JS comes with a bunch of other stuff to make your life easier, such as: a CSS Modernizer, HTML5 enabler, a Screen Size detector, Dynamic CSS, a CSS Router (so you can target specific pages), a Browser detector, and Javascript Feature detection. That is a lot of stuff crammed into 2.3k. I can see Head JS becoming widely used once they get everything finalized.</p>
<p><strong>UPDATE: <a href="http://doctype.tv/printing">DOCTYPE just did a video</a> explaining this better than I ever could. I recommend watching it to learn more!</strong></p>
<h3>Ending thoughts</h3>
<p>I think I have wrote enough about Wijmo, but Head JS looks extremely promising. Once they have a stable release I will be curious to see if the <a href="http://html5boilerplate.com/">HTML5 Boilerplate</a> will incorporate it. I read that the creator has looked into it, but said it isn&#8217;t ready yet to be included. Curious to see what the final outcome of that will be.</p>
<p>Some things you find out there are cool, while others suck. Either way, it is fun to find out. Let me know your thoughts on either of these, because I am very curious to read other points of view.</p>
<div class="gator">
<a  href="http://secure.hostgator.com/~affiliat/cgi-bin/affiliates/clickthru.cgi?id=jcDesigns-" rel="nofollow"><img src="http://tracking.hostgator.com/img/Shared/468x60.gif" border=0></a></p>
<p>Coupon Code: webmachine</p>
</div>
 <img src="http://jc-designs.net/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=669" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://jc-designs.net/blog/2010/12/wijmo-and-headjs-reviews/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Another Simple jQuery Gallery Idea</title>
		<link>http://jc-designs.net/blog/2010/11/another-simple-jquery-gallery-idea/</link>
		<comments>http://jc-designs.net/blog/2010/11/another-simple-jquery-gallery-idea/#comments</comments>
		<pubDate>Tue, 09 Nov 2010 03:50:48 +0000</pubDate>
		<dc:creator>jcDesigns</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://jc-designs.net/blog/?p=636</guid>
		<description><![CDATA[Lock and Load that HTML A co-worker had asked me for some help the other day on the jQuery running his gallery. Of course, I was more than happy to help. He ran into other issues later (which he cleared up) involving a plugin, but that doesn&#8217;t really matter in this demo/tutorial. What he wanted [...]]]></description>
			<content:encoded><![CDATA[<h3>Lock and Load that HTML</h3>
<p>A co-worker had asked me for some help the other day on the jQuery running his gallery. Of course, I was more than happy to help. He ran into other issues later (which he cleared up) involving a plugin, but that doesn&#8217;t really matter in this demo/tutorial. What he wanted was to have a navigation at the top, each item pertaining to a different part of his portfolio (websites, flash work, graphic design&#8230;). Each section though had a ton of information that would increase the page load significantly if they were all loaded on the page at the same time. That ruled out putting a simple hide/show on some divs. My thought was, why don&#8217;t we put the HTML into separate files, and load them when a user clicks on one of the nav items. You can check out the gist of what was trying to be accomplished by check out the demo below.</p>
<p><a class="viewDemo" href="http://www.jc-designs.net/demo/gallery2.html">View Demo</a></p>
<p><span id="more-636"></span></p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;color: #439AD0; font-weight: bold;"><span style="color: #003366; font-weight: bold;color: #439AD0;">function</span> imageGroup <span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #009900;color: #439AD0;">&#41;</span> <span style="color: #009900;color: #439AD0;">&#123;</span>
		$<span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #3366CC;color: #439AD0;">'#holder'</span><span style="color: #009900;color: #439AD0;">&#41;</span>.<span style="color: #660066;">load</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #3366CC;color: #439AD0;">'imageGroup1.html'</span><span style="color: #009900;color: #439AD0;">&#41;</span>
		$<span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #3366CC;color: #439AD0;">'.image1'</span><span style="color: #009900;color: #439AD0;">&#41;</span>.<span style="color: #660066;">addClass</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #3366CC;color: #439AD0;">'active'</span><span style="color: #009900;color: #439AD0;">&#41;</span><span style="color: #339933;color: #439AD0;">;</span>
	<span style="color: #009900;color: #439AD0;">&#125;</span><span style="color: #339933;color: #439AD0;">;</span>
	imageGroup<span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #009900;color: #439AD0;">&#41;</span><span style="color: #339933;color: #439AD0;">;</span>
	$<span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #003366; font-weight: bold;color: #439AD0;">function</span> <span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #009900;color: #439AD0;">&#41;</span> <span style="color: #009900;color: #439AD0;">&#123;</span>
		$<span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #3366CC;color: #439AD0;">'#container a'</span><span style="color: #009900;color: #439AD0;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #003366; font-weight: bold;color: #439AD0;">function</span><span style="color: #009900;color: #439AD0;">&#40;</span>e<span style="color: #009900;color: #439AD0;">&#41;</span> <span style="color: #009900;color: #439AD0;">&#123;</span>
			e.<span style="color: #660066;">preventDefault</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #009900;color: #439AD0;">&#41;</span><span style="color: #339933;color: #439AD0;">;</span>
			$<span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #3366CC;color: #439AD0;">'#container a'</span><span style="color: #009900;color: #439AD0;">&#41;</span>.<span style="color: #660066;">removeClass</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #3366CC;color: #439AD0;">'active'</span><span style="color: #009900;color: #439AD0;">&#41;</span><span style="color: #339933;color: #439AD0;">;</span>
			$<span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #000066; font-weight: bold;color: #439AD0;">this</span><span style="color: #009900;color: #439AD0;">&#41;</span>.<span style="color: #660066;">addClass</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #3366CC;color: #439AD0;">'active'</span><span style="color: #009900;color: #439AD0;">&#41;</span><span style="color: #339933;color: #439AD0;">;</span>
		<span style="color: #009900;color: #439AD0;">&#125;</span><span style="color: #009900;color: #439AD0;">&#41;</span><span style="color: #339933;color: #439AD0;">;</span>
		$<span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #3366CC;color: #439AD0;">'.image1'</span><span style="color: #009900;color: #439AD0;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #003366; font-weight: bold;color: #439AD0;">function</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #009900;color: #439AD0;">&#41;</span><span style="color: #009900;color: #439AD0;">&#123;</span>$<span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #3366CC;color: #439AD0;">'#holder'</span><span style="color: #009900;color: #439AD0;">&#41;</span>.<span style="color: #660066;">load</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #3366CC;color: #439AD0;">'imageGroup1.html'</span><span style="color: #009900;color: #439AD0;">&#41;</span><span style="color: #339933;color: #439AD0;">;</span><span style="color: #009900;color: #439AD0;">&#125;</span><span style="color: #009900;color: #439AD0;">&#41;</span><span style="color: #339933;color: #439AD0;">;</span>
		$<span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #3366CC;color: #439AD0;">'.image2'</span><span style="color: #009900;color: #439AD0;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #003366; font-weight: bold;color: #439AD0;">function</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #009900;color: #439AD0;">&#41;</span><span style="color: #009900;color: #439AD0;">&#123;</span>$<span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #3366CC;color: #439AD0;">'#holder'</span><span style="color: #009900;color: #439AD0;">&#41;</span>.<span style="color: #660066;">load</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #3366CC;color: #439AD0;">'imageGroup2.html'</span><span style="color: #009900;color: #439AD0;">&#41;</span><span style="color: #339933;color: #439AD0;">;</span><span style="color: #009900;color: #439AD0;">&#125;</span><span style="color: #009900;color: #439AD0;">&#41;</span><span style="color: #339933;color: #439AD0;">;</span>
	<span style="color: #009900;color: #439AD0;">&#125;</span><span style="color: #009900;color: #439AD0;">&#41;</span><span style="color: #339933;color: #439AD0;">;</span></pre></div></div>

<h3>What its doing &#8211; and keeping it simple</h3>
<p>I&#8217;m sure there is a much more efficient way of writing the jQuery, but I was going for something simple he would be able to add to, and understand what was going on. What is going on you ask? Great question, and if you didn&#8217;t ask this article would be over.</p>
<p>The first two lines deal with loading content right off the bat. So I created a function which loads the HTML from the page &#8216;imageGroup1.html&#8217;. Just so you know what is going on, the two external HTML pages only contain images (that&#8217;s it, no html tag, no body, nothing but the img&#8217;s). You can obviously include whatever you want in those those. The second line of the first function then adds the active class to the first &#8216;a&#8217; tag, which has the class &#8216;active&#8217; on it. This gives the first nav item the roll-over state on page load, which you can see in the demo. Looking at the code above, you see the line &#8216;imageGroup();&#8217; which calls the function, because without it, those first lines don&#8217;t do anything. They will wait for a call that will never happen.</p>
<p>After that is an anonymous function (no need to name it for what we are doing here) that controls the switching of the class &#8216;active&#8217; between nav items, and the loading of HTML from different pages. First is the click event on all the &#8216;a&#8217; tags within the nav list. We prevent the default action of what &#8216;a&#8217; tags normally do, then remove the &#8216;active&#8217; class from all of them, and add it again to the specific one clicked. That moves the &#8216;active&#8217; class to whatever nav item was clicked last.</p>
<p>Next comes the actual loading of the external HTML. This is probably where a better method could be used, but we are not dealing with anything complicated here so I kept it simple. I am guessing a case switch could be used if we were dealing with a large number of items being loaded. Each of the &#8216;a&#8217; tags in the nav has a specific class, and when they are clicked, a specific HTML page gets loaded into a div with an id of &#8216;holder&#8217;. So if the first nav item is clicked, &#8216;imageGroup1.html&#8217; gets loaded into &#8216;holder&#8217;, and if the second is clicked, &#8216;imageGroup2.html&#8217; is loaded. That is all there is to it to this gallery.</p>
<h3>Final Words</h3>
<p>This is just a basic demo, so there is minimal styling going on, but think about what you can do with that. My co-worker added fancybox to it, to add some pop-ups when the images were clicked. You can add whatever the hell you want to this, like description text, fades, animations&#8230;whatever. Have fun with it, and let me know what you think!</p>
<div class="gator">
<a  href="http://secure.hostgator.com/~affiliat/cgi-bin/affiliates/clickthru.cgi?id=jcDesigns-" rel="nofollow"><img src="http://tracking.hostgator.com/img/Shared/468x60.gif" border=0></a></p>
<p>Coupon Code: webmachine</p>
</div>
 <img src="http://jc-designs.net/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=636" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://jc-designs.net/blog/2010/11/another-simple-jquery-gallery-idea/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Thinking Outside The Box With jQuery</title>
		<link>http://jc-designs.net/blog/2010/09/thinking-outside-the-box-with-jquery/</link>
		<comments>http://jc-designs.net/blog/2010/09/thinking-outside-the-box-with-jquery/#comments</comments>
		<pubDate>Wed, 22 Sep 2010 02:59:48 +0000</pubDate>
		<dc:creator>jcDesigns</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://jc-designs.net/blog/?p=557</guid>
		<description><![CDATA[Is it waves ahead of Flash? NOTE: Stick through to the end of the article, and I&#8217;ll give you a cool link for a reward! No, but it can still do a lot of cool crap. Today I was noodling around and somehow this idea popped into my head. Normally, at my current place of [...]]]></description>
			<content:encoded><![CDATA[<h3>Is it waves ahead of Flash?</h3>
<p><em>NOTE: Stick through to the end of the article, and I&#8217;ll give you a cool link for a reward!</em><br />
No, but it can still do a lot of cool crap. Today I was noodling around and somehow this idea popped into my head. Normally, at my current place of employment, we build animations using Flash. Butterflies fluttering around, fades and what-not, hell I even did a water ripple effect once. I thought, what if we could do some of the simple banners that are just plain fades and use jQuery instead of Flash to do everything. My initial idea was, what if a client has a photo of a beach, and he wants the stupid water to move. Could I do something in jQuery instead of having to rely on Flash?</p>
<h3>The set up</h3>
<p>My HTML for the demo is easy: a container div, 1 div with the original image, and 2 additional divs with only the water section of the image. 3 divs, 2 seperate images. The images are pretty large, because in this demo I was going for a rough effect rather than bringing the size down.</p>
<p><span id="more-557"></span><br />
The jQuery is rather simple, too. Two animations in a loop&#8230;1 on each of the &#8216;just water&#8217; images. The first animation moves it left and back, while the second moves it down and up. Here it is for you to look at:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;color: #439AD0; font-weight: bold;"><span style="color: #003366; font-weight: bold;color: #439AD0;">function</span> waves <span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #009900;color: #439AD0;">&#41;</span> <span style="color: #009900;color: #439AD0;">&#123;</span>
		<span style="color: #000066; font-weight: bold;color: #439AD0;">for</span><span style="color: #009900;color: #439AD0;">&#40;</span>i<span style="color: #339933;color: #439AD0;">=</span><span style="color: #CC0000;color: #439AD0;">0</span><span style="color: #339933;color: #439AD0;">;</span> i<span style="color: #339933;color: #439AD0;">&lt;</span><span style="color: #CC0000;color: #439AD0;">1000</span><span style="color: #339933;color: #439AD0;">;</span> i<span style="color: #339933;color: #439AD0;">++</span><span style="color: #009900;color: #439AD0;">&#41;</span> <span style="color: #009900;color: #439AD0;">&#123;</span>
			$<span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #3366CC;color: #439AD0;">'#two'</span><span style="color: #009900;color: #439AD0;">&#41;</span>.<span style="color: #660066;">animate</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #009900;color: #439AD0;">&#123;</span>
				<span style="color: #3366CC;color: #439AD0;">'top'</span> <span style="color: #339933;color: #439AD0;">:</span> <span style="color: #339933;color: #439AD0;">+</span><span style="color: #CC0000;color: #439AD0;">15</span><span style="color: #339933;color: #439AD0;">,</span>
				<span style="color: #3366CC;color: #439AD0;">'opacity'</span> <span style="color: #339933;color: #439AD0;">:</span> .2
			<span style="color: #009900;color: #439AD0;">&#125;</span><span style="color: #339933;color: #439AD0;">,</span><span style="color: #CC0000;color: #439AD0;">2000</span><span style="color: #009900;color: #439AD0;">&#41;</span>.<span style="color: #660066;">animate</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #009900;color: #439AD0;">&#123;</span>
				<span style="color: #3366CC;color: #439AD0;">'top'</span> <span style="color: #339933;color: #439AD0;">:</span> <span style="color: #339933;color: #439AD0;">-</span><span style="color: #CC0000;color: #439AD0;">2</span><span style="color: #339933;color: #439AD0;">,</span>
				<span style="color: #3366CC;color: #439AD0;">'opacity'</span> <span style="color: #339933;color: #439AD0;">:</span> <span style="color: #CC0000;color: #439AD0;">1</span>
			<span style="color: #009900;color: #439AD0;">&#125;</span><span style="color: #339933;color: #439AD0;">,</span><span style="color: #CC0000;color: #439AD0;">2000</span><span style="color: #009900;color: #439AD0;">&#41;</span><span style="color: #339933;color: #439AD0;">;</span>
			$<span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #3366CC;color: #439AD0;">'#three'</span><span style="color: #009900;color: #439AD0;">&#41;</span>.<span style="color: #660066;">animate</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #009900;color: #439AD0;">&#123;</span>
				<span style="color: #3366CC;color: #439AD0;">'left'</span> <span style="color: #339933;color: #439AD0;">:</span> <span style="color: #339933;color: #439AD0;">-</span><span style="color: #CC0000;color: #439AD0;">5</span><span style="color: #339933;color: #439AD0;">,</span>
				<span style="color: #3366CC;color: #439AD0;">'opacity'</span> <span style="color: #339933;color: #439AD0;">:</span> .2
			<span style="color: #009900;color: #439AD0;">&#125;</span><span style="color: #339933;color: #439AD0;">,</span><span style="color: #CC0000;color: #439AD0;">2000</span><span style="color: #009900;color: #439AD0;">&#41;</span>.<span style="color: #660066;">animate</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #009900;color: #439AD0;">&#123;</span>
				<span style="color: #3366CC;color: #439AD0;">'left'</span> <span style="color: #339933;color: #439AD0;">:</span> <span style="color: #CC0000;color: #439AD0;">0</span><span style="color: #339933;color: #439AD0;">,</span>
				<span style="color: #3366CC;color: #439AD0;">'opacity'</span> <span style="color: #339933;color: #439AD0;">:</span> .6
			<span style="color: #009900;color: #439AD0;">&#125;</span><span style="color: #339933;color: #439AD0;">,</span><span style="color: #CC0000;color: #439AD0;">2000</span><span style="color: #009900;color: #439AD0;">&#41;</span><span style="color: #339933;color: #439AD0;">;</span>			
		<span style="color: #009900;color: #439AD0;">&#125;</span><span style="color: #339933;color: #439AD0;">;</span>				
	<span style="color: #009900;color: #439AD0;">&#125;</span><span style="color: #339933;color: #439AD0;">;</span>
	waves<span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #009900;color: #439AD0;">&#41;</span><span style="color: #339933;color: #439AD0;">;</span></pre></div></div>

<p>I&#8217;m sure there is a better way to do that, but I am going for getting you thinking right now, not prettiness. I will assume you at least know enough about jQuery to understand what I am doing there, because there isn&#8217;t anything tricky or awesome going on.</p>
<p><a href="http://www.jc-designs.net/demo/waves.html">View Demo</a></p>
<h3>Thrillsville, but who really cares?</h3>
<p>The demo is more to show that you can do things you normally wouldn&#8217;t with jQuery. Sure you can build a cool slider, or drop down, or form validation, etc. The next time you have to do some little bit of animation though, maybe you will think about using jQuery instead of Flash. For instance, the butterfly thing I mentioned. All I did was create a movie clip in Flash that had different states of wing flappage. You could very easily do that with jQuery by doing a simple animation like my waves, only use an image sprite. Shift the sprite over every fraction of a second and you would have the same effect going.</p>
<p>After creating this moving water bit, I know I&#8217;ll be thinking outside the box, and see if maybe jQuery will fit the bill more easily. Please take note that I am not against Flash at all. I like using it, and there will be times where that is the only route to get a specific thing accomplished. I&#8217;m not on some crusade to get rid of it. All this was for, was to get you to think about the possibilities if you have jQuery at your disposal.</p>
<p>Now onto your reward! Check out <a href="http://www.dropmocks.com/">this link</a>, when you get there you&#8217;ll know what to do. Can&#8217;t use it in IE though, but I think they&#8217;ll get to that someday.</p>
<div class="gator">
<a  href="http://secure.hostgator.com/~affiliat/cgi-bin/affiliates/clickthru.cgi?id=jcDesigns-"><img src="http://tracking.hostgator.com/img/Shared/468x60.gif" border=0></a></p>
<p>Coupon Code: webmachine</p>
</div>
 <img src="http://jc-designs.net/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=557" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://jc-designs.net/blog/2010/09/thinking-outside-the-box-with-jquery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Actually Knowing What You Are Doing &#8211; jQuery Addition</title>
		<link>http://jc-designs.net/blog/2010/09/actually-knowing-what-you-are-doing-jquery-addition/</link>
		<comments>http://jc-designs.net/blog/2010/09/actually-knowing-what-you-are-doing-jquery-addition/#comments</comments>
		<pubDate>Tue, 21 Sep 2010 03:30:10 +0000</pubDate>
		<dc:creator>jcDesigns</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://jc-designs.net/blog/?p=555</guid>
		<description><![CDATA[THAT&#8217;S why we do that There are times that we learn to do something in web development, and we do them without really knowing the reason why we do it. For instance. I learned a couple of things today about jQuery. The first thing was about return false; versus preventDefault (which I learned here). Now, [...]]]></description>
			<content:encoded><![CDATA[<h3>THAT&#8217;S why we do that</h3>
<p>There are times that we learn to do something in web development, and we do them without really knowing the reason why we do it. For instance. I learned a couple of things today about jQuery.  The first thing was about return false; versus preventDefault (which I learned <a href="http://fuelyourcoding.com/jquery-events-stop-misusing-return-false/">here</a>). Now, I know the difference. The return false; kills event bubbling. That&#8217;s great, right? We don&#8217;t want that crap going up through the DOM. But what if you did? An example would be if you wanted to prevent a link from actually doing what the browser expects a link to do, AND have the parent div do something as well.</p>
<p><span id="more-555"></span><br />
Example &#8211; here is the html:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;color: #439AD0; font-weight: bold;">&lt;div id=&quot;myDiv&quot;&gt;
&lt;a href=&quot;http://www.google.com&quot;&gt;This is a test link.&lt;/a&gt;
&lt;div class=&quot;myClass&quot;&gt;&lt;p&gt;This is the div that should be hidden&lt;/p&gt;&lt;/div&gt;
&lt;/div&gt;</pre></div></div>

<p>Here is the CSS:</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;color: #439AD0; font-weight: bold;"><span style="color: #cc00cc;">#myDiv</span> <span style="color: #00AA00;color: #439AD0;">&#123;</span>
	<span style="color: #000000; font-weight: bold;color: #439AD0;">width</span><span style="color: #00AA00;color: #439AD0;">:</span> <span style="color: #933;">500px</span><span style="color: #00AA00;color: #439AD0;">;</span>
	<span style="color: #000000; font-weight: bold;color: #439AD0;">height</span><span style="color: #00AA00;color: #439AD0;">:</span> <span style="color: #933;">500px</span><span style="color: #00AA00;color: #439AD0;">;</span>
	<span style="color: #000000; font-weight: bold;color: #439AD0;">background</span><span style="color: #00AA00;color: #439AD0;">:</span> <span style="color: #993333;color: #439AD0;">none</span> <span style="color: #cc00cc;">#999999</span><span style="color: #00AA00;color: #439AD0;">;</span>
	<span style="color: #000000; font-weight: bold;color: #439AD0;">margin</span><span style="color: #00AA00;color: #439AD0;">:</span> <span style="color: #933;">30px</span> <span style="color: #993333;color: #439AD0;">auto</span><span style="color: #00AA00;color: #439AD0;">;</span>
<span style="color: #00AA00;color: #439AD0;">&#125;</span>
<span style="color: #6666ff;color: #439AD0;">.redHighlight</span> <span style="color: #00AA00;color: #439AD0;">&#123;</span>
	<span style="color: #000000; font-weight: bold;color: #439AD0;">color</span><span style="color: #00AA00;color: #439AD0;">:</span> <span style="color: #cc00cc;">#ff0000</span><span style="color: #00AA00;color: #439AD0;">;</span>
	<span style="color: #000000; font-weight: bold;color: #439AD0;">font-weight</span><span style="color: #00AA00;color: #439AD0;">:</span> <span style="color: #993333;color: #439AD0;">bold</span><span style="color: #00AA00;color: #439AD0;">;</span>
<span style="color: #00AA00;color: #439AD0;">&#125;</span></pre></div></div>

<p>And lastly, the jQuery:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;color: #439AD0; font-weight: bold;">$<span style="color: #009900;color: #439AD0;">&#40;</span>document<span style="color: #009900;color: #439AD0;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #003366; font-weight: bold;color: #439AD0;">function</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #009900;color: #439AD0;">&#41;</span> <span style="color: #009900;color: #439AD0;">&#123;</span>
$<span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #3366CC;color: #439AD0;">'#myDiv a'</span><span style="color: #009900;color: #439AD0;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #003366; font-weight: bold;color: #439AD0;">function</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #009900;color: #439AD0;">&#41;</span> <span style="color: #009900;color: #439AD0;">&#123;</span>		   
$<span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #3366CC;color: #439AD0;">'.myClass'</span><span style="color: #009900;color: #439AD0;">&#41;</span>.<span style="color: #660066;">addClass</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #3366CC;color: #439AD0;">'redHighlight'</span><span style="color: #009900;color: #439AD0;">&#41;</span><span style="color: #339933;color: #439AD0;">;</span>
<span style="color: #000066; font-weight: bold;color: #439AD0;">return</span> <span style="color: #003366; font-weight: bold;color: #439AD0;">false</span><span style="color: #339933;color: #439AD0;">;</span>
<span style="color: #009900;color: #439AD0;">&#125;</span><span style="color: #009900;color: #439AD0;">&#41;</span><span style="color: #339933;color: #439AD0;">;</span>
$<span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #3366CC;color: #439AD0;">'#myDiv'</span><span style="color: #009900;color: #439AD0;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #003366; font-weight: bold;color: #439AD0;">function</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #009900;color: #439AD0;">&#41;</span>  <span style="color: #009900;color: #439AD0;">&#123;</span>
$<span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #3366CC;color: #439AD0;">'.myClass'</span><span style="color: #009900;color: #439AD0;">&#41;</span>.<span style="color: #660066;">hide</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #009900;color: #439AD0;">&#41;</span><span style="color: #339933;color: #439AD0;">;</span>
<span style="color: #009900;color: #439AD0;">&#125;</span><span style="color: #009900;color: #439AD0;">&#41;</span><span style="color: #339933;color: #439AD0;">;</span>
<span style="color: #009900;color: #439AD0;">&#125;</span><span style="color: #009900;color: #439AD0;">&#41;</span><span style="color: #339933;color: #439AD0;">;</span></pre></div></div>

<p>This took me some time fiddling with a demo to see if what the above linked article was saying was true. The above code, will do two things: add the class &#8216;redHighlight&#8217; to .myClass if you click the &#8216;a&#8217; tag while preventing the link to go to Google, and 2) if you click the parent of the &#8216;a&#8217; tag, &#8216;#myDiv&#8217;, it will hide the div with the class &#8216;myClass&#8217;.</p>
<p>HERE though is what I learned. IF you click on the &#8216;a&#8217; tag, it WILL add the class &#8216;redHighlight&#8217;. What it won&#8217;t do, is hide the div &#8216;.myClass&#8217;, even though it is within &#8216;#myDiv&#8217;. This is because the return false; prevents the click event to bubble up to its parent, therefore the click that is supposed to hide &#8216;myClass&#8217; never fires. View the demo below to see what I am talking about, but click on the link, then refresh and click on the gray box.</p>
<p><a href="http://www.jc-designs.net/demo/return.html">View Demo</a></p>
<p>NOW change return false; to preventDefault, so it looks like this:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;color: #439AD0; font-weight: bold;">$<span style="color: #009900;color: #439AD0;">&#40;</span>document<span style="color: #009900;color: #439AD0;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #003366; font-weight: bold;color: #439AD0;">function</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #009900;color: #439AD0;">&#41;</span> <span style="color: #009900;color: #439AD0;">&#123;</span>
$<span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #3366CC;color: #439AD0;">'#myDiv a'</span><span style="color: #009900;color: #439AD0;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #003366; font-weight: bold;color: #439AD0;">function</span><span style="color: #009900;color: #439AD0;">&#40;</span>e<span style="color: #009900;color: #439AD0;">&#41;</span> <span style="color: #009900;color: #439AD0;">&#123;</span>
e.<span style="color: #660066;">preventDefault</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #009900;color: #439AD0;">&#41;</span><span style="color: #339933;color: #439AD0;">;</span>
$<span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #3366CC;color: #439AD0;">'.myClass'</span><span style="color: #009900;color: #439AD0;">&#41;</span>.<span style="color: #660066;">addClass</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #3366CC;color: #439AD0;">'redHighlight'</span><span style="color: #009900;color: #439AD0;">&#41;</span><span style="color: #339933;color: #439AD0;">;</span>
<span style="color: #009900;color: #439AD0;">&#125;</span><span style="color: #009900;color: #439AD0;">&#41;</span><span style="color: #339933;color: #439AD0;">;</span>
$<span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #3366CC;color: #439AD0;">'#myDiv'</span><span style="color: #009900;color: #439AD0;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #003366; font-weight: bold;color: #439AD0;">function</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #009900;color: #439AD0;">&#41;</span>  <span style="color: #009900;color: #439AD0;">&#123;</span>
$<span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #3366CC;color: #439AD0;">'.myClass'</span><span style="color: #009900;color: #439AD0;">&#41;</span>.<span style="color: #660066;">hide</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #009900;color: #439AD0;">&#41;</span><span style="color: #339933;color: #439AD0;">;</span>
<span style="color: #009900;color: #439AD0;">&#125;</span><span style="color: #009900;color: #439AD0;">&#41;</span><span style="color: #339933;color: #439AD0;">;</span>
<span style="color: #009900;color: #439AD0;">&#125;</span><span style="color: #009900;color: #439AD0;">&#41;</span><span style="color: #339933;color: #439AD0;">;</span></pre></div></div>

<p><a href="http://www.jc-designs.net/demo/return2.html">View Demo</a></p>
<p>View the above demo, and again, click on the link to see what happens, refresh and click on the surrounding gray box. You will see the difference. The first demo changes the color, the second demo hides the the &#8216;myClass&#8217; div. Why does it happen differently with preventDefault? Because the bubbling effect goes up to the parent div. Meaning the click event bubbles up to the parent div &#8216;myDiv&#8217; and fires off the event to hide the div &#8216;myClass&#8217;.</p>
<p>PRETTY DAMN AWESOME! I knew before what event propagation meant, but I never really understood the effect it would have. Now I do because of the linked article. So remember&#8230;return false will kill event bubbling, prevents the default behavior, and stops callback execution and returns immediately when called. The preventDefault() only prevents the default behavior.</p>
<h3>Caching the location of your selection</h3>
<p>The second thing I learned doesn&#8217;t actually effect how I write my code. This is more of a &#8220;I didn&#8217;t know that..&#8221; type of thing. Do you know why you use variables when you are writing jQuery? If you answered &#8220;Because it is easier to write the variable name than writing the damn thing out everytime&#8221;&#8230;well you are right. BUT there is another reason. When you write a variable like:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;color: #439AD0; font-weight: bold;"><span style="color: #003366; font-weight: bold;color: #439AD0;">var</span> awesome <span style="color: #339933;color: #439AD0;">=</span> $<span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #3366CC;color: #439AD0;">'#pfarmFlavorBlastedGoldfish'</span><span style="color: #009900;color: #439AD0;">&#41;</span><span style="color: #339933;color: #439AD0;">;</span></pre></div></div>

<p>You are caching the location of that selection. If you wrote it out each time you needed it, like so:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;color: #439AD0; font-weight: bold;">$<span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #3366CC;color: #439AD0;">'#pfarmFlavorBlastedGoldfish'</span><span style="color: #009900;color: #439AD0;">&#41;</span>.<span style="color: #660066;">hide</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #009900;color: #439AD0;">&#41;</span><span style="color: #339933;color: #439AD0;">;</span>
$<span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #3366CC;color: #439AD0;">'#pfarmFlavorBlastedGoldfish'</span><span style="color: #009900;color: #439AD0;">&#41;</span>.<span style="color: #660066;">show</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #009900;color: #439AD0;">&#41;</span><span style="color: #339933;color: #439AD0;">;</span>
$<span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #3366CC;color: #439AD0;">'#pfarmFlavorBlastedGoldfish'</span><span style="color: #009900;color: #439AD0;">&#41;</span>.<span style="color: #660066;">eatthehelloutthem</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #009900;color: #439AD0;">&#41;</span><span style="color: #339933;color: #439AD0;">;</span></pre></div></div>

<p>Yes I am eating these addicting things&#8230;but anyway, the above is repeatedly querying the DOM and creating multiple jQuery objects.</p>
<h3>Final words</h3>
<p>Sometimes we do things just because we read how to do them, but not the actual WHY we are doing it a certain way. I love learning the reasons behind things that I do, such as the two examples I&#8217;ve written about tonight. It strengthens my knowledge of the subject, in this case jQuery, and makes it easier to explain to someone else why it is I am doing something.</p>
<p>A VERY big shout out to Doug Neiner at <a href="http://fuelyourcoding.com/jquery-events-stop-misusing-return-false/">Fuel Your Coding</a> for that article. It taught me a lot. And a thanks to <a href="http://net.tutsplus.com/tutorials/javascript-ajax/14-helpful-jquery-tricks-notes-and-best-practices">net.tutsplus.com</a> for a bunch of helpful hints.</p>
<div class="gator">
<a  href="http://secure.hostgator.com/~affiliat/cgi-bin/affiliates/clickthru.cgi?id=jcDesigns-"><img src="http://tracking.hostgator.com/img/Shared/468x60.gif" border=0></a></p>
<p>Coupon Code: webmachine</p>
</div>
 <img src="http://jc-designs.net/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=555" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://jc-designs.net/blog/2010/09/actually-knowing-what-you-are-doing-jquery-addition/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Adding Scripts, CSS, And Extras &#8211; When Is It Too Much?</title>
		<link>http://jc-designs.net/blog/2010/09/adding-scripts-css-and-extras-when-is-it-too-much/</link>
		<comments>http://jc-designs.net/blog/2010/09/adding-scripts-css-and-extras-when-is-it-too-much/#comments</comments>
		<pubDate>Thu, 09 Sep 2010 02:40:58 +0000</pubDate>
		<dc:creator>jcDesigns</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://jc-designs.net/blog/?p=541</guid>
		<description><![CDATA[Let&#8217;s stick that in there too! Ok, I will admit that this topic just popped into my head, mainly because of what I was doing at work, and then thinking of the HTML5 Boilerplate. I&#8217;m using that as a starting point to illustrate what I am talking about, not bashing it. I think the template [...]]]></description>
			<content:encoded><![CDATA[<h3>Let&#8217;s stick that in there too!</h3>
<p>Ok, I will admit that this topic just popped into my head, mainly because of what I was doing at work, and then thinking of the <a href="http://html5boilerplate.com/">HTML5 Boilerplate</a>. I&#8217;m using that as a starting point to illustrate what I am talking about, not bashing it. I think the template is awesome and I am using it in my personal projects.</p>
<p>Let&#8217;s say we are using it to start a new site. It has a lot of awesome things in it to compensate for a ton of stuff. It has jQuery, a ready to go script page for your js, a nicely organized style sheet, dd-belatedpng.js for png support in IE6, Google Analytics code, Modernizer 1.5 js for HTML5 tag support in browsers that don&#8217;t actually support HTML5&#8230;and a few other things I can&#8217;t remember at the moment. For argument&#8217;s sake though, let&#8217;s just pretend that is it.</p>
<p><span id="more-541"></span></p>
<h3>Now you start adding in your stuff</h3>
<p>The blank js file for your code is already taken care of, so you don&#8217;t have to add that. But maybe you are adding a piece of Flash, which naturally leads you to throwing swfobject in. Ohhh, and that neat <a href="http://nivo.dev7studios.com/">Nivo slider</a> on there too! Hmmm&#8230;.ok, downloaded and now added the plugin to your page.</p>
<p>That should be it right? Oh crap! Since we are being extra cool and tricky, we&#8217;ll need some sort of lightbox plugin, so insert that over there. THAT should be about it&#8230;oh&#8230;you are right, we want to use some sort of easing for that bit of jQuery you were planning, better put that in its correct spot. Done? Maybe?</p>
<h3>Is there such a thing as too much</h3>
<p>This is just the kind of stuff that I can think of adding that might make sense. You could probably take a few of those off if we are being reasonable. I&#8217;m a reasonable kind of guy. Now take into account a customer who thinks they know what the #@$% they are doing and says &#8220;I saw this piece of utter crap on this other site, and I want mine to do that to. Oh, and the twitter-y posting thing on the sidebar thinga-ma-jigger, ya I want that also. Ohhhh, you know what would also be the cat&#8217;s meow? That other piece of stupid I can barely describe to you in regular English, but is nearly impossible without you seeing my hand movements!&#8221;</p>
<p>Now that was sort of for comic relief, but I think you get the point. Go back to before the made up customer bit. Is there a point where it is just too much being added? Where does it stop? The HTML5 boilerplate is awesome the way it is. I can add my own jQuery functions without adding another request, it takes care of a lot of old browser issues (which for some reason I am very opposed to letting go for some idiot reason), and basically is my dream starting template. There are going to be a ton of people adding on to it though. Tons more scripts, and what-not&#8230;PLUS things we haven&#8217;t even heard of yet to be inserted into the page later.</p>
<p>I don&#8217;t want to use the word, but all I can think of is bloated. A word I use to describe certain IDE&#8217;s I have tried that have too many feaures. But honestly, do we actually need to use all that crap? For all the headaches we can think of in web development, IE, with all its versions, really adds to this &#8220;bloat&#8221;. If you dropped everything but IE9, when it comes out of course, you could probably drop the modernizer js, the png fix, no more PIE, and the other crap we need to make the lesser versions work. This is BEFORE we actually do ANY kind of design and layout work, too!</p>
<p>I&#8217;m not trying to tell you what to add or not to add to your websites to make it awesome. I&#8217;m just trying to make you stop and think for a minute, and maybe answer my question in the comments (they would be very welcome!). So&#8230;..where, if there is such a thing, is the cut off point, where we just say &#8220;This is getting ridiculous! No more clutter!&#8221; Maybe we aren&#8217;t there yet, but it just seems like we are getting close to that line with every new bit of cool we add.</p>
<p>I&#8217;ll leave you with a musical quote that has nothing to do with this topic, because I am listening to Children of Bodom right now (favorite band at the moment): &#8220;Waiting for you I want to just tell you, if you want peace, prepare for war!&#8221;</p>
<div class="gator">
<a  href="http://secure.hostgator.com/~affiliat/cgi-bin/affiliates/clickthru.cgi?id=jcDesigns-"><img src="http://tracking.hostgator.com/img/Shared/468x60.gif" border=0></a></p>
<p>Coupon Code: webmachine</p>
</div>
 <img src="http://jc-designs.net/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=541" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://jc-designs.net/blog/2010/09/adding-scripts-css-and-extras-when-is-it-too-much/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Creating a simple jQuery Gallery</title>
		<link>http://jc-designs.net/blog/2010/08/creating-a-simple-jquery-gallery/</link>
		<comments>http://jc-designs.net/blog/2010/08/creating-a-simple-jquery-gallery/#comments</comments>
		<pubDate>Thu, 12 Aug 2010 04:14:27 +0000</pubDate>
		<dc:creator>jcDesigns</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://jc-designs.net/blog/?p=495</guid>
		<description><![CDATA[Thinking it through I can&#8217;t claim anything new with this, but I would like to show you how to use jQuery to build a very simple image gallery. This one really hit home on how important it is to think your way through what you want jQuery to do BEFORE you start writing the code. [...]]]></description>
			<content:encoded><![CDATA[<h3>Thinking it through</h3>
<p>I can&#8217;t claim anything new with this, but I would like to show you how to use jQuery to build a very simple image gallery. This one really hit home on how important it is to think your way through what you want jQuery to do BEFORE you start writing the code. You will find that you get into trouble if you don&#8217;t.</p>
<p><a href="http://www.jc-designs.net/demo/simpleGallery.html" target="_blank">Click here</a> to see the demo.</p>
<h3>Binary Solo!</h3>
<p>Ten points if you can comment and tell me what HBO show that heading is from. Anyway, on to the code! I will leave out the css because it is really irrelevant. You can style your gallery however you want. This is just for demo purposes.</p>
<p><span id="more-495"></span><br />
Here is the HTML:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;color: #439AD0; font-weight: bold;">&lt;div id=&quot;simple&quot;&gt;
&lt;a href=&quot;images/green_L.jpg&quot;&gt;&lt;img src=&quot;images/green_S.jpg&quot; width=&quot;100&quot; height=&quot;100&quot; alt=&quot;Green&quot;&gt;&lt;/a&gt;
&lt;a href=&quot;images/purple_L.jpg&quot;&gt;&lt;img src=&quot;images/purple_S.jpg&quot; width=&quot;100&quot; height=&quot;100&quot; alt=&quot;Purple&quot;&gt;&lt;/a&gt;
&lt;a href=&quot;images/blue_L.jpg&quot;&gt;&lt;img src=&quot;images/blue_S.jpg&quot; width=&quot;100&quot; height=&quot;100&quot; alt=&quot;Blue&quot;&gt;&lt;/a&gt;
&lt;/div&gt;</pre></div></div>

<p>As you can see, each &#8216;a&#8217; tag is wrapped around an image. The image tag&#8217;s source is the thumbnail, while the href of the &#8216;a&#8217; tag is the src of the large photo. If you look at the demo link above, you will see what it is supposed to do. Click on the thumbnails and you will see the Large image swap out for the matching thumbnail image.</p>
<p>Now here is the first part of the jQuery code, I&#8217;ll do it in 3 sections:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;color: #439AD0; font-weight: bold;">$<span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #3366CC;color: #439AD0;">'#simple a'</span><span style="color: #009900;color: #439AD0;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #003366; font-weight: bold;color: #439AD0;">function</span><span style="color: #009900;color: #439AD0;">&#40;</span>evt<span style="color: #009900;color: #439AD0;">&#41;</span> <span style="color: #009900;color: #439AD0;">&#123;</span>
		 evt.<span style="color: #660066;">preventDefault</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #009900;color: #439AD0;">&#41;</span><span style="color: #339933;color: #439AD0;">;</span>
	     <span style="color: #003366; font-weight: bold;color: #439AD0;">var</span> imgPath <span style="color: #339933;color: #439AD0;">=</span> $<span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #000066; font-weight: bold;color: #439AD0;">this</span><span style="color: #009900;color: #439AD0;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #3366CC;color: #439AD0;">'href'</span><span style="color: #009900;color: #439AD0;">&#41;</span><span style="color: #339933;color: #439AD0;">;</span>
		 <span style="color: #003366; font-weight: bold;color: #439AD0;">var</span> oldImage <span style="color: #339933;color: #439AD0;">=</span> $<span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #3366CC;color: #439AD0;">'#photo img'</span><span style="color: #009900;color: #439AD0;">&#41;</span><span style="color: #339933;color: #439AD0;">;</span>
		 <span style="color: #000066; font-weight: bold;color: #439AD0;">if</span> <span style="color: #009900;color: #439AD0;">&#40;</span>imgPath <span style="color: #339933;color: #439AD0;">==</span> oldImage.<span style="color: #660066;">attr</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #3366CC;color: #439AD0;">'src'</span><span style="color: #009900;color: #439AD0;">&#41;</span><span style="color: #009900;color: #439AD0;">&#41;</span> <span style="color: #009900;color: #439AD0;">&#123;</span> 
		 	<span style="color: #000066; font-weight: bold;color: #439AD0;">return</span><span style="color: #339933;color: #439AD0;">;</span>
		 <span style="color: #009900;color: #439AD0;">&#125;</span> <span style="color: #000066; font-weight: bold;color: #439AD0;">else</span> <span style="color: #009900;color: #439AD0;">&#123;</span>
       $<span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #3366CC;color: #439AD0;">'.selected'</span><span style="color: #009900;color: #439AD0;">&#41;</span>.<span style="color: #660066;">removeClass</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #3366CC;color: #439AD0;">'selected'</span><span style="color: #009900;color: #439AD0;">&#41;</span><span style="color: #339933;color: #439AD0;">;</span>		
			 $<span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #000066; font-weight: bold;color: #439AD0;">this</span><span style="color: #009900;color: #439AD0;">&#41;</span>.<span style="color: #660066;">addClass</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #3366CC;color: #439AD0;">'selected'</span><span style="color: #009900;color: #439AD0;">&#41;</span><span style="color: #339933;color: #439AD0;">;</span></pre></div></div>

<p>Starting with line 1 -</p>
<ol>
<li>Get all the &#8216;a&#8217; tags with in the div that has an id of &#8216;simple&#8217;</li>
<li>Prevent the default action of the &#8216;a&#8217; tag &#8211; if you don&#8217;t do this, it just loads a page with just the large image</li>
<li>Create variable that is equal to the href of the &#8216;a&#8217; tag</li>
<li>Create a variable equal to the image in the div with an id of #photo (gets the large img)</li>
<li>If the &#8216;a&#8217; tag&#8217;s href is equal to the large image source don&#8217;t do anything &#8211; means you just clicked the thumbnail that matches the large image</li>
<li>Otherwise do this (the else line)</li>
<li>Find the &#8216;a&#8217; tag with the class selected on it, remove the class</li>
<li>And add it to the one the user clicked (&#8216;selected&#8217; class gets placed on the &#8216;a&#8217; tag clicked)</li>
</ol>
<p>So far so good? On to the next chunk:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;color: #439AD0; font-weight: bold;"> <span style="color: #003366; font-weight: bold;color: #439AD0;">var</span> newImage <span style="color: #339933;color: #439AD0;">=</span> $<span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #3366CC;color: #439AD0;">'&lt;img src=&quot;'</span> <span style="color: #339933;color: #439AD0;">+</span> imgPath <span style="color: #339933;color: #439AD0;">+</span><span style="color: #3366CC;color: #439AD0;">'&quot;&gt;'</span><span style="color: #009900;color: #439AD0;">&#41;</span><span style="color: #339933;color: #439AD0;">;</span>
			 newImage.<span style="color: #660066;">hide</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #009900;color: #439AD0;">&#41;</span><span style="color: #339933;color: #439AD0;">;</span>
			 $<span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #3366CC;color: #439AD0;">'#photo'</span><span style="color: #009900;color: #439AD0;">&#41;</span>.<span style="color: #660066;">prepend</span><span style="color: #009900;color: #439AD0;">&#40;</span>newImage<span style="color: #009900;color: #439AD0;">&#41;</span><span style="color: #339933;color: #439AD0;">;</span>
			 oldImage.<span style="color: #660066;">fadeOut</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #CC0000;color: #439AD0;">1000</span><span style="color: #339933;color: #439AD0;">,</span><span style="color: #003366; font-weight: bold;color: #439AD0;">function</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #009900;color: #439AD0;">&#41;</span><span style="color: #009900;color: #439AD0;">&#123;</span>
		     $<span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #000066; font-weight: bold;color: #439AD0;">this</span><span style="color: #009900;color: #439AD0;">&#41;</span>.<span style="color: #660066;">remove</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #009900;color: #439AD0;">&#41;</span><span style="color: #339933;color: #439AD0;">;</span>
				<span style="color: #009900;color: #439AD0;">&#125;</span><span style="color: #009900;color: #439AD0;">&#41;</span><span style="color: #339933;color: #439AD0;">;</span>
&nbsp;
			 newImage.<span style="color: #660066;">fadeIn</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #CC0000;color: #439AD0;">1000</span><span style="color: #009900;color: #439AD0;">&#41;</span><span style="color: #339933;color: #439AD0;">;</span>
		 <span style="color: #009900;color: #439AD0;">&#125;</span>
	<span style="color: #009900;color: #439AD0;">&#125;</span><span style="color: #009900;color: #439AD0;">&#41;</span><span style="color: #339933;color: #439AD0;">;</span></pre></div></div>

<ol>
<li>Create a new image set to a variable, where it&#8217;s source is equal to the href of the &#8216;a&#8217; tag clicked</li>
<li>Hide this new image</li>
<li>Prepend the new image to the div with an id of &#8216;photo&#8217; (meaning you created html that is an image tag with a source attribute, and you are now placing it as the first child of &#8216;photo&#8217;).</li>
<li>Fade out the old image, and when it is done, use a call back function to remove it &#8211; so the large image that was showing fades, then gets removed from the DOM</li>
<li>Fade in the new image you created</li>
</ol>
<p>And finally:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;color: #439AD0; font-weight: bold;">$<span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #3366CC;color: #439AD0;">'#simple a:eq(0)'</span><span style="color: #009900;color: #439AD0;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;color: #439AD0;">&#40;</span><span style="color: #009900;color: #439AD0;">&#41;</span><span style="color: #339933;color: #439AD0;">;</span></pre></div></div>

<p>This last line is basically saying &#8220;Let&#8217;s pretend that the 1st &#8216;a&#8217; tag has already been clicked, which is why you see the large green image. If you didn&#8217;t have that line, there would be no large image showing when the document loaded.</p>
<h3>And there you have it!</h3>
<p>Now of course you can add all sorts of crap to make it even more flashy, but then&#8230;it wouldn&#8217;t be a &#8220;simple&#8221; gallery, now would it. If you have any questions, let me know!</p>
<div class="gator">
<a  href="http://secure.hostgator.com/~affiliat/cgi-bin/affiliates/clickthru.cgi?id=jcDesigns-"><img src="http://tracking.hostgator.com/img/Shared/468x60.gif" border=0></a></p>
<p>Coupon Code: webmachine</p>
</div>
 <img src="http://jc-designs.net/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=495" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://jc-designs.net/blog/2010/08/creating-a-simple-jquery-gallery/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>

