<?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>Devirtuoso &#187; HTML</title>
	<atom:link href="http://www.devirtuoso.com/category/front-end-development/html-front-end-development/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.devirtuoso.com</link>
	<description>Web Development Wickedness</description>
	<lastBuildDate>Sat, 20 Mar 2010 16:35:57 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Tips to Build a Better Newsletter</title>
		<link>http://www.devirtuoso.com/2009/09/tips-to-build-a-better-newsletter/</link>
		<comments>http://www.devirtuoso.com/2009/09/tips-to-build-a-better-newsletter/#comments</comments>
		<pubDate>Fri, 11 Sep 2009 01:57:44 +0000</pubDate>
		<dc:creator>Shawn</dc:creator>
				<category><![CDATA[Development Best Practices]]></category>
		<category><![CDATA[Front End Development]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[best practices]]></category>
		<category><![CDATA[newsletter]]></category>

		<guid isPermaLink="false">http://www.devirtuoso.com/?p=1104</guid>
		<description><![CDATA[Newsletters unfortunately are a necessary evil.&#160; Developers hate them and marketers love them.&#160; Here is a couple tips to help you through your next newsletter.
 
&#160;
Newsletter Width
Probably the most common question regarding newsletter is what dimensions should they be.&#160; The problem is each mail client is completely different.&#160; Some are tall and skinny, others short [...]]]></description>
			<content:encoded><![CDATA[<p>Newsletters unfortunately are a necessary evil.&#160; Developers hate them and marketers love them.&#160; Here is a couple tips to help you through your next newsletter.</p>
<p> <span id="more-1104"></span>
<p>&#160;</p>
<h2>Newsletter Width</h2>
<p>Probably the most common question regarding newsletter is what dimensions should they be.&#160; The problem is each mail client is completely different.&#160; Some are tall and skinny, others short and fat.&#160; It’s kind of like the left over bin at a bargain basement sale, you don’t know what you’re going to get.&#160; According to <a title="Campaign Monitor" href="http://www.campaignmontior.com" target="_blank">campaignmontior.com</a>, they suggest not to go any wider than 550-600 pixels.</p>
<p><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="newsletter width" border="0" alt="newsletter width" src="http://www.devirtuoso.com/wp-content/uploads/2009/09/image25.png" width="445" height="199" /> </p>
<p>&#160;</p>
<h2>Tables for Structure</h2>
<p>You’ve spent all this time using divs and CSS in your websites to layout everything.&#160; Well with email you can forget all that. Back to the 1990’s we go.&#160; Best practice for laying out columns or any other structural areas is to use the good ol’ table.&#160; A lot mail clients don’t support the CSS that make using divs a viable solutions.</p>
<p><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="table structure" border="0" alt="table structure" src="http://www.devirtuoso.com/wp-content/uploads/2009/09/image26.png" width="445" height="445" /> </p>
<p>&#160;</p>
<h2>Inline Styles</h2>
<p>It’s generally good practice to keep all your styles inline.&#160; Some mail clients take pleasure in adding their own CSS to the equation which throws yours out the window. Inline styles insure the mail client uses your styles and not theirs.&#160; If you do wish to put your styles at the top of your document, just be sure to do it within the body tag.&#160; I know what your thinking…but that won’t validate?&#160; You’re absolute right, but some mail clients totally discard the head tag, so anything in there will be thrown out like 2 month old milk.</p>
<p><a href="http://www.devirtuoso.com/wp-content/uploads/2009/09/image27.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="inline styles" border="0" alt="inline styles" src="http://www.devirtuoso.com/wp-content/uploads/2009/09/image_thumb.png" width="445" height="163" /></a> </p>
<p>&#160;</p>
<h2>Padding or Width, Not Both</h2>
<p>In CSS it’s generally good practice to keep padding and width separate.&#160; The same goes for emails.&#160; Width and padding don’t get along. Think of them like the contenders in the next UFC fight night.&#160; Since the mail clients are still stuck in prehistoric web days, padding can sometimes add to the width, even if the width is specified.&#160; If you need to have both then you’ll have to put a table within a table.&#160; The outside table cell specifying the width, and the inside one specifying the padding.</p>
<p><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="padding or width, not both" border="0" alt="padding or width, not both" src="http://www.devirtuoso.com/wp-content/uploads/2009/09/image28.png" width="445" height="445" /> </p>
<p>&#160;</p>
<h2>Backgrounds</h2>
<p>Unfortunately Outlook 2007 screwed this up for everyone.&#160; It doesn’t support background images.&#160; So consider this when designing your next newsletter.&#160; Also the body tag gets stripped of any styles, so if you put a background color on it, it won’t show up in some mail clients.&#160; You’re best bet is to wrap you’re entire newsletter in a table, and apply the background color to the cell.&#160; It’s also good practice to use the old bgcolor attribute in place of the CSS.&#160; It ensures that all mail clients will display your background color.</p>
<p><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="backgrounds" border="0" alt="backgrounds" src="http://www.devirtuoso.com/wp-content/uploads/2009/09/image29.png" width="445" height="280" /> </p>
<p>&#160;</p>
<h2>JavaScript / Flash</h2>
<p>Plain and simple, JavaScript and Flash aren’t supported, some cases they are, but most aren’t..&#160; They’re like the embarrassing friend of yours that nobody wants to hang out with.&#160; Sorry.</p>
<p><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="don&#39;t use flash or javascript" border="0" alt="don&#39;t use flash or javascript" src="http://www.devirtuoso.com/wp-content/uploads/2009/09/image30.png" width="445" height="263" /> </p>
<p>&#160;</p>
<h2>Images</h2>
<p>Consider it good practice to always specify the width, height, and alt tags of all your images.&#160; A lot of email clients have images shut off automatically.&#160; With the width and height specified it will keep the structure of your layout, and the alt tag will give a description of the image.&#160; </p>
<p><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="width height alt tags" border="0" alt="width height alt tags" src="http://www.devirtuoso.com/wp-content/uploads/2009/09/image31.png" width="445" height="117" /> </p>
<p>One extra little tip for images, sometimes you’ll notice an extra space underneath your images that you can’t get rid of.&#160; This can be a couple of things.</p>
<ol>
<li>You set your doctype of your document.&#160; Get rid of the doctype, or set it to HTML 4 transitional to fix this problem. </li>
<li>An old HTML bug where the image should be right up against the closing &lt;/td&gt; or else it throws in an extra space. </li>
</ol>
<h2>Conclusion</h2>
<p>In general try and think like you’re back in the old days of internet.&#160; For those younger people out there that haven’t developed in the olden days, now you see what we had to put up with, nothing works the way it should…wow I sound like my father. <img src='http://www.devirtuoso.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.devirtuoso.com/2009/09/tips-to-build-a-better-newsletter/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Beginners Guide to jQuery Sorting Part 2</title>
		<link>http://www.devirtuoso.com/2009/09/beginners-guide-to-jquery-sorting-part-2/</link>
		<comments>http://www.devirtuoso.com/2009/09/beginners-guide-to-jquery-sorting-part-2/#comments</comments>
		<pubDate>Thu, 03 Sep 2009 21:56:03 +0000</pubDate>
		<dc:creator>Shawn</dc:creator>
				<category><![CDATA[Ajax]]></category>
		<category><![CDATA[Front End Development]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[How to]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[JQuery]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[web development]]></category>

		<guid isPermaLink="false">http://www.devirtuoso.com/?p=1040</guid>
		<description><![CDATA[In the last tutorial we covered how to reorder a list by dragging and dropping.&#160; In this tutorial we will show how to save the order of the list via Ajax.

Where We Left Off
We should be at a point where we now know how to reorder a list.&#160; If you haven’t read the previous tutorial [...]]]></description>
			<content:encoded><![CDATA[<p>In the <a title="Beginners Guide to jQuery Sorting" href="http://www.devirtuoso.com/2009/09/beginners-guide-to-jquery-sorting/" target="_blank">last tutorial</a> we covered how to reorder a list by dragging and dropping.&#160; In this tutorial we will show how to <strong>save the order</strong> of the list via <strong>Ajax</strong>.</p>
<p><span id="more-1040"></span></p>
<h2>Where We Left Off</h2>
<p>We should be at a point where we now know how to reorder a list.&#160; If you haven’t read the previous tutorial or aren’t certain on how to reorder lists in jQuery, I encourage you to check out <a href="http://www.devirtuoso.com/2009/09/beginners-guide-to-jquery-sorting/" target="_blank">Beginners Guide to jQuery Sorting part 1</a>.</p>
<p>Here is the code from the previous post:</p>
<div class="codecolorer-container html4strict " style="overflow:auto;white-space:nowrap;width:580px"><table cellspacing="0" cellpadding="0"><tbody><tr><td class="line-numbers"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br /></div></td><td><div class="html4strict codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="sc0">&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot;</span><br />
<span class="sc0">&nbsp; &nbsp; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;</span><br />
<br />
<span class="sc2">&lt;<a href="http://december.com/html/4/element/html.html"><span class="kw2">html</span></a> <span class="kw3">lang</span><span class="sy0">=</span><span class="st0">&quot;en&quot;</span>&gt;</span><br />
<span class="sc2">&lt;<a href="http://december.com/html/4/element/head.html"><span class="kw2">head</span></a>&gt;</span><br />
&nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/title.html"><span class="kw2">title</span></a>&gt;</span>jQuery UI Sortable - Drop placeholder<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/title.html"><span class="kw2">title</span></a>&gt;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; <br />
<br />
&nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/style.html"><span class="kw2">style</span></a> <span class="kw3">type</span><span class="sy0">=</span><span class="st0">&quot;text/css&quot;</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; body{<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; background-color: #111;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; color:white;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; font-family: Arial, &quot;MS Trebuchet&quot;, sans-serif;<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; #sortable { <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; list-style-type: none; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; margin: 0; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; padding: 0; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; width:300px<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; #sortable li { <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; margin: 0 5px 5px 5px; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; padding: 5px 20px; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; font-size: 1.2em; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; height: 1.5em; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; background-color: #678;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cursor:pointer;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; #sortable li.highlight { <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; height: 1.5em; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; line-height: 1.2em;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; background-color: #036;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; background-image: none;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; border:none;<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; <span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/style.html"><span class="kw2">style</span></a>&gt;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/script.html"><span class="kw2">script</span></a> <span class="kw3">src</span><span class="sy0">=</span><span class="st0">&quot;http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js&quot;</span> <span class="kw3">type</span><span class="sy0">=</span><span class="st0">&quot;text/javascript&quot;</span> <span class="kw3">charset</span><span class="sy0">=</span><span class="st0">&quot;utf-8&quot;</span>&gt;&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/script.html"><span class="kw2">script</span></a>&gt;</span><br />
&nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/script.html"><span class="kw2">script</span></a> <span class="kw3">type</span><span class="sy0">=</span><span class="st0">&quot;text/javascript&quot;</span> <span class="kw3">src</span><span class="sy0">=</span><span class="st0">&quot;http://jqueryui.com/latest/ui/ui.core.js&quot;</span>&gt;&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/script.html"><span class="kw2">script</span></a>&gt;</span><br />
&nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/script.html"><span class="kw2">script</span></a> <span class="kw3">type</span><span class="sy0">=</span><span class="st0">&quot;text/javascript&quot;</span> <span class="kw3">src</span><span class="sy0">=</span><span class="st0">&quot;http://jqueryui.com/latest/ui/ui.sortable.js&quot;</span>&gt;&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/script.html"><span class="kw2">script</span></a>&gt;</span><br />
&nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/script.html"><span class="kw2">script</span></a> <span class="kw3">type</span><span class="sy0">=</span><span class="st0">&quot;text/javascript&quot;</span>&gt;</span><br />
&nbsp; &nbsp; $(function() {<br />
&nbsp; &nbsp; &nbsp; &nbsp; $(&quot;#sortable&quot;).sortable({<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; placeholder: 'highlight'<br />
&nbsp; &nbsp; &nbsp; &nbsp; });<br />
&nbsp; &nbsp; &nbsp; &nbsp; $(&quot;#sortable&quot;).disableSelection();<br />
&nbsp; &nbsp; });<br />
&nbsp; &nbsp; <span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/script.html"><span class="kw2">script</span></a>&gt;</span><br />
<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/head.html"><span class="kw2">head</span></a>&gt;</span><br />
<span class="sc2">&lt;<a href="http://december.com/html/4/element/body.html"><span class="kw2">body</span></a>&gt;</span><br />
<br />
<span class="sc2">&lt;<a href="http://december.com/html/4/element/ul.html"><span class="kw2">ul</span></a> <span class="kw3">id</span><span class="sy0">=</span><span class="st0">&quot;sortable&quot;</span>&gt;</span><br />
&nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;</span>Item 1<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;</span><br />
&nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;</span>Item 2<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;</span><br />
&nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;</span>Item 3<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;</span><br />
&nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;</span>Item 4<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;</span><br />
&nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;</span>Item 5<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;</span><br />
&nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;</span>Item 6<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;</span><br />
&nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;</span>Item 7<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;</span><br />
<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/ul.html"><span class="kw2">ul</span></a>&gt;</span><br />
<br />
<br />
<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/body.html"><span class="kw2">body</span></a>&gt;</span><br />
<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/html.html"><span class="kw2">html</span></a>&gt;</span></div></td></tr></tbody></table></div>
<p>&#160;</p>
<h2>What We’re Building</h2>
<p>This time around we’re just going to take the current order of the list and save it to the database for future use.</p>
<div class="resources"><a class="Download" href="http://www.devirtuoso.com/Examples/Drag-Drop/example2.zip" target="_blank">Download</a> <a class="Example" href="http://www.devirtuoso.com/Examples/Drag-Drop/index.php" target="_blank">Example</a></div>
<p><a title="Drag and Drop Example" href="http://www.devirtuoso.com/Examples/Drag-Drop/index.php" target="_blank"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://www.devirtuoso.com/wp-content/uploads/2009/09/image.png" width="394" height="349" /></a> </p>
<p>&#160;</p>
<h2>Reworking the List</h2>
<p>Previously we had a simple HTML un-ordered list.&#160; This time we’re going to make it a little more complicated, with good reason of course.&#160; In order to view the updates we make to the database, we first have to have a list&#160; pulling from the database.&#160; For this we will be using PHP and MySQL.</p>
<p>First we’re going to create a file called db.php.&#160; In this file we’re going to do two things.&#160; First connect to the database, and second select all the items from the database and create a list from them.&#160; I’m not going to go into too much detail with the connection info.&#160; If you want a little refresher, we went into more depth in our <a href="http://www.devirtuoso.com/2009/08/beginners-guide-to-using-ajax-with-jquery-part-2/" target="_blank">Beginners Guide to Using Ajax with jQuery</a> post.</p>
<p>Here is the PHP code for connecting to the database:</p>
<div class="codecolorer-container php " style="overflow:auto;white-space:nowrap;width:580px"><table cellspacing="0" cellpadding="0"><tbody><tr><td class="line-numbers"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br /></div></td><td><div class="php codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="kw2">&lt;?php</span><br />
<br />
<span class="co1">//Connection Info</span><br />
<span class="re0">$username</span><span class="sy0">=</span><span class="st0">&quot;root&quot;</span><span class="sy0">;</span><br />
<span class="re0">$password</span><span class="sy0">=</span><span class="st0">&quot;&quot;</span><span class="sy0">;</span><br />
<span class="re0">$host</span><span class="sy0">=</span><span class="st0">&quot;localhost&quot;</span><span class="sy0">;</span><br />
<span class="re0">$database</span> <span class="sy0">=</span> <span class="st0">&quot;DragDrop&quot;</span><span class="sy0">;</span><br />
<br />
<br />
<span class="co1">//Connect to database</span><br />
<span class="re0">$mysqli</span> <span class="sy0">=</span> &nbsp;<span class="kw2">new</span> mysqli<span class="br0">&#40;</span><span class="re0">$host</span><span class="sy0">,</span> <span class="re0">$username</span><span class="sy0">,</span> <span class="re0">$password</span><span class="sy0">,</span> <span class="re0">$database</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
<br />
<span class="co1">// check connection </span><br />
<span class="kw1">if</span> <span class="br0">&#40;</span>mysqli_connect_errno<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; <a href="http://www.php.net/printf"><span class="kw3">printf</span></a><span class="br0">&#40;</span><span class="st0">&quot;Connect failed: <span class="es6">%s</span><span class="es1">\n</span>&quot;</span><span class="sy0">,</span> mysqli_connect_error<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <a href="http://www.php.net/exit"><span class="kw3">exit</span></a><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
<span class="br0">&#125;</span><br />
<br />
<span class="sy1">?&gt;</span></div></td></tr></tbody></table></div>
<p>&#160;</p>
<p>I guess at this point it might be helpful to see what the database looks like.&#160; We have 3 columns:</p>
<ul>
<li>&#160;<strong>itemID</strong> (unique identifier), </li>
<li><strong>content</strong> (the text inside our list) </li>
<li><strong>Order</strong> (keep track of the order) </li>
</ul>
<p><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="database table" border="0" alt="database table" src="http://www.devirtuoso.com/wp-content/uploads/2009/09/image1.png" width="287" height="210" /></p>
<p>&#160;</p>
<p>&#160;</p>
<p>Now we’ll create a function that selects all the items from the database and outputs an un-ordered list.</p>
<p>Here is the <strong>PHP</strong>:</p>
<div class="codecolorer-container php " style="overflow:auto;white-space:nowrap;width:580px"><table cellspacing="0" cellpadding="0"><tbody><tr><td class="line-numbers"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br /></div></td><td><div class="php codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="co1">//Display a list of all entries</span><br />
<span class="kw2">function</span> displayAll <span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; <a href="http://www.php.net/global"><span class="kw3">global</span></a> <span class="re0">$mysqli</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span class="co1">//Get all Entries</span><br />
&nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span><span class="re0">$result</span> <span class="sy0">=</span> <span class="re0">$mysqli</span><span class="sy0">-&gt;</span><span class="me1">query</span><span class="br0">&#40;</span><span class="st0">&quot;SELECT * FROM `Items` ORDER BY `Order` ASC&quot;</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//start list</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$returnValue</span> <span class="sy0">=</span> <span class="st0">&quot;&lt;ul id='sortable'&gt;&quot;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">while</span> <span class="br0">&#40;</span><span class="re0">$row</span> <span class="sy0">=</span> <span class="re0">$result</span><span class="sy0">-&gt;</span><span class="me1">fetch_array</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//add a new list item each iteration</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$returnValue</span> <span class="sy0">.=</span> <span class="st0">&quot;&lt;li id='item_&quot;</span><span class="sy0">.</span><a href="http://www.php.net/htmlentities"><span class="kw3">htmlentities</span></a><span class="br0">&#40;</span><span class="re0">$row</span><span class="br0">&#91;</span><span class="st_h">'itemID'</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="sy0">.</span><span class="st0">&quot;'&gt;&quot;</span><span class="sy0">.</span><a href="http://www.php.net/htmlentities"><span class="kw3">htmlentities</span></a><span class="br0">&#40;</span><span class="re0">$row</span><span class="br0">&#91;</span><span class="st_h">'content'</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="sy0">.</span><span class="st0">&quot;&lt;/li&gt;&quot;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//close list</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$returnValue</span> <span class="sy0">.=</span> <span class="st0">&quot;&lt;ul&gt;&quot;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//display list</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/echo"><span class="kw3">echo</span></a> <span class="re0">$returnValue</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="coMULTI">/* free result set */</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$result</span><span class="sy0">-&gt;</span><span class="me1">close</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></div></td></tr></tbody></table></div>
<p>&#160;</p>
<p>First we query the database with the mysqli object we created when we connected to the database.&#160; If it returns results without errors then we can go ahead with making our list.&#160; </p>
<p>Making the list isn’t too hard, we’re simply creating a variable that holds our list.&#160; We then cycle through all of the items returned from the database and add it to the end of our variable.&#160; After we have all the info in our variable, we display it for the world to see.&#160; One special note, you’ll see that we are giving each &lt;li&gt; an id.&#160; We’re going to use this when we get to the Ajax portion of the tutorial.&#160; For now just know that the id is required.</p>
<p>&#160;</p>
<p><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="display all function" border="0" alt="display all function" src="http://www.devirtuoso.com/wp-content/uploads/2009/09/image2.png" width="420" height="304" /> </p>
<p>&#160;</p>
<h2>The New HTML</h2>
<p>Now that we have our db.php file ready to go, we can now make use of it in our main file.</p>
<p>First off we’re going to import the file to use it.&#160; At the very top we’ll just put:</p>
<div class="codecolorer-container php " style="overflow:auto;white-space:nowrap;width:580px"><table cellspacing="0" cellpadding="0"><tbody><tr><td class="line-numbers"><div>1<br /></div></td><td><div class="php codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="kw2">&lt;?php</span> <span class="kw1">require</span><span class="br0">&#40;</span><span class="st0">&quot;db.php&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span> <span class="sy1">?&gt;</span></div></td></tr></tbody></table></div>
<p>&#160;</p>
<p>Now we can use the function displayAll() that we just created.&#160; We’ll be replacing the un-ordered list with this function.&#160; When the page is processed, the function will pull the data from the database and output a brand spankin’ new list.&#160; Pretty sweet huh.</p>
<div class="codecolorer-container html4strict " style="overflow:auto;white-space:nowrap;width:580px"><table cellspacing="0" cellpadding="0"><tbody><tr><td class="line-numbers"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br /></div></td><td><div class="html4strict codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="sc2">&lt;<a href="http://december.com/html/4/element/body.html"><span class="kw2">body</span></a>&gt;</span><br />
<span class="sc2">&lt;?php</span><br />
<br />
<span class="sc2"><span class="sy0">//</span>Displays the list.</span><br />
<br />
<span class="sc2">displayAll<span class="br0">&#40;</span><span class="br0">&#41;</span>;</span><br />
<br />
<span class="sc2">?&gt;</span><br />
<br />
<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/body.html"><span class="kw2">body</span></a>&gt;</span></div></td></tr></tbody></table></div>
<p>&#160;</p>
<h2>The jQuery</h2>
<p>The jQuery changed a bit.&#160; We’re adding a new update parameter to the sortable function.&#160; This will be called whenever the order has been changed.</p>
<p>In the update function we’ll be doing 3 things.</p>
<ul>
<li>Prepping the info to be sent via Ajax </li>
<li>Send the info via Ajax </li>
<li>Display the new updated list </li>
</ul>
<p>Here is the <strong>jQuery</strong>:</p>
<div class="codecolorer-container javascript " style="overflow:auto;white-space:nowrap;width:580px"><table cellspacing="0" cellpadding="0"><tbody><tr><td class="line-numbers"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br /></div></td><td><div class="javascript codecolorer" style="font-family:Monaco,Lucida Console,monospace">$<span class="br0">&#40;</span><span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; $<span class="br0">&#40;</span><span class="st0">&quot;#sortable&quot;</span><span class="br0">&#41;</span>.<span class="me1">sortable</span><span class="br0">&#40;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; placeholder<span class="sy0">:</span> <span class="st0">'highlight'</span><span class="sy0">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//NEW----Called when order is changed</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; update<span class="sy0">:</span> <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//Prep the list order for transfer</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> listOrder <span class="sy0">=</span> $<span class="br0">&#40;</span><span class="kw1">this</span><span class="br0">&#41;</span>.<span class="me1">sortable</span><span class="br0">&#40;</span><span class="st0">&quot;serialize&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//send info to our php file.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $.<span class="me1">post</span><span class="br0">&#40;</span><span class="st0">&quot;update.php&quot;</span><span class="sy0">,</span> listOrder<span class="sy0">,</span> <span class="kw2">function</span><span class="br0">&#40;</span>response<span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//update the list with the new list.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $<span class="br0">&#40;</span><span class="st0">&quot;sortable&quot;</span><span class="br0">&#41;</span>.<span class="me1">html</span><span class="br0">&#40;</span>response<span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; $<span class="br0">&#40;</span><span class="st0">&quot;#sortable&quot;</span><span class="br0">&#41;</span>.<span class="me1">disableSelection</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
<span class="br0">&#125;</span><span class="br0">&#41;</span><span class="sy0">;</span></div></td></tr></tbody></table></div>
<p>&#160;</p>
<p><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="serialize order" border="0" alt="serialize order" src="http://www.devirtuoso.com/wp-content/uploads/2009/09/image3.png" width="420" height="305" /> </p>
<p>&#160;</p>
<h4>Prepping the Info</h4>
<p>First thing we tackle is prepping the info by serializing it.&#160; This just means that we’re taking the order of the list and preparing them in a way that they can be attached to a url.(e.g. www.domain.com<strong>?serialized=data</strong> )&#160; For this serialize function to work we have to create ids for our list items in a particular way.&#160; If I want an array called “item”&#160; then I would give my li tags an id of item_1, item_2, item_3, etc. The serialize function will take the text before the underscore as the array name, and the number after as it’s value.&#160; So a list with ids of item_1, item_2 would be serialized to item[]=1&amp;item[]=2 .&#160;&#160; When we created the function displayAll() we took this into consideration, and put the items ID value from the database after the underscore so we can reference it later.</p>
<p>&#160;</p>
<h4>Send Info</h4>
<p>Next comes the Ajax.&#160; We’re going to use the post function.&#160; We simply have to give it a url, any data we want to send to the url and the function we want to call when we receive something back from the url.</p>
<p>&#160;</p>
<h4>Display New List</h4>
<p>The function that handles the response simply just switches out the list’s HTML with the new HTML.</p>
<p>&#160;</p>
<h2>Updating the Database</h2>
<p>The first thing we’re going to do is create a file called update.php.&#160; This is the file that will be called by the Ajax.&#160; In this file a couple of things are going to happen.</p>
<ul>
<li>Get the array sent in by the Ajax </li>
<li>Cycle through each item in the array </li>
<li>Update the database with the new value </li>
<li>Display a new list </li>
</ul>
<p>Here is the <strong>PHP</strong>:</p>
<div class="codecolorer-container php " style="overflow:auto;white-space:nowrap;width:580px"><table cellspacing="0" cellpadding="0"><tbody><tr><td class="line-numbers"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br /></div></td><td><div class="php codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="kw2">&lt;?php</span><br />
<br />
<span class="co1">//Get the Array from Ajax</span><br />
<span class="co1">//Make sure it is an array.</span><br />
<span class="kw1">if</span> <span class="br0">&#40;</span><a href="http://www.php.net/is_array"><span class="kw3">is_array</span></a><span class="br0">&#40;</span><span class="re0">$_POST</span><span class="br0">&#91;</span><span class="st_h">'item'</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="re0">$items</span> <span class="sy0">=</span> <span class="re0">$_POST</span><span class="br0">&#91;</span><span class="st_h">'item'</span><span class="br0">&#93;</span><span class="sy0">;</span> <br />
<span class="br0">&#125;</span><span class="kw1">else</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="re0">$items</span> <span class="sy0">=</span> <span class="st0">&quot;&quot;</span><span class="sy0">;</span><br />
<span class="br0">&#125;</span><br />
<br />
<br />
<br />
<span class="kw1">if</span> <span class="br0">&#40;</span><span class="re0">$items</span> <span class="sy0">!=</span> <span class="st0">&quot;&quot;</span><span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; <br />
<span class="co1">//Connect to database.</span><br />
<span class="kw1">require</span> <span class="st_h">'db.php'</span><span class="sy0">;</span> &nbsp;<br />
<br />
&nbsp; <br />
&nbsp; &nbsp; <span class="co1">//Cycle through Array.</span><br />
&nbsp; &nbsp; <span class="kw1">for</span> <span class="br0">&#40;</span><span class="re0">$i</span><span class="sy0">=</span><span class="nu0">0</span><span class="sy0">;</span> <span class="re0">$i</span> <span class="sy0">&lt;</span> <a href="http://www.php.net/count"><span class="kw3">count</span></a><span class="br0">&#40;</span><span class="re0">$items</span><span class="br0">&#41;</span><span class="sy0">;</span> <span class="re0">$i</span><span class="sy0">++</span><span class="br0">&#41;</span> <span class="br0">&#123;</span> <br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//Make sure the value of the item is numeric.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span><a href="http://www.php.net/is_numeric"><span class="kw3">is_numeric</span></a><span class="br0">&#40;</span><span class="re0">$items</span><span class="br0">&#91;</span><span class="re0">$i</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$id</span> <span class="sy0">=</span> <span class="re0">$items</span><span class="br0">&#91;</span><span class="re0">$i</span><span class="br0">&#93;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><span class="kw1">else</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/die"><span class="kw3">die</span></a><span class="br0">&#40;</span><span class="st0">&quot;Invalid ID&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//Set the database order to match the order of the array.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$query</span> <span class="sy0">=</span> <span class="st0">&quot;UPDATE `Items` SET `Order` = &quot;</span> <span class="sy0">.</span> <span class="re0">$i</span> <span class="sy0">.</span> <span class="st0">&quot; WHERE `itemID` = &quot;</span> <span class="sy0">.</span> <span class="re0">$items</span><span class="br0">&#91;</span><span class="re0">$i</span><span class="br0">&#93;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$mysqli</span><span class="sy0">-&gt;</span><span class="me1">query</span><span class="br0">&#40;</span><span class="re0">$query</span><span class="br0">&#41;</span> or <a href="http://www.php.net/die"><span class="kw3">die</span></a><span class="br0">&#40;</span><span class="st_h">'Error, insert query failed'</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span class="coMULTI">/* Display a new list */</span><br />
&nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span><span class="re0">$result</span> <span class="sy0">=</span> <span class="re0">$mysqli</span><span class="sy0">-&gt;</span><span class="me1">query</span><span class="br0">&#40;</span><span class="st0">&quot;SELECT * FROM `Items` ORDER BY `Order` ASC&quot;</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$returnValue</span> <span class="sy0">=</span> <span class="st0">&quot;&quot;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">while</span> <span class="br0">&#40;</span><span class="re0">$row</span> <span class="sy0">=</span> <span class="re0">$result</span><span class="sy0">-&gt;</span><span class="me1">fetch_array</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$returnValue</span> <span class="sy0">.=</span> <span class="st0">&quot;&lt;li id='item_&quot;</span><span class="sy0">.</span><a href="http://www.php.net/htmlentities"><span class="kw3">htmlentities</span></a><span class="br0">&#40;</span><span class="re0">$row</span><span class="br0">&#91;</span><span class="st_h">'itemID'</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="sy0">.</span><span class="st0">&quot;'&gt;&quot;</span><span class="sy0">.</span><a href="http://www.php.net/htmlentities"><span class="kw3">htmlentities</span></a><span class="br0">&#40;</span><span class="re0">$row</span><span class="br0">&#91;</span><span class="st_h">'content'</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="sy0">.</span><span class="st0">&quot;&lt;/li&gt;&quot;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/echo"><span class="kw3">echo</span></a> <span class="re0">$returnValue</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="coMULTI">/* free result set */</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$result</span><span class="sy0">-&gt;</span><span class="me1">close</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; <br />
<span class="br0">&#125;</span><br />
<br />
<br />
<span class="sy1">?&gt;</span></div></td></tr></tbody></table></div>
<p>&#160;</p>
<h4>Get the Array from Ajax</h4>
<p>Since we used the post method in our jQuery, PHP’s $_POST variable will be populated by what we pasted in.&#160; In our case it was the item array. It’s always good practice to make sure you’ll be receiving what you’re expecting.&#160; In this case we’re expecting an array, so we check and make sure it is an array.</p>
<h4>&#160;</h4>
<h4>Cycle through the Array</h4>
<p>After we’re sure we have an array on our hands, we cycle through each element in the array.&#160; For each element we’re going to check and make sure the value is a number.&#160; If we didn’t malicious users could pass in some harmful stuff.</p>
<h4>&#160;</h4>
<h4>Update the Database</h4>
<p>After we have verified that array’s value is a number, we then pass it into our SQL statement.&#160; The array is ordered in the same manner as the list was.&#160; So the first item in the array is also the first item in the list.&#160; The SQL will&#160; then set the Order of the item to where it is in the array.</p>
<h4>&#160;</h4>
<h4>Display a New List</h4>
<p>The code for this is pretty well the same as displayAll().&#160; The only difference is that we’re leaving the &lt;ul&gt;&lt;/ul&gt; off, as these will already be in place, and we’re just replacing the innards.</p>
<p>&#160;</p>
<h2>That’s IT</h2>
<p>That’s pretty well it.&#160; Now we have our initial code that display’s our list.&#160; Then our jQuery that passes on the order of the list via AJAX.&#160; Then our update PHP file that checks to make sure the values are good, and passes them to the database.&#160; After all that it passes the new list back to the jQuery to display.&#160; Voila!</p>
<p>db.php : </p>
<div class="codecolorer-container php " style="overflow:auto;white-space:nowrap;width:580px"><table cellspacing="0" cellpadding="0"><tbody><tr><td class="line-numbers"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br /></div></td><td><div class="php codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="kw2">&lt;?php</span><br />
<span class="co1">//Connection Info</span><br />
<span class="re0">$username</span><span class="sy0">=</span><span class="st0">&quot;root&quot;</span><span class="sy0">;</span><br />
<span class="re0">$password</span><span class="sy0">=</span><span class="st0">&quot;&quot;</span><span class="sy0">;</span><br />
<span class="re0">$host</span><span class="sy0">=</span><span class="st0">&quot;localhost&quot;</span><span class="sy0">;</span><br />
<span class="re0">$database</span> <span class="sy0">=</span> <span class="st0">&quot;DragDrop&quot;</span><span class="sy0">;</span><br />
<br />
<br />
<span class="co1">//Connect to database</span><br />
<span class="re0">$mysqli</span> <span class="sy0">=</span> &nbsp;<span class="kw2">new</span> mysqli<span class="br0">&#40;</span><span class="re0">$host</span><span class="sy0">,</span> <span class="re0">$username</span><span class="sy0">,</span> <span class="re0">$password</span><span class="sy0">,</span> <span class="re0">$database</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
<br />
<span class="co1">// check connection </span><br />
<span class="kw1">if</span> <span class="br0">&#40;</span>mysqli_connect_errno<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; <a href="http://www.php.net/printf"><span class="kw3">printf</span></a><span class="br0">&#40;</span><span class="st0">&quot;Connect failed: <span class="es6">%s</span><span class="es1">\n</span>&quot;</span><span class="sy0">,</span> mysqli_connect_error<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <a href="http://www.php.net/exit"><span class="kw3">exit</span></a><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
<span class="br0">&#125;</span><br />
<br />
<span class="co1">//Display a list of all entries</span><br />
<span class="kw2">function</span> displayAll <span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; <a href="http://www.php.net/global"><span class="kw3">global</span></a> <span class="re0">$mysqli</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span class="co1">//Get all Entries</span><br />
&nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span><span class="re0">$result</span> <span class="sy0">=</span> <span class="re0">$mysqli</span><span class="sy0">-&gt;</span><span class="me1">query</span><span class="br0">&#40;</span><span class="st0">&quot;SELECT * FROM `Items` ORDER BY `Order` ASC&quot;</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//start list</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$returnValue</span> <span class="sy0">=</span> <span class="st0">&quot;&lt;ul id='sortable'&gt;&quot;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">while</span> <span class="br0">&#40;</span><span class="re0">$row</span> <span class="sy0">=</span> <span class="re0">$result</span><span class="sy0">-&gt;</span><span class="me1">fetch_array</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//add a new list item each iteration</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$returnValue</span> <span class="sy0">.=</span> <span class="st0">&quot;&lt;li id='item_&quot;</span><span class="sy0">.</span><a href="http://www.php.net/htmlentities"><span class="kw3">htmlentities</span></a><span class="br0">&#40;</span><span class="re0">$row</span><span class="br0">&#91;</span><span class="st_h">'itemID'</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="sy0">.</span><span class="st0">&quot;'&gt;&quot;</span><span class="sy0">.</span><a href="http://www.php.net/htmlentities"><span class="kw3">htmlentities</span></a><span class="br0">&#40;</span><span class="re0">$row</span><span class="br0">&#91;</span><span class="st_h">'content'</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="sy0">.</span><span class="st0">&quot;&lt;/li&gt;&quot;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//close list</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$returnValue</span> <span class="sy0">.=</span> <span class="st0">&quot;&lt;ul&gt;&quot;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//display list</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/echo"><span class="kw3">echo</span></a> <span class="re0">$returnValue</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="coMULTI">/* free result set */</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$result</span><span class="sy0">-&gt;</span><span class="me1">close</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span><br />
<br />
<span class="sy1">?&gt;</span></div></td></tr></tbody></table></div>
<p>&#160;</p>
<p>Here is the <strong>HTML / jQuery / PHP</strong>:</p>
<div class="codecolorer-container html4strict " style="overflow:auto;white-space:nowrap;width:580px"><table cellspacing="0" cellpadding="0"><tbody><tr><td class="line-numbers"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br /></div></td><td><div class="html4strict codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="sc2">&lt;?php require<span class="br0">&#40;</span><span class="st0">&quot;db.php&quot;</span><span class="br0">&#41;</span>; ?&gt;</span><br />
<br />
<span class="sc0">&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot;</span><br />
<span class="sc0">&nbsp; &nbsp; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;</span><br />
<br />
<span class="sc2">&lt;<a href="http://december.com/html/4/element/html.html"><span class="kw2">html</span></a> <span class="kw3">lang</span><span class="sy0">=</span><span class="st0">&quot;en&quot;</span>&gt;</span><br />
<span class="sc2">&lt;<a href="http://december.com/html/4/element/head.html"><span class="kw2">head</span></a>&gt;</span><br />
&nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/title.html"><span class="kw2">title</span></a>&gt;</span>jQuery UI Sortable - Drop placeholder<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/title.html"><span class="kw2">title</span></a>&gt;</span><br />
<br />
&nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/style.html"><span class="kw2">style</span></a> <span class="kw3">type</span><span class="sy0">=</span><span class="st0">&quot;text/css&quot;</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; body{<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; background-color: #111;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; color:white;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; font-family: Arial, &quot;MS Trebuchet&quot;, sans-serif;<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; #sortable { <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; list-style-type: none; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; margin: 0; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; padding: 0; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; width:300px<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; #sortable li { <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; margin: 0 5px 5px 5px; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; padding: 5px 20px; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; font-size: 1.2em; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; height: 1.5em; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; background-color: #678;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cursor:pointer;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; #sortable li.highlight { <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; height: 1.5em; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; line-height: 1.2em;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; background-color: #036;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; background-image: none;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; border:none;<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; <span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/style.html"><span class="kw2">style</span></a>&gt;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/script.html"><span class="kw2">script</span></a> <span class="kw3">src</span><span class="sy0">=</span><span class="st0">&quot;http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js&quot;</span> <span class="kw3">type</span><span class="sy0">=</span><span class="st0">&quot;text/javascript&quot;</span> <span class="kw3">charset</span><span class="sy0">=</span><span class="st0">&quot;utf-8&quot;</span>&gt;&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/script.html"><span class="kw2">script</span></a>&gt;</span><br />
&nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/script.html"><span class="kw2">script</span></a> <span class="kw3">type</span><span class="sy0">=</span><span class="st0">&quot;text/javascript&quot;</span> <span class="kw3">src</span><span class="sy0">=</span><span class="st0">&quot;http://jqueryui.com/latest/ui/ui.core.js&quot;</span>&gt;&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/script.html"><span class="kw2">script</span></a>&gt;</span><br />
&nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/script.html"><span class="kw2">script</span></a> <span class="kw3">type</span><span class="sy0">=</span><span class="st0">&quot;text/javascript&quot;</span> <span class="kw3">src</span><span class="sy0">=</span><span class="st0">&quot;http://jqueryui.com/latest/ui/ui.sortable.js&quot;</span>&gt;&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/script.html"><span class="kw2">script</span></a>&gt;</span><br />
&nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/script.html"><span class="kw2">script</span></a> <span class="kw3">type</span><span class="sy0">=</span><span class="st0">&quot;text/javascript&quot;</span>&gt;</span><br />
&nbsp; &nbsp; $(function() {<br />
&nbsp; &nbsp; &nbsp; &nbsp; $(&quot;#sortable&quot;).sortable({<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; placeholder: 'highlight',<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //NEW----Called when order is changed<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; update: function() {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //Prep the list order for transfer<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var listOrder = $(this).sortable(&quot;serialize&quot;);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //send info to our php file.<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $.post(&quot;update.php&quot;, listOrder, function(response){<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //update the list with the new list.<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $(&quot;sortable&quot;).html(response);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; });<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; });<br />
&nbsp; &nbsp; &nbsp; &nbsp; $(&quot;#sortable&quot;).disableSelection();<br />
&nbsp; &nbsp; });<br />
&nbsp; &nbsp; <span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/script.html"><span class="kw2">script</span></a>&gt;</span><br />
<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/head.html"><span class="kw2">head</span></a>&gt;</span><br />
<span class="sc2">&lt;<a href="http://december.com/html/4/element/body.html"><span class="kw2">body</span></a>&gt;</span><br />
<span class="sc2">&lt;?php</span><br />
<br />
<span class="sc2"><span class="sy0">//</span>Displays the list.</span><br />
<br />
<span class="sc2">displayAll<span class="br0">&#40;</span><span class="br0">&#41;</span>;</span><br />
<br />
<span class="sc2">?&gt;</span><br />
<br />
<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/body.html"><span class="kw2">body</span></a>&gt;</span><br />
<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/html.html"><span class="kw2">html</span></a>&gt;</span></div></td></tr></tbody></table></div>
<p>&#160;</p>
<p>update.php</p>
<div class="codecolorer-container php " style="overflow:auto;white-space:nowrap;width:580px"><table cellspacing="0" cellpadding="0"><tbody><tr><td class="line-numbers"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br /></div></td><td><div class="php codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="kw2">&lt;?php</span><br />
<br />
<span class="co1">//Get the Array from Ajax</span><br />
<span class="co1">//Make sure it is an array.</span><br />
<span class="kw1">if</span> <span class="br0">&#40;</span><a href="http://www.php.net/is_array"><span class="kw3">is_array</span></a><span class="br0">&#40;</span><span class="re0">$_POST</span><span class="br0">&#91;</span><span class="st_h">'item'</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="re0">$items</span> <span class="sy0">=</span> <span class="re0">$_POST</span><span class="br0">&#91;</span><span class="st_h">'item'</span><span class="br0">&#93;</span><span class="sy0">;</span> <br />
<span class="br0">&#125;</span><span class="kw1">else</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="re0">$items</span> <span class="sy0">=</span> <span class="st0">&quot;&quot;</span><span class="sy0">;</span><br />
<span class="br0">&#125;</span><br />
<br />
<br />
<br />
<span class="kw1">if</span> <span class="br0">&#40;</span><span class="re0">$items</span> <span class="sy0">!=</span> <span class="st0">&quot;&quot;</span><span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; <br />
<span class="co1">//Connect to database.</span><br />
<span class="kw1">require</span> <span class="st_h">'db.php'</span><span class="sy0">;</span> &nbsp;<br />
<br />
&nbsp; <br />
&nbsp; &nbsp; <span class="co1">//Cycle through Array.</span><br />
&nbsp; &nbsp; <span class="kw1">for</span> <span class="br0">&#40;</span><span class="re0">$i</span><span class="sy0">=</span><span class="nu0">0</span><span class="sy0">;</span> <span class="re0">$i</span> <span class="sy0">&lt;</span> <a href="http://www.php.net/count"><span class="kw3">count</span></a><span class="br0">&#40;</span><span class="re0">$items</span><span class="br0">&#41;</span><span class="sy0">;</span> <span class="re0">$i</span><span class="sy0">++</span><span class="br0">&#41;</span> <span class="br0">&#123;</span> <br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//Make sure the value of the item is numeric.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span><a href="http://www.php.net/is_numeric"><span class="kw3">is_numeric</span></a><span class="br0">&#40;</span><span class="re0">$items</span><span class="br0">&#91;</span><span class="re0">$i</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$id</span> <span class="sy0">=</span> <span class="re0">$items</span><span class="br0">&#91;</span><span class="re0">$i</span><span class="br0">&#93;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><span class="kw1">else</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/die"><span class="kw3">die</span></a><span class="br0">&#40;</span><span class="st0">&quot;Invalid ID&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//Set the database order to match the order of the array.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$query</span> <span class="sy0">=</span> <span class="st0">&quot;UPDATE `Items` SET `Order` = &quot;</span> <span class="sy0">.</span> <span class="re0">$i</span> <span class="sy0">.</span> <span class="st0">&quot; WHERE `itemID` = &quot;</span> <span class="sy0">.</span> <span class="re0">$items</span><span class="br0">&#91;</span><span class="re0">$i</span><span class="br0">&#93;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$mysqli</span><span class="sy0">-&gt;</span><span class="me1">query</span><span class="br0">&#40;</span><span class="re0">$query</span><span class="br0">&#41;</span> or <a href="http://www.php.net/die"><span class="kw3">die</span></a><span class="br0">&#40;</span><span class="st_h">'Error, insert query failed'</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span class="coMULTI">/* Display a new list */</span><br />
&nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span><span class="re0">$result</span> <span class="sy0">=</span> <span class="re0">$mysqli</span><span class="sy0">-&gt;</span><span class="me1">query</span><span class="br0">&#40;</span><span class="st0">&quot;SELECT * FROM `Items` ORDER BY `Order` ASC&quot;</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$returnValue</span> <span class="sy0">=</span> <span class="st0">&quot;&quot;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">while</span> <span class="br0">&#40;</span><span class="re0">$row</span> <span class="sy0">=</span> <span class="re0">$result</span><span class="sy0">-&gt;</span><span class="me1">fetch_array</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$returnValue</span> <span class="sy0">.=</span> <span class="st0">&quot;&lt;li id='item_&quot;</span><span class="sy0">.</span><a href="http://www.php.net/htmlentities"><span class="kw3">htmlentities</span></a><span class="br0">&#40;</span><span class="re0">$row</span><span class="br0">&#91;</span><span class="st_h">'itemID'</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="sy0">.</span><span class="st0">&quot;'&gt;&quot;</span><span class="sy0">.</span><a href="http://www.php.net/htmlentities"><span class="kw3">htmlentities</span></a><span class="br0">&#40;</span><span class="re0">$row</span><span class="br0">&#91;</span><span class="st_h">'content'</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="sy0">.</span><span class="st0">&quot;&lt;/li&gt;&quot;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/echo"><span class="kw3">echo</span></a> <span class="re0">$returnValue</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="coMULTI">/* free result set */</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$result</span><span class="sy0">-&gt;</span><span class="me1">close</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; <br />
<span class="br0">&#125;</span><br />
<br />
<br />
<span class="sy1">?&gt;</span></div></td></tr></tbody></table></div>
<p>&#160;</p>
<div class="resources"><a class="Download" href="http://www.devirtuoso.com/Examples/Drag-Drop/example2.zip" target="_blank">Download</a> <a class="Example" href="http://www.devirtuoso.com/Examples/Drag-Drop/index.php" target="_blank">Example</a></div>
]]></content:encoded>
			<wfw:commentRss>http://www.devirtuoso.com/2009/09/beginners-guide-to-jquery-sorting-part-2/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Beginners Guide to jQuery Sorting</title>
		<link>http://www.devirtuoso.com/2009/09/beginners-guide-to-jquery-sorting/</link>
		<comments>http://www.devirtuoso.com/2009/09/beginners-guide-to-jquery-sorting/#comments</comments>
		<pubDate>Tue, 01 Sep 2009 23:05:42 +0000</pubDate>
		<dc:creator>Shawn</dc:creator>
				<category><![CDATA[Front End Development]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[How to]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[JQuery]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[web development]]></category>

		<guid isPermaLink="false">http://www.devirtuoso.com/?p=1029</guid>
		<description><![CDATA[Beginners might often steer away from trying to reorder lists by dragging and dropping.&#160; The thought of doing something like that sounds daunting.&#160; Luckily jQuery has made it relatively simple. Here is a tutorial on how to make a list sortable.

What We’re Building
Quite simply, we’re trying to give the user the ability to sort a [...]]]></description>
			<content:encoded><![CDATA[<p>Beginners might often steer away from trying to reorder lists by dragging and dropping.&#160; The thought of doing something like that sounds daunting.&#160; Luckily jQuery has made it relatively simple. Here is a tutorial on how to make a list sortable.</p>
<p><span id="more-1029"></span></p>
<h2>What We’re Building</h2>
<p>Quite simply, we’re trying to give the user the ability to sort a list by dragging and dropping items into place.&#160; We’re also going to give a nice place holder to help guide the user.</p>
<div class="resources"> <a href="http://www.devirtuoso.com/Examples/Drag-Drop/example.zip"class="Download" target="_blank">Download</a>  <a href="http://www.devirtuoso.com/Examples/Drag-Drop/"class="Example" target="_blank">Example</a></div>
<p><a title="Drag and Drop Example" href="http://www.devirtuoso.com/Examples/Drag-Drop" target="_blank"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://www.devirtuoso.com/wp-content/uploads/2009/09/image.png" width="394" height="349" /></a> </p>
<p>&#160;</p>
<h2>Building the HTML</h2>
<p>Fortunately the HTML is pretty simple.&#160; All you will need is a simple un-ordered list, with some items in it. </p>
<p><strong>HTML</strong>:</p>
<div class="codecolorer-container html4strict " style="overflow:auto;white-space:nowrap;width:580px"><table cellspacing="0" cellpadding="0"><tbody><tr><td class="line-numbers"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br /></div></td><td><div class="html4strict codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="sc2">&lt;<a href="http://december.com/html/4/element/ul.html"><span class="kw2">ul</span></a> <span class="kw3">id</span><span class="sy0">=</span><span class="st0">&quot;sortable&quot;</span>&gt;</span><br />
&nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;</span>Item 1<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;</span><br />
&nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;</span>Item 2<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;</span><br />
&nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;</span>Item 3<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;</span><br />
&nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;</span>Item 4<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;</span><br />
&nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;</span>Item 5<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;</span><br />
&nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;</span>Item 6<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;</span><br />
&nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;</span>Item 7<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;</span><br />
<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/ul.html"><span class="kw2">ul</span></a>&gt;</span></div></td></tr></tbody></table></div>
<p>&#160;</p>
<h2>The CSS</h2>
<p>The CSS is solely for appearances.&#160; You don’t have to use what I used here, feel free to experiment with different styles.&#160; The only class that needs any sort of explanation is the highlight class.&#160; This class is for the placeholder for when the user starts dragging. So more than likely you’ll want to make this subdue, it’s just suppose to be a hint of where to drag the box.</p>
<p><strong>CSS</strong>: </p>
<div class="codecolorer-container css " style="overflow:auto;white-space:nowrap;width:580px"><table cellspacing="0" cellpadding="0"><tbody><tr><td class="line-numbers"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br /></div></td><td><div class="css codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="coMULTI">/*Styling the body*/</span><br />
body<span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw1">background-color</span><span class="sy0">:</span> <span class="re0">#111</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="kw1">color</span><span class="sy0">:</span><span class="kw2">white</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="kw1">font-family</span><span class="sy0">:</span> Arial<span class="sy0">,</span> <span class="st0">&quot;MS Trebuchet&quot;</span><span class="sy0">,</span> <span class="kw2">sans-serif</span><span class="sy0">;</span><br />
<span class="br0">&#125;</span><br />
<br />
<span class="coMULTI">/* Get rid of bullets and list indent,<br />
&nbsp; &nbsp;also adjust the width to what we want*/</span><br />
<span class="re0">#sortable</span> <span class="br0">&#123;</span> <br />
&nbsp; &nbsp; <span class="kw1">list-style-type</span><span class="sy0">:</span> <span class="kw2">none</span><span class="sy0">;</span> <br />
&nbsp; &nbsp; <span class="kw1">margin</span><span class="sy0">:</span> <span class="nu0">0</span><span class="sy0">;</span> <br />
&nbsp; &nbsp; <span class="kw1">padding</span><span class="sy0">:</span> <span class="nu0">0</span><span class="sy0">;</span> <br />
&nbsp; &nbsp; <span class="kw1">width</span><span class="sy0">:</span><span class="re3">300px</span><br />
&nbsp; &nbsp; <br />
<span class="br0">&#125;</span><br />
<br />
<span class="coMULTI">/* Styling each of the list elements*/</span><br />
<span class="re0">#sortable</span> li <span class="br0">&#123;</span> <br />
&nbsp; &nbsp; <span class="kw1">margin</span><span class="sy0">:</span> <span class="nu0">0</span> <span class="re3">5px</span> <span class="re3">5px</span> <span class="re3">5px</span><span class="sy0">;</span> <br />
&nbsp; &nbsp; <span class="kw1">padding</span><span class="sy0">:</span> <span class="re3">5px</span> <span class="re3">20px</span><span class="sy0">;</span> <br />
&nbsp; &nbsp; <span class="kw1">font-size</span><span class="sy0">:</span> <span class="re3">1.2em</span><span class="sy0">;</span> <br />
&nbsp; &nbsp; <span class="kw1">height</span><span class="sy0">:</span> <span class="re3">1.5em</span><span class="sy0">;</span> <br />
&nbsp; &nbsp; <span class="kw1">background-color</span><span class="sy0">:</span> <span class="re0">#678</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="kw1">cursor</span><span class="sy0">:</span><span class="kw2">pointer</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <br />
<span class="br0">&#125;</span><br />
<br />
<span class="coMULTI">/* Styling the placeholder for when<br />
&nbsp; &nbsp;the user starts dragging an item */</span><br />
<span class="re0">#sortable</span> li<span class="re1">.highlight</span> <span class="br0">&#123;</span> <br />
&nbsp; &nbsp; <span class="kw1">height</span><span class="sy0">:</span> <span class="re3">1.5em</span><span class="sy0">;</span> <br />
&nbsp; &nbsp; <span class="kw1">line-height</span><span class="sy0">:</span> <span class="re3">1.2em</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="kw1">background-color</span><span class="sy0">:</span> <span class="re0">#036</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="kw1">background-image</span><span class="sy0">:</span> <span class="kw2">none</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="kw1">border</span><span class="sy0">:</span><span class="kw2">none</span><span class="sy0">;</span><br />
<span class="br0">&#125;</span></div></td></tr></tbody></table></div>
<p>&#160;</p>
<p>&#160;</p>
<h2>The jQuery</h2>
<p>We’ll be using a library from the jQuery UI.&#160; This does all the complicated code so you don’t have to.&#160; You’re going to have to import 3 files</p>
<ol>
<li>jQuery : <a title="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" href="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" target="_blank">http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js</a></li>
<li>jQuery UI Core file : <a target="_blank" title="http://jqueryui.com/latest/ui/ui.core.js" href="http://jqueryui.com/latest/ui/ui.core.js">http://jqueryui.com/latest/ui/ui.core.js</a></li>
<li>jQuery UI Sortable file : <a target="_blank" title="http://jqueryui.com/latest/ui/ui.sortable.js" href="http://jqueryui.com/latest/ui/ui.sortable.js">http://jqueryui.com/latest/ui/ui.sortable.js</a></li>
</ol>
<p>Once we have these imported then we’re good to go.&#160; The jQuery that we’ll have to write isn’t overly complicated.</p>
<p><strong>jQuery</strong>:</p>
<div class="codecolorer-container javascript " style="overflow:auto;white-space:nowrap;width:580px"><table cellspacing="0" cellpadding="0"><tbody><tr><td class="line-numbers"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br /></div></td><td><div class="javascript codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="co1">//When everything is loaded...</span><br />
$<span class="br0">&#40;</span>document<span class="br0">&#41;</span>.<span class="me1">ready</span><span class="br0">&#40;</span><span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span class="co1">//makes the list with the id &quot;sortable&quot; sortable.</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span class="co1">//the placehoder option is not necessary.</span><br />
&nbsp; &nbsp; <span class="co1">//the highlight is the CSS class applied</span><br />
&nbsp; &nbsp; <span class="co1">//to the placeholder.</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; $<span class="br0">&#40;</span><span class="st0">&quot;#sortable&quot;</span><span class="br0">&#41;</span>.<span class="me1">sortable</span><span class="br0">&#40;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; placeholder<span class="sy0">:</span> <span class="st0">'highlight'</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span class="co1">//prevents the list from being selectable.&nbsp; </span><br />
&nbsp; &nbsp; $<span class="br0">&#40;</span><span class="st0">&quot;#sortable&quot;</span><span class="br0">&#41;</span>.<span class="me1">disableSelection</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
<span class="br0">&#125;</span><span class="br0">&#41;</span><span class="sy0">;</span></div></td></tr></tbody></table></div>
<p>&#160;</p>
<p>&#160;</p>
<h2>Conclusion</h2>
<p>Now that you realize how easy it is to create a sortable list, use and abuse it.&#160; Keep an eye out for part two of this tutorial where I will show how to interact with the database via AJAX.</p>
<p>Here is the code all together:</p>
<div class="codecolorer-container html4strict " style="overflow:auto;white-space:nowrap;width:580px"><table cellspacing="0" cellpadding="0"><tbody><tr><td class="line-numbers"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br /></div></td><td><div class="html4strict codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="sc0">&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot;</span><br />
<span class="sc0">&nbsp; &nbsp; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;</span><br />
<br />
<span class="sc2">&lt;<a href="http://december.com/html/4/element/html.html"><span class="kw2">html</span></a> <span class="kw3">lang</span><span class="sy0">=</span><span class="st0">&quot;en&quot;</span>&gt;</span><br />
<span class="sc2">&lt;<a href="http://december.com/html/4/element/head.html"><span class="kw2">head</span></a>&gt;</span><br />
&nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/title.html"><span class="kw2">title</span></a>&gt;</span>jQuery UI Sortable - Drop placeholder<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/title.html"><span class="kw2">title</span></a>&gt;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; <br />
<br />
&nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/style.html"><span class="kw2">style</span></a> <span class="kw3">type</span><span class="sy0">=</span><span class="st0">&quot;text/css&quot;</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; body{<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; background-color: #111;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; color:white;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; font-family: Arial, &quot;MS Trebuchet&quot;, sans-serif;<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; #sortable { <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; list-style-type: none; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; margin: 0; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; padding: 0; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; width:300px<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; #sortable li { <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; margin: 0 5px 5px 5px; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; padding: 5px 20px; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; font-size: 1.2em; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; height: 1.5em; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; background-color: #678;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cursor:pointer;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; #sortable li.highlight { <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; height: 1.5em; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; line-height: 1.2em;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; background-color: #036;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; background-image: none;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; border:none;<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; <span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/style.html"><span class="kw2">style</span></a>&gt;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/script.html"><span class="kw2">script</span></a> <span class="kw3">src</span><span class="sy0">=</span><span class="st0">&quot;http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js&quot;</span> <span class="kw3">type</span><span class="sy0">=</span><span class="st0">&quot;text/javascript&quot;</span> <span class="kw3">charset</span><span class="sy0">=</span><span class="st0">&quot;utf-8&quot;</span>&gt;&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/script.html"><span class="kw2">script</span></a>&gt;</span><br />
&nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/script.html"><span class="kw2">script</span></a> <span class="kw3">type</span><span class="sy0">=</span><span class="st0">&quot;text/javascript&quot;</span> <span class="kw3">src</span><span class="sy0">=</span><span class="st0">&quot;http://jqueryui.com/latest/ui/ui.core.js&quot;</span>&gt;&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/script.html"><span class="kw2">script</span></a>&gt;</span><br />
&nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/script.html"><span class="kw2">script</span></a> <span class="kw3">type</span><span class="sy0">=</span><span class="st0">&quot;text/javascript&quot;</span> <span class="kw3">src</span><span class="sy0">=</span><span class="st0">&quot;http://jqueryui.com/latest/ui/ui.sortable.js&quot;</span>&gt;&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/script.html"><span class="kw2">script</span></a>&gt;</span><br />
&nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/script.html"><span class="kw2">script</span></a> <span class="kw3">type</span><span class="sy0">=</span><span class="st0">&quot;text/javascript&quot;</span>&gt;</span><br />
&nbsp; &nbsp; $(function() {<br />
&nbsp; &nbsp; &nbsp; &nbsp; $(&quot;#sortable&quot;).sortable({<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; placeholder: 'highlight'<br />
&nbsp; &nbsp; &nbsp; &nbsp; });<br />
&nbsp; &nbsp; &nbsp; &nbsp; $(&quot;#sortable&quot;).disableSelection();<br />
&nbsp; &nbsp; });<br />
&nbsp; &nbsp; <span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/script.html"><span class="kw2">script</span></a>&gt;</span><br />
<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/head.html"><span class="kw2">head</span></a>&gt;</span><br />
<span class="sc2">&lt;<a href="http://december.com/html/4/element/body.html"><span class="kw2">body</span></a>&gt;</span><br />
<br />
<span class="sc2">&lt;<a href="http://december.com/html/4/element/ul.html"><span class="kw2">ul</span></a> <span class="kw3">id</span><span class="sy0">=</span><span class="st0">&quot;sortable&quot;</span>&gt;</span><br />
&nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;</span>Item 1<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;</span><br />
&nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;</span>Item 2<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;</span><br />
&nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;</span>Item 3<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;</span><br />
&nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;</span>Item 4<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;</span><br />
&nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;</span>Item 5<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;</span><br />
&nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;</span>Item 6<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;</span><br />
&nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;</span>Item 7<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;</span><br />
<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/ul.html"><span class="kw2">ul</span></a>&gt;</span><br />
<br />
<br />
<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/body.html"><span class="kw2">body</span></a>&gt;</span><br />
<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/html.html"><span class="kw2">html</span></a>&gt;</span></div></td></tr></tbody></table></div>
<p>&#160;</p>
<div class="resources"> <a href="http://www.devirtuoso.com/Examples/Drag-Drop/example.zip"class="Download" target="_blank">Download</a>  <a href="http://www.devirtuoso.com/Examples/Drag-Drop/"class="Example" target="_blank">Example</a></div>
<p>&#160;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.devirtuoso.com/2009/09/beginners-guide-to-jquery-sorting/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Speeding Up Page Loading for JavaScript Heavy Sites</title>
		<link>http://www.devirtuoso.com/2009/08/speeding-up-page-loading-for-javascript-heavy-sites/</link>
		<comments>http://www.devirtuoso.com/2009/08/speeding-up-page-loading-for-javascript-heavy-sites/#comments</comments>
		<pubDate>Wed, 26 Aug 2009 18:37:51 +0000</pubDate>
		<dc:creator>Shawn</dc:creator>
				<category><![CDATA[Development Best Practices]]></category>
		<category><![CDATA[Front End Development]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[best practices]]></category>
		<category><![CDATA[speed]]></category>
		<category><![CDATA[web development]]></category>

		<guid isPermaLink="false">http://www.devirtuoso.com/?p=972</guid>
		<description><![CDATA[JavaScript libraries help enhance our websites.&#160; Unfortunately they also slow down the page loading process. Here is a little tip to help speed up your page loads, while keeping those fantastic libraries you love so much.

Positioning
 
The problem with loading JavaScript files is when they’re being downloaded the browser doesn&#8217;t download anything else.&#160; So JavaScript [...]]]></description>
			<content:encoded><![CDATA[<p>JavaScript libraries help enhance our websites.&#160; Unfortunately they also slow down the page loading process. Here is a little tip to help speed up your page loads, while keeping those fantastic libraries you love so much.</p>
<p><span id="more-972"></span></p>
<h2>Positioning</h2>
<p><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="images can&#39;t load until javascript is done" border="0" alt="images can&#39;t load until javascript is done" src="http://www.devirtuoso.com/wp-content/uploads/2009/08/image35.png" width="420" height="217" /> </p>
<p>The problem with loading JavaScript files is when they’re being downloaded the browser doesn&#8217;t download anything else.&#160; So JavaScript affectively blocks your browsers from downloading other assets like CSS, or images. Giving the illusion that your page takes longer to load simply because the users notice the CSS and images not being loaded.&#160; A simple trick is to place all of your JavaScript just before the end body tag.&#160; This way it insures everything else has already started loading before it hits your JavaScript.&#160; Really you’re not speeding up anything, just re-arranging how things load.</p>
<p><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="load javascript later" border="0" alt="load javascript later" src="http://www.devirtuoso.com/wp-content/uploads/2009/08/image36.png" width="420" height="215" /> </p>
<p>&#160;</p>
<h2>Load it When You Need it</h2>
<p>JavaScript should only be used as an enhancement. Your website should work perfectly fine when JavaScript is shut off.&#160; If it doesn’t you should consider looking into <a title="Progressive Enhancement" href="http://www.devirtuoso.com/2009/05/front-end-development-the-easier-way/" target="_blank">Progressive Enhancement</a>. It’s a method that make sure your HTML is laid out first, then you add the bells and whistles.&#160; That aside, because JavaScript shouldn’t be completely necessary, you should be able to load the script as you need them…not on page load.&#160; This will speed up your initial page load, and get people into your site quicker.&#160; </p>
<p><img style="border-bottom: 0px; border-left: 0px; display: inline; margin-left: 0px; border-top: 0px; margin-right: 0px; border-right: 0px" title="loading javascript as needed" border="0" alt="loading javascript as needed" src="http://www.devirtuoso.com/wp-content/uploads/2009/08/image37.png" width="420" height="207" /></p>
<p>So how do you do this you ask?&#160; With JavaScript of course.&#160; Here is some code:</p>
<div class="codecolorer-container javascript " style="overflow:auto;white-space:nowrap;width:580px"><table cellspacing="0" cellpadding="0"><tbody><tr><td class="line-numbers"><div>1<br />2<br />3<br />4<br />5<br />6<br /></div></td><td><div class="javascript codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="kw2">function</span> importFile<span class="br0">&#40;</span>src<span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw2">var</span> scriptElement <span class="sy0">=</span> document.<span class="me1">createElement</span><span class="br0">&#40;</span><span class="st0">'script'</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; scriptElement.<span class="me1">setAttribute</span><span class="br0">&#40;</span><span class="st0">'src'</span><span class="sy0">,</span>src<span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; scriptElement.<span class="me1">setAttribute</span><span class="br0">&#40;</span><span class="st0">'type'</span><span class="sy0">,</span><span class="st0">'text/javascript'</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; document.<span class="me1">getElementsByTagName</span><span class="br0">&#40;</span><span class="st0">'head'</span><span class="br0">&#41;</span><span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span>.<span class="me1">appendChild</span><span class="br0">&#40;</span>scriptElement<span class="br0">&#41;</span><span class="sy0">;</span><br />
<span class="br0">&#125;</span></div></td></tr></tbody></table></div>
<p>&#160;</p>
<p>The function importFile() will add an element to the head of your document, just like you would normally.</p>
<p>To use these function you might do something like this:</p>
<div class="codecolorer-container javascript " style="overflow:auto;white-space:nowrap;width:580px"><table cellspacing="0" cellpadding="0"><tbody><tr><td class="line-numbers"><div>1<br />2<br />3<br />4<br />5<br />6<br /></div></td><td><div class="javascript codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="kw1">if</span> <span class="br0">&#40;</span>FunctionInFile<span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="co1">// javascript is loaded</span><br />
<span class="br0">&#125;</span><br />
<span class="kw1">else</span><span class="br0">&#123;</span> <span class="co1">// not loaded yet</span><br />
&nbsp; &nbsp; importFile<span class="br0">&#40;</span><span class="st0">'javascriptFile.js'</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
<span class="br0">&#125;</span></div></td></tr></tbody></table></div>
<p>&#160;</p>
<p>It checks to see if a function you have in your JavaScript file exists, if it doesn’t then load the JavaScript file.</p>
<p>&#160;</p>
<h2>Delaying</h2>
<p><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="delay loading javascript" border="0" alt="delay loading javascript" src="http://www.devirtuoso.com/wp-content/uploads/2009/08/image38.png" width="420" height="225" /> </p>
<p>The problem with loading your JavaScript on demand is there can be a pause while the script loads.&#160; To prevent this we can just put a delay on loading the JavaScript.&#160; This way it won’t load on page load, and it will be ready for whenever you need it.&#160; This might look something like this:</p>
<div class="codecolorer-container javascript " style="overflow:auto;white-space:nowrap;width:580px"><table cellspacing="0" cellpadding="0"><tbody><tr><td class="line-numbers"><div>1<br />2<br /></div></td><td><div class="javascript codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="co1">//Called on page load</span><br />
setTimeout<span class="br0">&#40;</span><span class="st0">&quot;loadFiles();&quot;</span><span class="sy0">,</span> <span class="nu0">5000</span><span class="br0">&#41;</span><span class="sy0">;</span></div></td></tr></tbody></table></div>
<p>&#160;</p>
<h2>Other Methods</h2>
<p>Besides that you should consider combining all your JavaScript into one file, this way there are less requests for your browser to make. </p>
<p> Also consider caching you’re JavaScript files.&#160; If the browser already has the file on hand it won’t download it, saving precious load time.</p>
<p> Lastly consider compressing your files, the smaller the files, the less the user has to download.</p>
<p>&#160;</p>
<h2>Conclusion</h2>
<p>Hopefully these methods will help speed up your load times a bit.&#160; You’re users will thank you for it…or rather they won’t complain as much…which is sort of like a thank you <img src='http://www.devirtuoso.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>&#160;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.devirtuoso.com/2009/08/speeding-up-page-loading-for-javascript-heavy-sites/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>A Quick Way to Use Page Scrolling to Reveal an Image</title>
		<link>http://www.devirtuoso.com/2009/08/a-quick-way-to-use-page-scrolling-to-reveal-an-image/</link>
		<comments>http://www.devirtuoso.com/2009/08/a-quick-way-to-use-page-scrolling-to-reveal-an-image/#comments</comments>
		<pubDate>Fri, 14 Aug 2009 14:33:46 +0000</pubDate>
		<dc:creator>Shawn</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[Front End Development]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[How to]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://www.devirtuoso.com/?p=886</guid>
		<description><![CDATA[From time to time you may see a website that reveals some image in the background when the user scrolls.  More times than not it displays advertising.  We’re going to create a super quick and easy web page that reveals an image as the user scrolls down.

What We Are Building
Here is a look at what [...]]]></description>
			<content:encoded><![CDATA[<p>From time to time you may see a website that reveals some image in the background when the user scrolls.  More times than not it displays advertising.  We’re going to create a super quick and easy web page that reveals an image as the user scrolls down.</p>
<p><span id="more-886"></span></p>
<h2>What We Are Building</h2>
<p>Here is a look at what we’ll be building.  Not too fancy but it gets the job done.  It gives your site a nice little Easter egg for you users to find when surfing.</p>
<div class="resources"><a class="Download" href="http://www.devirtuoso.com/Examples/Scroll-Reveal/example.zip" target="_blank">Download</a><a class="Example" href="http://www.devirtuoso.com/Examples/Scroll-Reveal/" target="_blank">Example</a></div>
<p><a class="Example" href="http://www.devirtuoso.com/Examples/Scroll-Reveal/" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" src="http://www.devirtuoso.com/wp-content/uploads/2009/08/image19.png" border="0" alt="image" width="424" height="353" /></a></p>
<h2>Getting Started</h2>
<p>The first thing we’re going to have to do is image work.  Decide which image you want to reveal.  I just found a picture of a cat on the internet.  Second of all you’re going to have to create a fairly large image that goes from your background color to transparent.  It needs to be large enough to cover even your largest browser.  I made mine about 2000px square with a little texture in the gradation.  Once you have that made, simply save it as a transparent PNG and your ready to go.  The idea here is that the transparent PNG is going to sit on top of your hidden image.  Your PNG is going to scroll up,  but your hidden image is going to stay in place.  Kind of like the curtains at a theatre.</p>
<p><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" src="http://www.devirtuoso.com/wp-content/uploads/2009/08/image20.png" border="0" alt="image" width="429" height="496" /></p>
<h2>The Code</h2>
<p>There is not much to this.  There is a single div wrapper which will have the PNG overlay as it’s background, and the body will have the hidden image as it’s background.  In this tutorial I also added some text and an arrow just to show that it is scrolling.</p>
<p>Just a couple of notes.  For this to work in IE6 your going to have to find a PNG transparency fix.  There are 10 million out there, just pick one.  I used the <a title="jquery pngfix plugin" href="http://jquery.andreaseberhard.de/pngFix/" target="_blank">jQuery pngFix plugin</a>. Also be sure to get rid of any margin padding on the body.  You’re PNG overlay won’t go to the edges if you have this margin in place.</p>
<p>Here is the Code:</p>
<div class="codecolorer-container html4strict " style="overflow:auto;white-space:nowrap;width:580px"><table cellspacing="0" cellpadding="0"><tbody><tr><td class="line-numbers"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br /></div></td><td><div class="html4strict codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="sc0">&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot;</span><br />
<span class="sc0">&nbsp; &nbsp; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&quot;&gt;</span><br />
<span class="sc2">&lt;<a href="http://december.com/html/4/element/html.html"><span class="kw2">html</span></a>&gt;</span><br />
<span class="sc2">&lt;<a href="http://december.com/html/4/element/head.html"><span class="kw2">head</span></a>&gt;</span><br />
&nbsp; &nbsp; <br />
<span class="sc2">&lt;<a href="http://december.com/html/4/element/meta.html"><span class="kw2">meta</span></a> <span class="kw3">http-equiv</span><span class="sy0">=</span><span class="st0">&quot;Content-type&quot;</span> <span class="kw3">content</span><span class="sy0">=</span><span class="st0">&quot;text/html; charset=utf-8&quot;</span> <span class="sy0">/</span>&gt;</span><br />
<span class="sc2">&lt;<a href="http://december.com/html/4/element/title.html"><span class="kw2">title</span></a>&gt;</span>Page Title<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/title.html"><span class="kw2">title</span></a>&gt;</span><br />
<span class="sc2">&lt;<a href="http://december.com/html/4/element/style.html"><span class="kw2">style</span></a> <span class="kw3">type</span><span class="sy0">=</span><span class="st0">&quot;text/css&quot;</span> <span class="kw3">media</span><span class="sy0">=</span><span class="st0">&quot;screen&quot;</span>&gt;</span><br />
&nbsp; &nbsp; /* Get rid of any margins*/<br />
&nbsp; &nbsp; *{<br />
&nbsp; &nbsp; &nbsp; &nbsp; margin:0px;<br />
&nbsp; &nbsp; &nbsp; &nbsp; padding:0px;<br />
&nbsp; &nbsp; }<br />
&nbsp; &nbsp; /* Give the body your hidden image as the background<br />
&nbsp; &nbsp; and maked sure it is FIXED*/<br />
&nbsp; &nbsp; body{<br />
&nbsp; &nbsp; &nbsp; &nbsp; background: #000 url(1Fail.jpg) no-repeat fixed 50% bottom;<br />
&nbsp; &nbsp; }<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; /*Give the wrapper your overlay image as the background <br />
&nbsp; &nbsp; and make sure it SCROLLS*/<br />
&nbsp; &nbsp; #wrapper{<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; /* Just making sure you can scroll...probably will not need<br />
&nbsp; &nbsp; &nbsp; &nbsp; this if you have enough content */<br />
&nbsp; &nbsp; &nbsp; &nbsp; height:2000px;<br />
&nbsp; &nbsp; &nbsp; &nbsp; width:100%;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; background: transparent url(overlay.png) no-repeat scroll left top;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; color:white;<br />
&nbsp; &nbsp; &nbsp; &nbsp; font-family: &nbsp;Arial, &quot;MS Trebuchet&quot;, sans-serif;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; }<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; /* Centering and styling text/image within the wrapper */<br />
&nbsp; &nbsp; #wrapper h1, #wrapper img{<br />
&nbsp; &nbsp; &nbsp; &nbsp; text-align:center;<br />
&nbsp; &nbsp; &nbsp; &nbsp; width:700px;<br />
&nbsp; &nbsp; &nbsp; &nbsp; margin:0 auto;<br />
&nbsp; &nbsp; &nbsp; &nbsp; padding:100px 0px 0px;<br />
&nbsp; &nbsp; &nbsp; &nbsp; display:block;<br />
&nbsp; &nbsp; }<br />
<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/style.html"><span class="kw2">style</span></a>&gt;</span><br />
<br />
<span class="sc-1">&lt;!-- PNG FIX - NEEDED FOR IE6 &nbsp;--&gt;</span><br />
<span class="sc2">&lt;<a href="http://december.com/html/4/element/script.html"><span class="kw2">script</span></a> <span class="kw3">src</span><span class="sy0">=</span><span class="st0">&quot;http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js&quot;</span> <span class="kw3">type</span><span class="sy0">=</span><span class="st0">&quot;text/javascript&quot;</span> <span class="kw3">charset</span><span class="sy0">=</span><span class="st0">&quot;utf-8&quot;</span>&gt;&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/script.html"><span class="kw2">script</span></a>&gt;</span><br />
<span class="sc2">&lt;<a href="http://december.com/html/4/element/script.html"><span class="kw2">script</span></a> <span class="kw3">src</span><span class="sy0">=</span><span class="st0">&quot;jquery.pngFix.pack.js&quot;</span> <span class="kw3">type</span><span class="sy0">=</span><span class="st0">&quot;text/javascript&quot;</span> <span class="kw3">charset</span><span class="sy0">=</span><span class="st0">&quot;utf-8&quot;</span>&gt;&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/script.html"><span class="kw2">script</span></a>&gt;</span><br />
<span class="sc2">&lt;<a href="http://december.com/html/4/element/script.html"><span class="kw2">script</span></a> <span class="kw3">type</span><span class="sy0">=</span><span class="st0">&quot;text/javascript&quot;</span>&gt;</span> <br />
&nbsp; &nbsp; $(document).ready(function(){ <br />
&nbsp; &nbsp; &nbsp; &nbsp; $(document).pngFix(); <br />
&nbsp; &nbsp; }); <br />
<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/script.html"><span class="kw2">script</span></a>&gt;</span> <br />
<br />
<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/head.html"><span class="kw2">head</span></a>&gt;</span><br />
<br />
<span class="sc2">&lt;<a href="http://december.com/html/4/element/body.html"><span class="kw2">body</span></a>&gt;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/div.html"><span class="kw2">div</span></a> <span class="kw3">id</span><span class="sy0">=</span><span class="st0">&quot;wrapper&quot;</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc-1">&lt;!-- Regular Content --&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/h1.html"><span class="kw2">h1</span></a>&gt;</span>Scroll Down to see the hidden image.<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/h1.html"><span class="kw2">h1</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/img.html"><span class="kw2">img</span></a> <span class="kw3">src</span><span class="sy0">=</span><span class="st0">&quot;arrow.gif&quot;</span> <span class="kw3">alt</span><span class="sy0">=</span><span class="st0">&quot;&quot;</span> <span class="kw3">title</span><span class="sy0">=</span><span class="st0">&quot;&quot;</span> <span class="sy0">/</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/div.html"><span class="kw2">div</span></a>&gt;</span><br />
&nbsp; &nbsp; <br />
<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/body.html"><span class="kw2">body</span></a>&gt;</span><br />
<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/html.html"><span class="kw2">html</span></a>&gt;</span></div></td></tr></tbody></table></div>
<p>That’s all there is too it.  Nice and quick for a pretty cool effect.  Enjoy.</p>
<div class="resources"><a class="Download" href="http://www.devirtuoso.com/Examples/Scroll-Reveal/example.zip" target="_blank">Download</a><a class="Example" href="http://www.devirtuoso.com/Examples/Scroll-Reveal/" target="_blank">Example</a></div>
<p>&#160;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.devirtuoso.com/2009/08/a-quick-way-to-use-page-scrolling-to-reveal-an-image/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Create a 3D Tag Cloud in jQuery</title>
		<link>http://www.devirtuoso.com/2009/08/how-to-create-a-3d-tag-cloud-in-jquery/</link>
		<comments>http://www.devirtuoso.com/2009/08/how-to-create-a-3d-tag-cloud-in-jquery/#comments</comments>
		<pubDate>Tue, 11 Aug 2009 01:53:24 +0000</pubDate>
		<dc:creator>Shawn</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[Front End Development]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[3d]]></category>
		<category><![CDATA[JQuery]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://www.devirtuoso.com/?p=829</guid>
		<description><![CDATA[With browsers rendering JavaScript faster than ever before, it’s a great opportunity to get creative with jQuery.&#160; This tutorial will show how to create a scrolling 3D tag cloud…it’s not as difficult as you might think.

&#160;
3D Tag Clouds..Oh My
What exactly will we be building?&#160; It’s somewhat like a carousel, but we’re going to have the [...]]]></description>
			<content:encoded><![CDATA[<p>With browsers rendering JavaScript faster than ever before, it’s a great opportunity to get creative with <strong>jQuery</strong>.&#160; This tutorial will show how to create <strong>a scrolling 3D tag cloud</strong>…it’s not as difficult as you might think.</p>
<p><span id="more-829"></span></p>
<p>&#160;</p>
<h3>3D Tag Clouds..Oh My</h3>
<p>What exactly will we be building?&#160; It’s somewhat like a carousel, but we’re going to have the take fade off into the distance like the lone ranger at the end of cheesy “B” western flick….very dramatic.&#160; </p>
<p>We’re also going to have our tag cloud interact with the users mouse.&#160; The further the mouse is away from the center, the faster it will rotate.</p>
<div class="resources"><a class="Download" href="http://www.devirtuoso.com/Examples/3D-jQuery/example.zip" target="_blank">Download</a><a class="Example" href="http://www.devirtuoso.com/Examples/3D-jQuery/" target="_blank">Example</a></div>
<p> <a href="http://http://www.devirtuoso.com/Examples/3D-jQuery/" target="_blank"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="3d tag cloud" border="0" alt="3d tag cloud" src="http://www.devirtuoso.com/wp-content/uploads/2009/08/image4.png" width="305" height="305" /></a></p>
<p>&#160;</p>
<h3>Simple HTML</h3>
<p>As the sub title suggests the HTML is painfully simple.&#160; Most of the complicated stuff is in the jQuery.&#160; All we’ll need is a list of anchor tags wrapped in a div.&#160; Told you it was simple,&#160; here is the <strong>HTML</strong>.</p>
<div class="codecolorer-container html4strict " style="overflow:auto;white-space:nowrap;width:580px"><table cellspacing="0" cellpadding="0"><tbody><tr><td class="line-numbers"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br /></div></td><td><div class="html4strict codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="sc0">&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot;</span><br />
<span class="sc0">&nbsp; &nbsp; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&quot;&gt;</span><br />
<span class="sc2">&lt;<a href="http://december.com/html/4/element/html.html"><span class="kw2">html</span></a>&gt;</span><br />
<span class="sc2">&lt;<a href="http://december.com/html/4/element/head.html"><span class="kw2">head</span></a>&gt;</span><br />
&nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/meta.html"><span class="kw2">meta</span></a> <span class="kw3">http-equiv</span><span class="sy0">=</span><span class="st0">&quot;Content-type&quot;</span> <span class="kw3">content</span><span class="sy0">=</span><span class="st0">&quot;text/html; charset=utf-8&quot;</span> <span class="sy0">/</span>&gt;</span><br />
&nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/title.html"><span class="kw2">title</span></a>&gt;</span>jQuery 3D<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/title.html"><span class="kw2">title</span></a>&gt;</span><br />
&nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/script.html"><span class="kw2">script</span></a> <span class="kw3">src</span><span class="sy0">=</span><span class="st0">&quot;http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js&quot;</span> <span class="kw3">type</span><span class="sy0">=</span><span class="st0">&quot;text/javascript&quot;</span> <span class="kw3">charset</span><span class="sy0">=</span><span class="st0">&quot;utf-8&quot;</span>&gt;&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/script.html"><span class="kw2">script</span></a>&gt;</span><br />
<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/head.html"><span class="kw2">head</span></a>&gt;</span><br />
<span class="sc2">&lt;<a href="http://december.com/html/4/element/body.html"><span class="kw2">body</span></a>&gt;</span><br />
&nbsp; &nbsp; <br />
<span class="sc2">&lt;<a href="http://december.com/html/4/element/div.html"><span class="kw2">div</span></a> <span class="kw3">id</span><span class="sy0">=</span><span class="st0">&quot;list&quot;</span>&gt;</span><br />
&nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/ul.html"><span class="kw2">ul</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;&lt;<a href="http://december.com/html/4/element/a.html"><span class="kw2">a</span></a> <span class="kw3">href</span><span class="sy0">=</span><span class="st0">&quot;#&quot;</span>&gt;</span>ajax<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/a.html"><span class="kw2">a</span></a>&gt;&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;&lt;<a href="http://december.com/html/4/element/a.html"><span class="kw2">a</span></a> <span class="kw3">href</span><span class="sy0">=</span><span class="st0">&quot;#&quot;</span>&gt;</span>css<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/a.html"><span class="kw2">a</span></a>&gt;&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;&lt;<a href="http://december.com/html/4/element/a.html"><span class="kw2">a</span></a> <span class="kw3">href</span><span class="sy0">=</span><span class="st0">&quot;#&quot;</span>&gt;</span>design<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/a.html"><span class="kw2">a</span></a>&gt;&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;&lt;<a href="http://december.com/html/4/element/a.html"><span class="kw2">a</span></a> <span class="kw3">href</span><span class="sy0">=</span><span class="st0">&quot;#&quot;</span>&gt;</span>firefox<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/a.html"><span class="kw2">a</span></a>&gt;&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;&lt;<a href="http://december.com/html/4/element/a.html"><span class="kw2">a</span></a> <span class="kw3">href</span><span class="sy0">=</span><span class="st0">&quot;#&quot;</span>&gt;</span>flash<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/a.html"><span class="kw2">a</span></a>&gt;&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;&lt;<a href="http://december.com/html/4/element/a.html"><span class="kw2">a</span></a> <span class="kw3">href</span><span class="sy0">=</span><span class="st0">&quot;#&quot;</span>&gt;</span>html<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/a.html"><span class="kw2">a</span></a>&gt;&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;&lt;<a href="http://december.com/html/4/element/a.html"><span class="kw2">a</span></a> <span class="kw3">href</span><span class="sy0">=</span><span class="st0">&quot;#&quot;</span>&gt;</span>Devirtuoso<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/a.html"><span class="kw2">a</span></a>&gt;&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;&lt;<a href="http://december.com/html/4/element/a.html"><span class="kw2">a</span></a> <span class="kw3">href</span><span class="sy0">=</span><span class="st0">&quot;#&quot;</span>&gt;</span>jquery<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/a.html"><span class="kw2">a</span></a>&gt;&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;&lt;<a href="http://december.com/html/4/element/a.html"><span class="kw2">a</span></a> <span class="kw3">href</span><span class="sy0">=</span><span class="st0">&quot;#&quot;</span>&gt;</span>PHP<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/a.html"><span class="kw2">a</span></a>&gt;&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;&lt;<a href="http://december.com/html/4/element/a.html"><span class="kw2">a</span></a> <span class="kw3">href</span><span class="sy0">=</span><span class="st0">&quot;#&quot;</span>&gt;</span>SEO<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/a.html"><span class="kw2">a</span></a>&gt;&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;&lt;<a href="http://december.com/html/4/element/a.html"><span class="kw2">a</span></a> <span class="kw3">href</span><span class="sy0">=</span><span class="st0">&quot;#&quot;</span>&gt;</span>usability<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/a.html"><span class="kw2">a</span></a>&gt;&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;&lt;<a href="http://december.com/html/4/element/a.html"><span class="kw2">a</span></a> <span class="kw3">href</span><span class="sy0">=</span><span class="st0">&quot;#&quot;</span>&gt;</span>www<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/a.html"><span class="kw2">a</span></a>&gt;&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;&lt;<a href="http://december.com/html/4/element/a.html"><span class="kw2">a</span></a> <span class="kw3">href</span><span class="sy0">=</span><span class="st0">&quot;#&quot;</span>&gt;</span>web<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/a.html"><span class="kw2">a</span></a>&gt;&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;&lt;<a href="http://december.com/html/4/element/a.html"><span class="kw2">a</span></a> <span class="kw3">href</span><span class="sy0">=</span><span class="st0">&quot;#&quot;</span>&gt;</span>xhtml<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/a.html"><span class="kw2">a</span></a>&gt;&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/ul.html"><span class="kw2">ul</span></a>&gt;</span><br />
<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/div.html"><span class="kw2">div</span></a>&gt;</span>&nbsp; <br />
<br />
<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/body.html"><span class="kw2">body</span></a>&gt;</span><br />
<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/html.html"><span class="kw2">html</span></a>&gt;</span></div></td></tr></tbody></table></div>
<p>&#160;</p>
<h3>Styling the List</h3>
<p>For the most part the CSS is just to make the links pretty.&#160; There are a couple of things that need to happen though.&#160; The anchor links need to have a position: absolute.&#160; This way the jQuery can give it x and y co-ordinates and the links will obey.&#160; Also we need to give a height and width of the div wrapper.&#160; The jQuery reference the dimensions of the wrapper to help layout the links.&#160; It might also be a good idea to give the wrapper a position:relative to keep the links inside the wrapper, this isn’t necessary though. </p>
<p>Here is the <strong>CSS</strong>:</p>
<div class="codecolorer-container css " style="overflow:auto;white-space:nowrap;width:580px"><table cellspacing="0" cellpadding="0"><tbody><tr><td class="line-numbers"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br /></div></td><td><div class="css codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="coMULTI">/* Set font and background for body*/</span> &nbsp; <br />
body<span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw1">font-family</span><span class="sy0">:</span> Arial<span class="sy0">,</span> <span class="st0">&quot;MS Trebuchet&quot;</span><span class="sy0">,</span> <span class="kw2">sans-serif</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="kw1">background-color</span><span class="sy0">:</span> <span class="re0">#111</span><span class="sy0">;</span><br />
<span class="br0">&#125;</span><br />
<br />
<span class="coMULTI">/* Styles the div wrapper<br />
the important part is the<br />
width and the height */</span><br />
<span class="re0">#list</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span class="coMULTI">/*Influences layout of list*/</span><br />
&nbsp; &nbsp; <span class="kw1">height</span><span class="sy0">:</span><span class="re3">600px</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="kw1">width</span><span class="sy0">:</span><span class="re3">600px</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span class="kw1">background-color</span><span class="sy0">:</span> <span class="re0">#000</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span class="coMULTI">/* Keeps list inside of wrapper*/</span><br />
&nbsp; &nbsp; <span class="kw1">position</span><span class="sy0">:</span><span class="kw2">relative</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="kw1">margin</span><span class="sy0">:</span><span class="nu0">0</span> <span class="kw2">auto</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="kw1">overflow</span><span class="sy0">:</span><span class="kw2">hidden</span><span class="sy0">;</span><br />
<span class="br0">&#125;</span><br />
<br />
<span class="coMULTI">/* Reset the list*/</span><br />
<span class="re0">#list</span> ul<span class="sy0">,</span><br />
<span class="re0">#list</span> li<span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw1">list-style</span><span class="sy0">:</span><span class="kw2">none</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="kw1">margin</span><span class="sy0">:</span><span class="nu0">0</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="kw1">padding</span><span class="sy0">:</span><span class="nu0">0</span><span class="sy0">;</span><br />
<span class="br0">&#125;</span><br />
<br />
<span class="coMULTI">/* List requires an absolute position<br />
so jQuery can move the items around<br />
freely */</span><br />
<span class="re0">#list</span> a<span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw1">position</span><span class="sy0">:</span><span class="kw2">absolute</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="kw1">text-decoration</span><span class="sy0">:</span> <span class="kw2">none</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="kw1">color</span><span class="sy0">:</span><span class="re0">#666</span><span class="sy0">;</span><br />
<span class="br0">&#125;</span><br />
<span class="re0">#list</span> a<span class="re2">:hover</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw1">color</span><span class="sy0">:</span><span class="re0">#ccc</span><span class="sy0">;</span><br />
<span class="br0">&#125;</span></div></td></tr></tbody></table></div>
<p>&#160;</p>
<h3>The Fun Part (jQuery)</h3>
<p>Now comes the trigonometry….see…your high school teacher was right, you will use this stuff in the real world.&#160; It really isn’t that bad though…3 lines of trigonometry is more than acceptable. I’m not going to go into great detail with the math.&#160; If you want to learn more about the math behind the 3D I recommend reading <a title="Scripting 3D in Flash" href="http://www.kirupa.com/developer/actionscript/3dexplore.htm" target="_blank">Kirupa.com tutorial on it</a>. The tutorial is for flash, but you will get the gist of how it works.</p>
<p>Here is the <strong>jQuery</strong>:</p>
<div class="codecolorer-container javascript " style="overflow:auto;white-space:nowrap;width:580px"><table cellspacing="0" cellpadding="0"><tbody><tr><td class="line-numbers"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br /></div></td><td><div class="javascript codecolorer" style="font-family:Monaco,Lucida Console,monospace">$<span class="br0">&#40;</span>document<span class="br0">&#41;</span>.<span class="me1">ready</span><span class="br0">&#40;</span><span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; <br />
<span class="co1">//Setup variables</span><br />
<span class="kw2">var</span> element <span class="sy0">=</span> $<span class="br0">&#40;</span><span class="st0">'#list a'</span><span class="br0">&#41;</span><span class="sy0">;</span> <span class="co1">// all the list elements</span><br />
<span class="kw2">var</span> offset <span class="sy0">=</span> <span class="nu0">0</span><span class="sy0">;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// angle offset for animation</span><br />
<span class="kw2">var</span> stepping <span class="sy0">=</span> <span class="nu0">0.03</span><span class="sy0">;</span>&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// how fast the list rotates</span><br />
<span class="kw2">var</span> list <span class="sy0">=</span> $<span class="br0">&#40;</span><span class="st0">'#list'</span><span class="br0">&#41;</span><span class="sy0">;</span>&nbsp; &nbsp; &nbsp; <span class="co1">// the list wrapper</span><br />
<span class="kw2">var</span> $list <span class="sy0">=</span> $<span class="br0">&#40;</span>list<span class="br0">&#41;</span><span class="sy0">;</span><br />
<br />
<span class="coMULTI">/* Handles mouse movement, the closer to the center<br />
the faster the list will rotate */</span><br />
$list.<span class="me1">mousemove</span><span class="br0">&#40;</span><span class="kw2">function</span><span class="br0">&#40;</span>e<span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span class="kw2">var</span> topOfList <span class="sy0">=</span> $list.<span class="me1">eq</span><span class="br0">&#40;</span><span class="nu0">0</span><span class="br0">&#41;</span>.<span class="me1">offset</span><span class="br0">&#40;</span><span class="br0">&#41;</span>.<span class="me1">top</span><br />
&nbsp; &nbsp; <span class="kw2">var</span> listHeight <span class="sy0">=</span> $list.<span class="me1">height</span><span class="br0">&#40;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span class="co1">// Sets variable that controls the speed of rotation.</span><br />
&nbsp; &nbsp; stepping <span class="sy0">=</span> <span class="br0">&#40;</span>e.<span class="me1">clientY</span> <span class="sy0">-</span> topOfList<span class="br0">&#41;</span> <span class="sy0">/</span> &nbsp;listHeight <span class="sy0">*</span> <span class="nu0">0.2</span> <span class="sy0">-</span> <span class="nu0">0.1</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <br />
<span class="br0">&#125;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
<br />
<br />
<span class="co2">/* Disperse elements evenly around the circle */</span><br />
<span class="kw1">for</span> <span class="br0">&#40;</span><span class="kw2">var</span> i <span class="sy0">=</span> element.<span class="me1">length</span> <span class="sy0">-</span> <span class="nu0">1</span><span class="sy0">;</span> i <span class="sy0">&gt;=</span> <span class="nu0">0</span><span class="sy0">;</span> i<span class="sy0">--</span><span class="br0">&#41;</span><br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp; element<span class="br0">&#91;</span>i<span class="br0">&#93;</span>.<span class="me1">elemAngle</span> <span class="sy0">=</span> i <span class="sy0">*</span> Math.<span class="me1">PI</span> <span class="sy0">*</span> <span class="nu0">2</span> <span class="sy0">/</span> element.<span class="me1">length</span><span class="sy0">;</span><br />
<span class="br0">&#125;</span><br />
<br />
<span class="co1">// call render function over and over</span><br />
setInterval<span class="br0">&#40;</span>render<span class="sy0">,</span> <span class="nu0">20</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
<br />
<br />
<span class="co1">// Handles how and where each element will be rendered.</span><br />
<span class="kw2">function</span> render<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span class="co1">//Steps through each element...</span><br />
&nbsp; &nbsp; <span class="kw1">for</span> <span class="br0">&#40;</span><span class="kw2">var</span> i <span class="sy0">=</span> element.<span class="me1">length</span> <span class="sy0">-</span> <span class="nu0">1</span><span class="sy0">;</span> i <span class="sy0">&gt;=</span> <span class="nu0">0</span><span class="sy0">;</span> i<span class="sy0">--</span><span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// offset adds degrees to where the element </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// is currently on the circle</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> angle <span class="sy0">=</span> element<span class="br0">&#91;</span>i<span class="br0">&#93;</span>.<span class="me1">elemAngle</span> <span class="sy0">+</span> offset<span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// Trig to figure out the size and where the</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// text should go</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; x <span class="sy0">=</span> <span class="nu0">120</span> <span class="sy0">+</span> Math.<span class="me1">sin</span><span class="br0">&#40;</span>angle<span class="br0">&#41;</span> <span class="sy0">*</span> <span class="nu0">30</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; y <span class="sy0">=</span> <span class="nu0">45</span> <span class="sy0">+</span> Math.<span class="me1">cos</span><span class="br0">&#40;</span>angle<span class="br0">&#41;</span> <span class="sy0">*</span> <span class="nu0">40</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; size <span class="sy0">=</span> Math.<span class="me1">round</span><span class="br0">&#40;</span><span class="nu0">40</span> <span class="sy0">-</span> Math.<span class="me1">sin</span><span class="br0">&#40;</span>angle<span class="br0">&#41;</span> <span class="sy0">*</span> <span class="nu0">40</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// Centers the text, instead of being left aligned.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> elementCenter <span class="sy0">=</span> $<span class="br0">&#40;</span>element<span class="br0">&#91;</span>i<span class="br0">&#93;</span><span class="br0">&#41;</span>.<span class="me1">width</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="sy0">/</span> <span class="nu0">2</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// Figure out the x value of the element.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> leftValue <span class="sy0">=</span> <span class="br0">&#40;</span><span class="br0">&#40;</span>$list.<span class="me1">width</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">/</span><span class="nu0">2</span><span class="br0">&#41;</span> <span class="sy0">*</span> x <span class="sy0">/</span> <span class="nu0">100</span> <span class="sy0">-</span> elementCenter<span class="br0">&#41;</span> <span class="sy0">+</span> <span class="st0">&quot;px&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// Apply the values to the text</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; $<span class="br0">&#40;</span>element<span class="br0">&#91;</span>i<span class="br0">&#93;</span><span class="br0">&#41;</span>.<span class="me1">css</span><span class="br0">&#40;</span><span class="st0">&quot;fontSize&quot;</span><span class="sy0">,</span> size <span class="sy0">+</span> <span class="st0">&quot;pt&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; $<span class="br0">&#40;</span>element<span class="br0">&#91;</span>i<span class="br0">&#93;</span><span class="br0">&#41;</span>.<span class="me1">css</span><span class="br0">&#40;</span><span class="st0">&quot;opacity&quot;</span><span class="sy0">,</span>size<span class="sy0">/</span><span class="nu0">100</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; $<span class="br0">&#40;</span>element<span class="br0">&#91;</span>i<span class="br0">&#93;</span><span class="br0">&#41;</span>.<span class="me1">css</span><span class="br0">&#40;</span><span class="st0">&quot;zIndex&quot;</span> <span class="sy0">,</span>size<span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; $<span class="br0">&#40;</span>element<span class="br0">&#91;</span>i<span class="br0">&#93;</span><span class="br0">&#41;</span>.<span class="me1">css</span><span class="br0">&#40;</span><span class="st0">&quot;left&quot;</span> <span class="sy0">,</span>leftValue<span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; $<span class="br0">&#40;</span>element<span class="br0">&#91;</span>i<span class="br0">&#93;</span><span class="br0">&#41;</span>.<span class="me1">css</span><span class="br0">&#40;</span><span class="st0">&quot;top&quot;</span><span class="sy0">,</span> y <span class="sy0">+</span> <span class="st0">&quot;%&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span class="co1">// Rotate the circle</span><br />
&nbsp; &nbsp; offset <span class="sy0">+=</span> stepping<span class="sy0">;</span><br />
<span class="br0">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <br />
<span class="br0">&#125;</span><span class="br0">&#41;</span><span class="sy0">;</span></div></td></tr></tbody></table></div>
<p>&#160;</p>
<p>Just to step through what we did.&#160; First we setup the mouse event. We figure out how far the mouse is away from the center and assign it to a variable that controls the speed of the scrolling list. </p>
<p><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="speed" border="0" alt="speed" src="http://www.devirtuoso.com/wp-content/uploads/2009/08/image5.png" width="260" height="243" /> </p>
<p>After that we step through each element in our list and give each one a spot on our 3D circle.&#160; A for loop walks through each one, and evenly assigns an angle to each element. (e.g. 1st = 0 degrees, 2nd = 5 degrees, 3rd = 10 degrees…etc) </p>
<p><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="degrees" border="0" alt="degrees" src="http://www.devirtuoso.com/wp-content/uploads/2009/08/image6.png" width="260" height="243" /> </p>
<p>After we placed each element on our 3D circle it’s time to animate it.&#160; We use a setInterval to call our render function repeatedly.&#160; The render function steps through each element and figures out where and how it should be displayed.&#160; The trigonometry basically creates a set of numbers that if you plot it on a graph look like a wave. If you apply those numbers to the size of the text, it gives the appearance of going back and forth in space.&#160; If you also apply these numbers to the y, this will give you the appearance that the text is going around in a circle. If you don’t understand the math inside this function not to worry.&#160; I encourage you to play around with the numbers to see how each number effects the outcome.</p>
<p><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="3d" border="0" alt="3d" src="http://www.devirtuoso.com/wp-content/uploads/2009/08/image7.png" width="260" height="243" /> </p>
<p>&#160;</p>
<h3>The Finish Line</h3>
<p>That’s all there is to it.&#160; Here is the code all together so you can have a look.&#160; Enjoy.</p>
<div class="codecolorer-container html4strict " style="overflow:auto;white-space:nowrap;width:580px"><table cellspacing="0" cellpadding="0"><tbody><tr><td class="line-numbers"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br />83<br />84<br />85<br />86<br />87<br />88<br />89<br />90<br />91<br />92<br />93<br />94<br />95<br />96<br />97<br />98<br />99<br />100<br />101<br />102<br />103<br />104<br />105<br />106<br />107<br />108<br />109<br />110<br />111<br />112<br />113<br />114<br />115<br />116<br />117<br />118<br /></div></td><td><div class="html4strict codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="sc0">&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot;</span><br />
<span class="sc0">&nbsp; &nbsp; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&quot;&gt;</span><br />
<span class="sc2">&lt;<a href="http://december.com/html/4/element/html.html"><span class="kw2">html</span></a>&gt;</span><br />
<span class="sc2">&lt;<a href="http://december.com/html/4/element/head.html"><span class="kw2">head</span></a>&gt;</span><br />
<span class="sc2">&lt;<a href="http://december.com/html/4/element/meta.html"><span class="kw2">meta</span></a> <span class="kw3">http-equiv</span><span class="sy0">=</span><span class="st0">&quot;Content-type&quot;</span> <span class="kw3">content</span><span class="sy0">=</span><span class="st0">&quot;text/html; charset=utf-8&quot;</span> <span class="sy0">/</span>&gt;</span><br />
<span class="sc2">&lt;<a href="http://december.com/html/4/element/title.html"><span class="kw2">title</span></a>&gt;</span>jQuery 3D<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/title.html"><span class="kw2">title</span></a>&gt;</span><br />
<br />
<span class="sc2">&lt;<a href="http://december.com/html/4/element/style.html"><span class="kw2">style</span></a> <span class="kw3">type</span><span class="sy0">=</span><span class="st0">&quot;text/css&quot;</span> <span class="kw3">media</span><span class="sy0">=</span><span class="st0">&quot;screen&quot;</span>&gt;</span><br />
&nbsp; &nbsp; body{<br />
&nbsp; &nbsp; &nbsp; &nbsp; font-family: Arial, &quot;MS Trebuchet&quot;, sans-serif;<br />
&nbsp; &nbsp; &nbsp; &nbsp; background-color: #111;<br />
&nbsp; &nbsp; }<br />
&nbsp; &nbsp; #list{<br />
&nbsp; &nbsp; &nbsp; &nbsp; margin:0 auto;<br />
&nbsp; &nbsp; &nbsp; &nbsp; height:600px;<br />
&nbsp; &nbsp; &nbsp; &nbsp; width:600px;<br />
&nbsp; &nbsp; &nbsp; &nbsp; overflow:hidden;<br />
&nbsp; &nbsp; &nbsp; &nbsp; position:relative;<br />
&nbsp; &nbsp; &nbsp; &nbsp; background-color: #000;<br />
&nbsp; &nbsp; }<br />
&nbsp; &nbsp; #list ul,<br />
&nbsp; &nbsp; #list li{<br />
&nbsp; &nbsp; &nbsp; &nbsp; list-style:none;<br />
&nbsp; &nbsp; &nbsp; &nbsp; margin:0;<br />
&nbsp; &nbsp; &nbsp; &nbsp; padding:0;<br />
&nbsp; &nbsp; }<br />
&nbsp; &nbsp; #list a{<br />
&nbsp; &nbsp; &nbsp; &nbsp; position:absolute;<br />
&nbsp; &nbsp; &nbsp; &nbsp; text-decoration: none;<br />
&nbsp; &nbsp; &nbsp; &nbsp; color:#666;<br />
&nbsp; &nbsp; }<br />
&nbsp; &nbsp; #list a:hover{<br />
&nbsp; &nbsp; &nbsp; &nbsp; color:#ccc;<br />
&nbsp; &nbsp; }<br />
<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/style.html"><span class="kw2">style</span></a>&gt;</span><br />
<span class="sc2">&lt;<a href="http://december.com/html/4/element/script.html"><span class="kw2">script</span></a> <span class="kw3">src</span><span class="sy0">=</span><span class="st0">&quot;http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js&quot;</span> <span class="kw3">type</span><span class="sy0">=</span><span class="st0">&quot;text/javascript&quot;</span> <span class="kw3">charset</span><span class="sy0">=</span><span class="st0">&quot;utf-8&quot;</span>&gt;&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/script.html"><span class="kw2">script</span></a>&gt;</span><br />
<br />
<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/head.html"><span class="kw2">head</span></a>&gt;</span><br />
<span class="sc2">&lt;<a href="http://december.com/html/4/element/body.html"><span class="kw2">body</span></a>&gt;</span><br />
&nbsp; &nbsp; <br />
<span class="sc2">&lt;<a href="http://december.com/html/4/element/div.html"><span class="kw2">div</span></a> <span class="kw3">id</span><span class="sy0">=</span><span class="st0">&quot;list&quot;</span>&gt;</span><br />
&nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/ul.html"><span class="kw2">ul</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;&lt;<a href="http://december.com/html/4/element/a.html"><span class="kw2">a</span></a> <span class="kw3">href</span><span class="sy0">=</span><span class="st0">&quot;#&quot;</span>&gt;</span>ajax<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/a.html"><span class="kw2">a</span></a>&gt;&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;&lt;<a href="http://december.com/html/4/element/a.html"><span class="kw2">a</span></a> <span class="kw3">href</span><span class="sy0">=</span><span class="st0">&quot;#&quot;</span>&gt;</span>css<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/a.html"><span class="kw2">a</span></a>&gt;&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;&lt;<a href="http://december.com/html/4/element/a.html"><span class="kw2">a</span></a> <span class="kw3">href</span><span class="sy0">=</span><span class="st0">&quot;#&quot;</span>&gt;</span>design<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/a.html"><span class="kw2">a</span></a>&gt;&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;&lt;<a href="http://december.com/html/4/element/a.html"><span class="kw2">a</span></a> <span class="kw3">href</span><span class="sy0">=</span><span class="st0">&quot;#&quot;</span>&gt;</span>firefox<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/a.html"><span class="kw2">a</span></a>&gt;&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;&lt;<a href="http://december.com/html/4/element/a.html"><span class="kw2">a</span></a> <span class="kw3">href</span><span class="sy0">=</span><span class="st0">&quot;#&quot;</span>&gt;</span>flash<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/a.html"><span class="kw2">a</span></a>&gt;&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;&lt;<a href="http://december.com/html/4/element/a.html"><span class="kw2">a</span></a> <span class="kw3">href</span><span class="sy0">=</span><span class="st0">&quot;#&quot;</span>&gt;</span>html<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/a.html"><span class="kw2">a</span></a>&gt;&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;&lt;<a href="http://december.com/html/4/element/a.html"><span class="kw2">a</span></a> <span class="kw3">href</span><span class="sy0">=</span><span class="st0">&quot;#&quot;</span>&gt;</span>Devirtuoso<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/a.html"><span class="kw2">a</span></a>&gt;&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;&lt;<a href="http://december.com/html/4/element/a.html"><span class="kw2">a</span></a> <span class="kw3">href</span><span class="sy0">=</span><span class="st0">&quot;#&quot;</span>&gt;</span>jquery<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/a.html"><span class="kw2">a</span></a>&gt;&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;&lt;<a href="http://december.com/html/4/element/a.html"><span class="kw2">a</span></a> <span class="kw3">href</span><span class="sy0">=</span><span class="st0">&quot;#&quot;</span>&gt;</span>PHP<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/a.html"><span class="kw2">a</span></a>&gt;&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;&lt;<a href="http://december.com/html/4/element/a.html"><span class="kw2">a</span></a> <span class="kw3">href</span><span class="sy0">=</span><span class="st0">&quot;#&quot;</span>&gt;</span>SEO<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/a.html"><span class="kw2">a</span></a>&gt;&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;&lt;<a href="http://december.com/html/4/element/a.html"><span class="kw2">a</span></a> <span class="kw3">href</span><span class="sy0">=</span><span class="st0">&quot;#&quot;</span>&gt;</span>usability<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/a.html"><span class="kw2">a</span></a>&gt;&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;&lt;<a href="http://december.com/html/4/element/a.html"><span class="kw2">a</span></a> <span class="kw3">href</span><span class="sy0">=</span><span class="st0">&quot;#&quot;</span>&gt;</span>www<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/a.html"><span class="kw2">a</span></a>&gt;&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;&lt;<a href="http://december.com/html/4/element/a.html"><span class="kw2">a</span></a> <span class="kw3">href</span><span class="sy0">=</span><span class="st0">&quot;#&quot;</span>&gt;</span>web<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/a.html"><span class="kw2">a</span></a>&gt;&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;&lt;<a href="http://december.com/html/4/element/a.html"><span class="kw2">a</span></a> <span class="kw3">href</span><span class="sy0">=</span><span class="st0">&quot;#&quot;</span>&gt;</span>xhtml<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/a.html"><span class="kw2">a</span></a>&gt;&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/ul.html"><span class="kw2">ul</span></a>&gt;</span><br />
<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/div.html"><span class="kw2">div</span></a>&gt;</span><br />
<br />
<span class="sc2">&lt;<a href="http://december.com/html/4/element/script.html"><span class="kw2">script</span></a> <span class="kw3">type</span><span class="sy0">=</span><span class="st0">&quot;text/javascript&quot;</span>&gt;</span><br />
<br />
<br />
$(document).ready(function(){<br />
&nbsp; &nbsp; <br />
var element = $('#list a');<br />
var offset = 0; <br />
var stepping = 0.03;<br />
var list = $('#list');<br />
var $list = $(list)<br />
<br />
$list.mousemove(function(e){<br />
&nbsp; &nbsp; var topOfList = $list.eq(0).offset().top<br />
&nbsp; &nbsp; var listHeight = $list.height()<br />
&nbsp; &nbsp; stepping = (e.clientY - topOfList) / &nbsp;listHeight * 0.2 - 0.1;<br />
&nbsp; &nbsp; <br />
});<br />
<br />
<br />
for (var i = element.length - 1; i &gt;= 0; i--)<br />
{<br />
&nbsp; &nbsp; element[i].elemAngle = i * Math.PI * 2 / element.length;<br />
}<br />
<br />
<br />
setInterval(render, 20);<br />
<br />
<br />
function render(){<br />
&nbsp; &nbsp; for (var i = element.length - 1; i &gt;= 0; i--){<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; var angle = element[i].elemAngle + offset;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; x = 120 + Math.sin(angle) * 30;<br />
&nbsp; &nbsp; &nbsp; &nbsp; y = 45 + Math.cos(angle) * 40;<br />
&nbsp; &nbsp; &nbsp; &nbsp; size = Math.round(40 - Math.sin(angle) * 40);<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; var elementCenter = $(element[i]).width() / 2;<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; var leftValue = (($list.width()/2) * x / 100 - elementCenter) + &quot;px&quot;<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; $(element[i]).css(&quot;fontSize&quot;, size + &quot;pt&quot;);<br />
&nbsp; &nbsp; &nbsp; &nbsp; $(element[i]).css(&quot;opacity&quot;,size/100);<br />
&nbsp; &nbsp; &nbsp; &nbsp; $(element[i]).css(&quot;zIndex&quot; ,size);<br />
&nbsp; &nbsp; &nbsp; &nbsp; $(element[i]).css(&quot;left&quot; ,leftValue);<br />
&nbsp; &nbsp; &nbsp; &nbsp; $(element[i]).css(&quot;top&quot;, y + &quot;%&quot;);<br />
&nbsp; &nbsp; }<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; offset += stepping;<br />
}<br />
<br />
&nbsp; &nbsp; <br />
});<br />
<br />
<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/script.html"><span class="kw2">script</span></a>&gt;</span><br />
<br />
<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/body.html"><span class="kw2">body</span></a>&gt;</span><br />
<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/html.html"><span class="kw2">html</span></a>&gt;</span></div></td></tr></tbody></table></div>
<p>&#160;</p>
<div class="resources"><a class="Download" href="http://www.devirtuoso.com/Examples/3D-jQuery/example.zip" target="_blank">Download</a><a class="Example" href="http://www.devirtuoso.com/Examples/3D-jQuery/" target="_blank">Example</a></div>
<p>&#160;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.devirtuoso.com/2009/08/how-to-create-a-3d-tag-cloud-in-jquery/feed/</wfw:commentRss>
		<slash:comments>26</slash:comments>
		</item>
		<item>
		<title>Styling Drop Down Boxes with jQuery</title>
		<link>http://www.devirtuoso.com/2009/08/styling-drop-down-boxes-with-jquery/</link>
		<comments>http://www.devirtuoso.com/2009/08/styling-drop-down-boxes-with-jquery/#comments</comments>
		<pubDate>Thu, 06 Aug 2009 09:58:02 +0000</pubDate>
		<dc:creator>Shawn</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[Front End Development]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[JQuery]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://www.devirtuoso.com/?p=804</guid>
		<description><![CDATA[One problem with HTML forms is it is hard to style the elements to fit into your design.  The tutorial will show you how to style the hardest of them all, the select box.

The Plan
Unfortunately browsers allow limited skinning of select boxes.  So the plan is to use jQuery to change a select box into [...]]]></description>
			<content:encoded><![CDATA[<p>One problem with HTML forms is it is hard to style the elements to fit into your design.  The tutorial will show you how to style the hardest of them all, the select box.</p>
<p><span id="more-804"></span></p>
<h3>The Plan</h3>
<p>Unfortunately browsers allow limited skinning of select boxes.  So the plan is to use jQuery to change a select box into a text box and a unorded list for the dropdown.  When a user clicks on the text box it will display the list below the textbox, just like a regular select box, but it’s easier to style.</p>
<div class="resources"><a class="Download" href="http://www.devirtuoso.com/Examples/Styling-Dropdown/example.zip" target="_blank">Download</a> <a class="Example" href="http://www.devirtuoso.com/Examples/Styling-Dropdown/" target="_blank">Example</a></div>
<p>&#160;</p>
<h3>Getting Started</h3>
<p>The first thing we’ll need is a select box.  Nothing special here, just a regular select, but we’re going to give it an id so we can reference it later in the jQuery.</p>
<div class="codecolorer-container html4strict " style="overflow:auto;white-space:nowrap;width:580px"><table cellspacing="0" cellpadding="0"><tbody><tr><td class="line-numbers"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br /></div></td><td><div class="html4strict codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="sc0">&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot;</span><br />
<span class="sc0"> &nbsp; &nbsp;&quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&quot;&gt;</span><br />
<span class="sc2">&lt;<a href="http://december.com/html/4/element/html.html"><span class="kw2">html</span></a>&gt;</span><br />
<span class="sc2">&lt;<a href="http://december.com/html/4/element/head.html"><span class="kw2">head</span></a>&gt;</span><br />
&nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/meta.html"><span class="kw2">meta</span></a> <span class="kw3">http-equiv</span><span class="sy0">=</span><span class="st0">&quot;Content-type&quot;</span> <span class="kw3">content</span><span class="sy0">=</span><span class="st0">&quot;text/html; charset=utf-8&quot;</span> <span class="sy0">/</span>&gt;</span><br />
&nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/title.html"><span class="kw2">title</span></a>&gt;</span>Styling Select Boxes<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/title.html"><span class="kw2">title</span></a>&gt;</span><br />
<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/head.html"><span class="kw2">head</span></a>&gt;</span><br />
<span class="sc2">&lt;<a href="http://december.com/html/4/element/body.html"><span class="kw2">body</span></a>&gt;</span><br />
&nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/select.html"><span class="kw2">select</span></a> <span class="kw3">name</span><span class="sy0">=</span><span class="st0">&quot;Items&quot;</span> <span class="kw3">id</span><span class="sy0">=</span><span class="st0">&quot;Items&quot;</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/option.html"><span class="kw2">option</span></a> <span class="kw3">value</span><span class="sy0">=</span><span class="st0">&quot;option1&quot;</span>&gt;</span>option1<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/option.html"><span class="kw2">option</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/option.html"><span class="kw2">option</span></a> <span class="kw3">value</span><span class="sy0">=</span><span class="st0">&quot;option2&quot;</span>&gt;</span>option2<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/option.html"><span class="kw2">option</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/option.html"><span class="kw2">option</span></a> <span class="kw3">value</span><span class="sy0">=</span><span class="st0">&quot;option3&quot;</span>&gt;</span>option3<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/option.html"><span class="kw2">option</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/option.html"><span class="kw2">option</span></a> <span class="kw3">value</span><span class="sy0">=</span><span class="st0">&quot;option4&quot;</span>&gt;</span>option4<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/option.html"><span class="kw2">option</span></a>&gt;</span><br />
<br />
&nbsp; &nbsp; <span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/select.html"><span class="kw2">select</span></a>&gt;</span><br />
<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/body.html"><span class="kw2">body</span></a>&gt;</span><br />
<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/html.html"><span class="kw2">html</span></a>&gt;</span></div></td></tr></tbody></table></div>
<p>&#160;</p>
<h3>The jQuery</h3>
<p>To save a little time we are going to use a plugin to handle converting the select into a text box.  I’ll be using the plugin from <a href="http://www.brainfault.com/2008/02/10/new-release-of-jquery-selectbox-replacement/" target="_blank">brainfault.com</a>. From my experience this plugin is far less painful then other ones I’ve tried. It’s as simple as importing the plugin and running a method.  Here is the code to get it up and running.</p>
<div class="codecolorer-container html4strict " style="overflow:auto;white-space:nowrap;width:580px"><table cellspacing="0" cellpadding="0"><tbody><tr><td class="line-numbers"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br /></div></td><td><div class="html4strict codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="sc2">&lt;<a href="http://december.com/html/4/element/link.html"><span class="kw2">link</span></a> <span class="kw3">rel</span><span class="sy0">=</span><span class="st0">&quot;stylesheet&quot;</span> <span class="kw3">type</span><span class="sy0">=</span><span class="st0">&quot;text/css&quot;</span> <span class="kw3">href</span><span class="sy0">=</span><span class="st0">&quot;selectbox.css&quot;</span> <span class="sy0">/</span>&gt;</span><br />
<span class="sc2">&lt;<a href="http://december.com/html/4/element/script.html"><span class="kw2">script</span></a> <span class="kw3">src</span><span class="sy0">=</span><span class="st0">&quot;http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js&quot;</span> <span class="kw3">type</span><span class="sy0">=</span><span class="st0">&quot;text/javascript&quot;</span> <span class="kw3">charset</span><span class="sy0">=</span><span class="st0">&quot;utf-8&quot;</span>&gt;&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/script.html"><span class="kw2">script</span></a>&gt;</span><br />
<span class="sc2">&lt;<a href="http://december.com/html/4/element/script.html"><span class="kw2">script</span></a> <span class="kw3">type</span><span class="sy0">=</span><span class="st0">&quot;text/javascript&quot;</span> <span class="kw3">src</span><span class="sy0">=</span><span class="st0">&quot;jquery.selectbox-0.5.js&quot;</span>&gt;&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/script.html"><span class="kw2">script</span></a>&gt;</span><br />
<br />
<span class="sc2">&lt;<a href="http://december.com/html/4/element/script.html"><span class="kw2">script</span></a> <span class="kw3">type</span><span class="sy0">=</span><span class="st0">&quot;text/javascript&quot;</span>&gt;</span><br />
$(document).ready(function() {<br />
&nbsp; &nbsp; $('#Items').selectbox();<br />
});<br />
<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/script.html"><span class="kw2">script</span></a>&gt;</span></div></td></tr></tbody></table></div>
<p>Basically we’ve just imported the CSS which styles everything, jQuery, and the plugin.  Once we have those then we just have to run the selectbox method on the select boxes we would like to style.  We could have done something like $(‘select’) if we wanted to apply it to all select boxes.</p>
<p>&#160;</p>
<h3>The CSS</h3>
<p>The CSS in selectbox.css isn’t too difficult, the most important part is applying the background image to the newly created text box.  Really you don’t need to touch anything in the CSS and just change the image.  In our case we want to make a couple of changes.  We’re simply going to change the font size and width inside the selectbox class.</p>
<div class="codecolorer-container css " style="overflow:auto;white-space:nowrap;width:580px"><table cellspacing="0" cellpadding="0"><tbody><tr><td class="line-numbers"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br /></div></td><td><div class="css codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="coMULTI">/* Look and feel of select box */</span><br />
<span class="re1">.selectbox</span><br />
<span class="br0">&#123;</span><br />
&nbsp; <span class="kw1">margin</span><span class="sy0">:</span> <span class="re3">0px</span> <span class="re3">5px</span> <span class="re3">10px</span> <span class="re3">0px</span><span class="sy0">;</span><br />
&nbsp; <span class="kw1">padding-left</span><span class="sy0">:</span><span class="re3">2px</span><span class="sy0">;</span><br />
&nbsp; <span class="kw1">font-family</span><span class="re2">:Verdana</span><span class="sy0">,</span> Geneva<span class="sy0">,</span> Arial<span class="sy0">,</span> Helvetica<span class="sy0">,</span> <span class="kw2">sans-serif</span><span class="sy0">;</span><br />
&nbsp; <span class="kw1">font-size</span><span class="sy0">:</span><span class="re3">1em</span><span class="sy0">;</span><span class="coMULTI">/* Resize Font*/</span><br />
&nbsp; <span class="kw1">width</span> <span class="sy0">:</span> <span class="re3">190px</span><span class="sy0">;</span> <span class="coMULTI">/* Resize Width */</span><br />
&nbsp; <span class="kw1">display</span> <span class="sy0">:</span> <span class="kw2">block</span><span class="sy0">;</span><br />
&nbsp; <span class="kw1">text-align</span><span class="sy0">:</span><span class="kw1">left</span><span class="sy0">;</span><br />
&nbsp; <span class="kw1">background</span><span class="sy0">:</span> <span class="kw2">url</span><span class="br0">&#40;</span><span class="st0">'bg_select.png'</span><span class="br0">&#41;</span> <span class="kw1">right</span><span class="sy0">;</span><br />
&nbsp; <span class="kw1">cursor</span><span class="sy0">:</span> <span class="kw2">pointer</span><span class="sy0">;</span><br />
&nbsp; <span class="kw1">border</span><span class="sy0">:</span><span class="re3">1px</span> <span class="kw2">solid</span> <span class="re0">#D1E4F6</span><span class="sy0">;</span><br />
&nbsp; <span class="kw1">color</span><span class="sy0">:</span><span class="re0">#333</span><span class="sy0">;</span><br />
<span class="br0">&#125;</span></div></td></tr></tbody></table></div>
<p>The full CSS file can be seen here:</p>
<div class="codecolorer-container css " style="overflow:auto;white-space:nowrap;width:580px"><table cellspacing="0" cellpadding="0"><tbody><tr><td class="line-numbers"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br /></div></td><td><div class="css codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="coMULTI">/* Drop down styles*/</span><br />
div<span class="re1">.selectbox-wrapper</span> <span class="br0">&#123;</span><br />
&nbsp; <span class="kw1">position</span><span class="sy0">:</span><span class="kw2">absolute</span><span class="sy0">;</span><br />
&nbsp; <span class="kw1">width</span><span class="sy0">:</span><span class="re3">400px</span><span class="sy0">;</span><br />
&nbsp; <span class="kw1">background-color</span><span class="sy0">:</span><span class="kw2">white</span><span class="sy0">;</span><br />
&nbsp; <span class="kw1">border</span><span class="sy0">:</span><span class="re3">1px</span> <span class="kw2">solid</span> <span class="re0">#ccc</span><span class="sy0">;</span><br />
&nbsp; <span class="kw1">margin</span><span class="sy0">:</span><span class="re3">0px</span><span class="sy0">;</span><br />
&nbsp; <span class="kw1">margin-top</span><span class="sy0">:</span><span class="re3">-10px</span><span class="sy0">;</span><br />
&nbsp; <span class="kw1">padding</span><span class="sy0">:</span><span class="re3">0px</span><span class="sy0">;</span><br />
&nbsp; <span class="kw1">text-align</span><span class="sy0">:</span><span class="kw1">left</span><span class="sy0">;</span><br />
&nbsp; <span class="kw1">max-height</span><span class="sy0">:</span><span class="re3">200px</span><span class="sy0">;</span><br />
&nbsp; <span class="kw1">overflow</span><span class="sy0">:</span><span class="kw2">auto</span><span class="sy0">;</span><br />
<span class="br0">&#125;</span><br />
<br />
<span class="coMULTI">/*Drop down list styles*/</span><br />
div<span class="re1">.selectbox-wrapper</span> ul <span class="br0">&#123;</span><br />
&nbsp; <span class="kw1">list-style-type</span><span class="sy0">:</span><span class="kw2">none</span><span class="sy0">;</span><br />
&nbsp; <span class="kw1">margin</span><span class="sy0">:</span><span class="re3">0px</span><span class="sy0">;</span><br />
&nbsp; <span class="kw1">padding</span><span class="sy0">:</span><span class="re3">0px</span><span class="sy0">;</span><br />
<span class="br0">&#125;</span><br />
<span class="coMULTI">/* Selected item in dropdown list*/</span><br />
div<span class="re1">.selectbox-wrapper</span> ul li<span class="re1">.selected</span> <span class="br0">&#123;</span><br />
&nbsp; <span class="kw1">background-color</span><span class="sy0">:</span> <span class="re0">#EAF2FB</span><span class="sy0">;</span><br />
<span class="br0">&#125;</span><br />
<br />
<span class="coMULTI">/* Hover state for dropdown list */</span><br />
div<span class="re1">.selectbox-wrapper</span> ul li<span class="re1">.current</span> <span class="br0">&#123;</span><br />
&nbsp; <span class="kw1">background-color</span><span class="sy0">:</span> <span class="re0">#CDD8E4</span><span class="sy0">;</span><br />
<span class="br0">&#125;</span><br />
<br />
<span class="coMULTI">/* Drop down list items style*/</span><br />
div<span class="re1">.selectbox-wrapper</span> ul li <span class="br0">&#123;</span><br />
&nbsp; <span class="kw1">list-style-type</span><span class="sy0">:</span><span class="kw2">none</span><span class="sy0">;</span><br />
&nbsp; <span class="kw1">display</span><span class="sy0">:</span><span class="kw2">block</span><span class="sy0">;</span><br />
&nbsp; <span class="kw1">margin</span><span class="sy0">:</span><span class="nu0">0</span><span class="sy0">;</span><br />
&nbsp; <span class="kw1">padding</span><span class="sy0">:</span><span class="re3">2px</span><span class="sy0">;</span><br />
&nbsp; <span class="kw1">cursor</span><span class="sy0">:</span><span class="kw2">pointer</span><span class="sy0">;</span><br />
<span class="br0">&#125;</span><br />
<br />
<span class="coMULTI">/* Look and feel of select box */</span><br />
<span class="re1">.selectbox</span><br />
<span class="br0">&#123;</span><br />
&nbsp; <span class="kw1">margin</span><span class="sy0">:</span> <span class="re3">0px</span> <span class="re3">5px</span> <span class="re3">10px</span> <span class="re3">0px</span><span class="sy0">;</span><br />
&nbsp; <span class="kw1">padding-left</span><span class="sy0">:</span><span class="re3">2px</span><span class="sy0">;</span><br />
&nbsp; <span class="kw1">font-family</span><span class="re2">:Verdana</span><span class="sy0">,</span> Geneva<span class="sy0">,</span> Arial<span class="sy0">,</span> Helvetica<span class="sy0">,</span> <span class="kw2">sans-serif</span><span class="sy0">;</span><br />
&nbsp; <span class="kw1">font-size</span><span class="sy0">:</span><span class="re3">1em</span><span class="sy0">;</span><span class="coMULTI">/* Resize Font*/</span><br />
&nbsp; <span class="kw1">width</span> <span class="sy0">:</span> <span class="re3">190px</span><span class="sy0">;</span> <span class="coMULTI">/* Resize Width */</span><br />
&nbsp; <span class="kw1">display</span> <span class="sy0">:</span> <span class="kw2">block</span><span class="sy0">;</span><br />
&nbsp; <span class="kw1">text-align</span><span class="sy0">:</span><span class="kw1">left</span><span class="sy0">;</span><br />
&nbsp; <span class="kw1">background</span><span class="sy0">:</span> <span class="kw2">url</span><span class="br0">&#40;</span><span class="st0">'bg_select.png'</span><span class="br0">&#41;</span> <span class="kw1">right</span><span class="sy0">;</span><br />
&nbsp; <span class="kw1">cursor</span><span class="sy0">:</span> <span class="kw2">pointer</span><span class="sy0">;</span><br />
&nbsp; <span class="kw1">border</span><span class="sy0">:</span><span class="re3">1px</span> <span class="kw2">solid</span> <span class="re0">#D1E4F6</span><span class="sy0">;</span><br />
&nbsp; <span class="kw1">color</span><span class="sy0">:</span><span class="re0">#333</span><span class="sy0">;</span><br />
<span class="br0">&#125;</span></div></td></tr></tbody></table></div>
<p>&#160;</p>
<h3>The Image</h3>
<p>The last thing we need to handle is creating the image that will be the background for our text box.  On the far left of the image is the button and to the left will be the background of the select box.  Here is the image we will be using.</p>
<p><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="bg_select" src="http://www.devirtuoso.com/wp-content/uploads/2009/08/bg_select_thumb.png" border="0" alt="bg_select" width="526" height="26" /></p>
<p>That’s it, after we’ve created the image we’re good to go.  I recommend looking at the plugin code to get an idea how it all works. This is a fantastic plugin so be sure to give your props over at  <a href="www.brainfault.com" target="_blank">www.brainfault.com</a> .</p>
<p>Here is the code all together.</p>
<div class="codecolorer-container html4strict " style="overflow:auto;white-space:nowrap;width:580px"><table cellspacing="0" cellpadding="0"><tbody><tr><td class="line-numbers"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br /></div></td><td><div class="html4strict codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="sc0">&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot;</span><br />
<span class="sc0"> &nbsp; &nbsp;&quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&quot;&gt;</span><br />
<span class="sc2">&lt;<a href="http://december.com/html/4/element/html.html"><span class="kw2">html</span></a>&gt;</span><br />
<span class="sc2">&lt;<a href="http://december.com/html/4/element/head.html"><span class="kw2">head</span></a>&gt;</span><br />
&nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/meta.html"><span class="kw2">meta</span></a> <span class="kw3">http-equiv</span><span class="sy0">=</span><span class="st0">&quot;Content-type&quot;</span> <span class="kw3">content</span><span class="sy0">=</span><span class="st0">&quot;text/html; charset=utf-8&quot;</span> <span class="sy0">/</span>&gt;</span><br />
&nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/title.html"><span class="kw2">title</span></a>&gt;</span>Styling Select Boxes<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/title.html"><span class="kw2">title</span></a>&gt;</span><br />
&nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/link.html"><span class="kw2">link</span></a> <span class="kw3">rel</span><span class="sy0">=</span><span class="st0">&quot;stylesheet&quot;</span> <span class="kw3">type</span><span class="sy0">=</span><span class="st0">&quot;text/css&quot;</span> <span class="kw3">href</span><span class="sy0">=</span><span class="st0">&quot;selectbox.css&quot;</span> <span class="sy0">/</span>&gt;</span><br />
&nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/script.html"><span class="kw2">script</span></a> <span class="kw3">src</span><span class="sy0">=</span><span class="st0">&quot;http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js&quot;</span> <span class="kw3">type</span><span class="sy0">=</span><span class="st0">&quot;text/javascript&quot;</span> <span class="kw3">charset</span><span class="sy0">=</span><span class="st0">&quot;utf-8&quot;</span>&gt;&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/script.html"><span class="kw2">script</span></a>&gt;</span><br />
&nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/script.html"><span class="kw2">script</span></a> <span class="kw3">type</span><span class="sy0">=</span><span class="st0">&quot;text/javascript&quot;</span> <span class="kw3">src</span><span class="sy0">=</span><span class="st0">&quot;jquery.selectbox-0.5.js&quot;</span>&gt;&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/script.html"><span class="kw2">script</span></a>&gt;</span><br />
&nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/script.html"><span class="kw2">script</span></a> <span class="kw3">type</span><span class="sy0">=</span><span class="st0">&quot;text/javascript&quot;</span>&gt;</span><br />
&nbsp; &nbsp; $(document).ready(function() {<br />
&nbsp; &nbsp; &nbsp; &nbsp; $('#Items').selectbox();<br />
&nbsp; &nbsp; });<br />
&nbsp; &nbsp; <span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/script.html"><span class="kw2">script</span></a>&gt;</span><br />
&nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/style.html"><span class="kw2">style</span></a> <span class="kw3">type</span><span class="sy0">=</span><span class="st0">&quot;text/css&quot;</span> <span class="kw3">media</span><span class="sy0">=</span><span class="st0">&quot;screen&quot;</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; body{<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; background-color: #111;<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; <span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/style.html"><span class="kw2">style</span></a>&gt;</span><br />
<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/head.html"><span class="kw2">head</span></a>&gt;</span><br />
<span class="sc2">&lt;<a href="http://december.com/html/4/element/body.html"><span class="kw2">body</span></a>&gt;</span><br />
&nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/select.html"><span class="kw2">select</span></a> <span class="kw3">name</span><span class="sy0">=</span><span class="st0">&quot;Items&quot;</span> <span class="kw3">id</span><span class="sy0">=</span><span class="st0">&quot;Items&quot;</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/option.html"><span class="kw2">option</span></a> <span class="kw3">value</span><span class="sy0">=</span><span class="st0">&quot;option1&quot;</span>&gt;</span>option1<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/option.html"><span class="kw2">option</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/option.html"><span class="kw2">option</span></a> <span class="kw3">value</span><span class="sy0">=</span><span class="st0">&quot;option2&quot;</span>&gt;</span>option2<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/option.html"><span class="kw2">option</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/option.html"><span class="kw2">option</span></a> <span class="kw3">value</span><span class="sy0">=</span><span class="st0">&quot;option3&quot;</span>&gt;</span>option3<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/option.html"><span class="kw2">option</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/option.html"><span class="kw2">option</span></a> <span class="kw3">value</span><span class="sy0">=</span><span class="st0">&quot;option4&quot;</span>&gt;</span>option4<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/option.html"><span class="kw2">option</span></a>&gt;</span><br />
&nbsp; &nbsp; <span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/select.html"><span class="kw2">select</span></a>&gt;</span><br />
<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/body.html"><span class="kw2">body</span></a>&gt;</span><br />
<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/html.html"><span class="kw2">html</span></a>&gt;</span></div></td></tr></tbody></table></div>
<p>The CSS:</p>
<div class="codecolorer-container css " style="overflow:auto;white-space:nowrap;width:580px"><table cellspacing="0" cellpadding="0"><tbody><tr><td class="line-numbers"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br /></div></td><td><div class="css codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="coMULTI">/* Drop down styles*/</span><br />
div<span class="re1">.selectbox-wrapper</span> <span class="br0">&#123;</span><br />
&nbsp; <span class="kw1">position</span><span class="sy0">:</span><span class="kw2">absolute</span><span class="sy0">;</span><br />
&nbsp; <span class="kw1">width</span><span class="sy0">:</span><span class="re3">400px</span><span class="sy0">;</span><br />
&nbsp; <span class="kw1">background-color</span><span class="sy0">:</span><span class="kw2">white</span><span class="sy0">;</span><br />
&nbsp; <span class="kw1">border</span><span class="sy0">:</span><span class="re3">1px</span> <span class="kw2">solid</span> <span class="re0">#ccc</span><span class="sy0">;</span><br />
&nbsp; <span class="kw1">margin</span><span class="sy0">:</span><span class="re3">0px</span><span class="sy0">;</span><br />
&nbsp; <span class="kw1">margin-top</span><span class="sy0">:</span><span class="re3">-10px</span><span class="sy0">;</span><br />
&nbsp; <span class="kw1">padding</span><span class="sy0">:</span><span class="re3">0px</span><span class="sy0">;</span><br />
&nbsp; <span class="kw1">text-align</span><span class="sy0">:</span><span class="kw1">left</span><span class="sy0">;</span><br />
&nbsp; <span class="kw1">max-height</span><span class="sy0">:</span><span class="re3">200px</span><span class="sy0">;</span><br />
&nbsp; <span class="kw1">overflow</span><span class="sy0">:</span><span class="kw2">auto</span><span class="sy0">;</span><br />
<span class="br0">&#125;</span><br />
<br />
<span class="coMULTI">/*Drop down list styles*/</span><br />
div<span class="re1">.selectbox-wrapper</span> ul <span class="br0">&#123;</span><br />
&nbsp; <span class="kw1">list-style-type</span><span class="sy0">:</span><span class="kw2">none</span><span class="sy0">;</span><br />
&nbsp; <span class="kw1">margin</span><span class="sy0">:</span><span class="re3">0px</span><span class="sy0">;</span><br />
&nbsp; <span class="kw1">padding</span><span class="sy0">:</span><span class="re3">0px</span><span class="sy0">;</span><br />
<span class="br0">&#125;</span><br />
<span class="coMULTI">/* Selected item in dropdown list*/</span><br />
div<span class="re1">.selectbox-wrapper</span> ul li<span class="re1">.selected</span> <span class="br0">&#123;</span><br />
&nbsp; <span class="kw1">background-color</span><span class="sy0">:</span> <span class="re0">#EAF2FB</span><span class="sy0">;</span><br />
<span class="br0">&#125;</span><br />
<br />
<span class="coMULTI">/* Hover state for dropdown list */</span><br />
div<span class="re1">.selectbox-wrapper</span> ul li<span class="re1">.current</span> <span class="br0">&#123;</span><br />
&nbsp; <span class="kw1">background-color</span><span class="sy0">:</span> <span class="re0">#CDD8E4</span><span class="sy0">;</span><br />
<span class="br0">&#125;</span><br />
<br />
<span class="coMULTI">/* Drop down list items style*/</span><br />
div<span class="re1">.selectbox-wrapper</span> ul li <span class="br0">&#123;</span><br />
&nbsp; <span class="kw1">list-style-type</span><span class="sy0">:</span><span class="kw2">none</span><span class="sy0">;</span><br />
&nbsp; <span class="kw1">display</span><span class="sy0">:</span><span class="kw2">block</span><span class="sy0">;</span><br />
&nbsp; <span class="kw1">margin</span><span class="sy0">:</span><span class="nu0">0</span><span class="sy0">;</span><br />
&nbsp; <span class="kw1">padding</span><span class="sy0">:</span><span class="re3">2px</span><span class="sy0">;</span><br />
&nbsp; <span class="kw1">cursor</span><span class="sy0">:</span><span class="kw2">pointer</span><span class="sy0">;</span><br />
<span class="br0">&#125;</span><br />
<br />
<span class="coMULTI">/* Look and feel of select box */</span><br />
<span class="re1">.selectbox</span><br />
<span class="br0">&#123;</span><br />
&nbsp; <span class="kw1">margin</span><span class="sy0">:</span> <span class="re3">0px</span> <span class="re3">5px</span> <span class="re3">10px</span> <span class="re3">0px</span><span class="sy0">;</span><br />
&nbsp; <span class="kw1">padding-left</span><span class="sy0">:</span><span class="re3">2px</span><span class="sy0">;</span><br />
&nbsp; <span class="kw1">font-family</span><span class="re2">:Verdana</span><span class="sy0">,</span> Geneva<span class="sy0">,</span> Arial<span class="sy0">,</span> Helvetica<span class="sy0">,</span> <span class="kw2">sans-serif</span><span class="sy0">;</span><br />
&nbsp; <span class="kw1">font-size</span><span class="sy0">:</span><span class="re3">1em</span><span class="sy0">;</span><span class="coMULTI">/* Resize Font*/</span><br />
&nbsp; <span class="kw1">width</span> <span class="sy0">:</span> <span class="re3">190px</span><span class="sy0">;</span> <span class="coMULTI">/* Resize Width */</span><br />
&nbsp; <span class="kw1">display</span> <span class="sy0">:</span> <span class="kw2">block</span><span class="sy0">;</span><br />
&nbsp; <span class="kw1">text-align</span><span class="sy0">:</span><span class="kw1">left</span><span class="sy0">;</span><br />
&nbsp; <span class="kw1">background</span><span class="sy0">:</span> <span class="kw2">url</span><span class="br0">&#40;</span><span class="st0">'bg_select.png'</span><span class="br0">&#41;</span> <span class="kw1">right</span><span class="sy0">;</span><br />
&nbsp; <span class="kw1">cursor</span><span class="sy0">:</span> <span class="kw2">pointer</span><span class="sy0">;</span><br />
&nbsp; <span class="kw1">border</span><span class="sy0">:</span><span class="re3">1px</span> <span class="kw2">solid</span> <span class="re0">#D1E4F6</span><span class="sy0">;</span><br />
&nbsp; <span class="kw1">color</span><span class="sy0">:</span><span class="re0">#333</span><span class="sy0">;</span><br />
<span class="br0">&#125;</span></div></td></tr></tbody></table></div>
<p>&#160;</p>
<div class="resources"><a class="Download" href="http://www.devirtuoso.com/Examples/Styling-Dropdown/example.zip" target="_blank">Download</a> <a class="Example" href="http://www.devirtuoso.com/Examples/Styling-Dropdown/" target="_blank">Example</a></div>
<p>&#160;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.devirtuoso.com/2009/08/styling-drop-down-boxes-with-jquery/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Contributing to the Death of IE6</title>
		<link>http://www.devirtuoso.com/2009/08/contributing-to-the-death-of-ie6/</link>
		<comments>http://www.devirtuoso.com/2009/08/contributing-to-the-death-of-ie6/#comments</comments>
		<pubDate>Wed, 05 Aug 2009 03:26:10 +0000</pubDate>
		<dc:creator>Shawn</dc:creator>
				<category><![CDATA[Front End Development]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[development Tools]]></category>
		<category><![CDATA[IE6]]></category>
		<category><![CDATA[JQuery]]></category>
		<category><![CDATA[tools]]></category>

		<guid isPermaLink="false">http://www.devirtuoso.com/?p=794</guid>
		<description><![CDATA[IE6 as every developer knows is a real pain. The website killie6.com has given an easy solution to help drive people away from using IE6.  Here is my spin on killie6’s module.

The Idea
I liked killie6’s module, but I think it has to be a little more in your face. Originally I thought having something like [...]]]></description>
			<content:encoded><![CDATA[<p>IE6 as every developer knows is a real pain. The website <a title="Kill IE 6" href="http://www.killie6.com/" target="_blank">killie6.com</a> has given an easy solution to help drive people away from using IE6.  Here is my spin on killie6’s module.</p>
<p><span id="more-794"></span></p>
<h3>The Idea</h3>
<p>I liked killie6’s module, but I think it has to be a little more in your face. Originally I thought having something like a humorous 404 page would do the trick, but that would kill any sort of navigation of your site.  So I opted to create a lightbox that pops up if you’re using IE6, make the user feel painfully guilty for using IE6, then give them a way to upgrade right then and there.  Hopefully this will get the idea across to users not to use IE6.</p>
<div class="resources"><a href="http://www.devirtuoso.com/Examples/Kill-IE6/example.zip" target="_blank" class="Download">Download</a><a class="Example" href="http://www.devirtuoso.com/Examples/Kill-IE6/" target="_blank">Example</a></div>
<p><a title="Kill IE6" href="http://www.devirtuoso.com/Examples/Kill-IE6/" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" src="http://www.devirtuoso.com/wp-content/uploads/2009/08/image_thumb.png" border="0" alt="image" width="355" height="502" /></a></p>
<p>If you like this idea please download and use it.  If you want something less obtrusive go with <a title="Kill IE 6" href="http://www.killie6.com/" target="_blank">killie6.com</a>.  Something has to be done, the browser is driving everyone CRAZY!…okay maybe not everyone…probably just me. <img src='http://www.devirtuoso.com/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.devirtuoso.com/2009/08/contributing-to-the-death-of-ie6/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>How To Build an Animated Header in jQuery</title>
		<link>http://www.devirtuoso.com/2009/07/how-to-build-an-animated-header-in-jquery/</link>
		<comments>http://www.devirtuoso.com/2009/07/how-to-build-an-animated-header-in-jquery/#comments</comments>
		<pubDate>Thu, 30 Jul 2009 19:25:46 +0000</pubDate>
		<dc:creator>Shawn</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[Front End Development]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[JQuery]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://www.devirtuoso.com/?p=775</guid>
		<description><![CDATA[Why not give a little flair to your header.&#160; This tutorial will show you how to animate your header’s background image using jQuery to give your website that little extra something.

What We Are Building
We are going to build a header that animates it’s background.&#160; We will also encase the header in shadow for the little [...]]]></description>
			<content:encoded><![CDATA[<p>Why not give a little flair to your header.&#160; This tutorial will show you how to <strong>animate your header’s background image using jQuery</strong> to give your website that little extra something.</p>
<p><span id="more-775"></span></p>
<h3>What We Are Building</h3>
<p>We are going to build a header that animates it’s background.&#160; We will also encase the header in shadow for the little extra dramatic effect.</p>
<div class="resources"><a class="Download" href="http://www.devirtuoso.com/Examples/jQuery-Animated-Header/example.zip" target="_blank">Download</a><a class="Example" href="http://www.devirtuoso.com/Examples/jQuery-Animated-Header/" target="_blank">Example</a></div>
<p><a class="Example" href="http://www.devirtuoso.com/Examples/jQuery-Animated-Header/" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Animated Header Background" border="0" alt="Animated Header Background" src="http://www.devirtuoso.com/wp-content/uploads/2009/07/image29.png" width="583" height="265" /></a> </p>
<p>&#160;</p>
<h3>How it’s Going to Work</h3>
<p>The header background image is going to be super tall. Here is the important part, we’re making a header that is 300px tall.&#160; The image’s top 300px and bottom 300px have to be the same.&#160; This will allow us to scroll our header seamlessly.&#160; So dust of your Photoshop skills you’re going to need them.&#160; Not to fret, it’s not that difficult.&#160; Just copy the top 300px of your image and paste them on the bottom.&#160; Then blend what was originally on your background with what you pasted in.</p>
<p><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Header Background Instructions" border="0" alt="Header Background Instructions" src="http://www.devirtuoso.com/wp-content/uploads/2009/07/image30.png" width="345" height="538" /> </p>
<p>&#160;</p>
<p>Now that we have our background image, we will also need to create a shadow overlay image. This will basically be a png with a transparent center that gradually turns to black on the edges.&#160; With the CSS we are going to lay this on top of our header to give a dramatic effect.</p>
<p><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Header Overlay Diagram" border="0" alt="Header Overlay Diagram" src="http://www.devirtuoso.com/wp-content/uploads/2009/07/image31.png" width="412" height="251" /> </p>
<p>&#160;</p>
<p>After that it’s just a matter of animating the background image with jQuery so it scrolls.</p>
<h3>&#160;</h3>
<h3>Getting Started</h3>
<p>The first thing we’re going to need is the HTML in place.&#160; It’s pretty straight forward.&#160; We have a wrapper div to center the website, a header div for the animation, another div within the header for the shadow overlay, and finally divs for the navigation and body copy.&#160; It’s a lot of divs, but what do you expect, it’s the framework <img src='http://www.devirtuoso.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>Here is the <strong>HTML</strong>:</p>
<div class="codecolorer-container html4strict " style="overflow:auto;white-space:nowrap;width:580px"><table cellspacing="0" cellpadding="0"><tbody><tr><td class="line-numbers"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br /></div></td><td><div class="html4strict codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="sc0">&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot;</span><br />
<span class="sc0">&nbsp; &nbsp; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&quot;&gt;</span><br />
<span class="sc2">&lt;<a href="http://december.com/html/4/element/html.html"><span class="kw2">html</span></a>&gt;</span><br />
<span class="sc2">&lt;<a href="http://december.com/html/4/element/head.html"><span class="kw2">head</span></a>&gt;</span><br />
&nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/meta.html"><span class="kw2">meta</span></a> <span class="kw3">http-equiv</span><span class="sy0">=</span><span class="st0">&quot;Content-type&quot;</span> <span class="kw3">content</span><span class="sy0">=</span><span class="st0">&quot;text/html; charset=utf-8&quot;</span> <span class="sy0">/</span>&gt;</span><br />
&nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/title.html"><span class="kw2">title</span></a>&gt;</span>Animated Header<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/title.html"><span class="kw2">title</span></a>&gt;</span><br />
<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/head.html"><span class="kw2">head</span></a>&gt;</span><br />
<br />
<span class="sc2">&lt;<a href="http://december.com/html/4/element/body.html"><span class="kw2">body</span></a>&gt;</span><br />
&nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/div.html"><span class="kw2">div</span></a> <span class="kw3">id</span><span class="sy0">=</span><span class="st0">&quot;wrapper&quot;</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/div.html"><span class="kw2">div</span></a> <span class="kw3">id</span><span class="sy0">=</span><span class="st0">&quot;header&quot;</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc-1">&lt;!-- Div is for Shadow Overlay--&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/div.html"><span class="kw2">div</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc-1">&lt;!-- Title --&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/h1.html"><span class="kw2">h1</span></a>&gt;</span>Animated Header Background<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/h1.html"><span class="kw2">h1</span></a>&gt;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/div.html"><span class="kw2">div</span></a>&gt;</span>&nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/div.html"><span class="kw2">div</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/div.html"><span class="kw2">div</span></a> <span class="kw3">id</span><span class="sy0">=</span><span class="st0">&quot;nav&quot;</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc-1">&lt;!-- Navigation Goes HERE --&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/div.html"><span class="kw2">div</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/div.html"><span class="kw2">div</span></a> <span class="kw3">id</span><span class="sy0">=</span><span class="st0">&quot;body&quot;</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc-1">&lt;!-- Body Content Goes HERE --&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/div.html"><span class="kw2">div</span></a>&gt;</span><br />
&nbsp; &nbsp; <span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/div.html"><span class="kw2">div</span></a>&gt;</span><br />
<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/body.html"><span class="kw2">body</span></a>&gt;</span> &nbsp; &nbsp; <br />
<br />
<span class="sc-1">&lt;!-- Import jQuery--&gt;</span><br />
<span class="sc2">&lt;<a href="http://december.com/html/4/element/script.html"><span class="kw2">script</span></a> <span class="kw3">src</span><span class="sy0">=</span><span class="st0">&quot;http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js&quot;</span> <span class="kw3">type</span><span class="sy0">=</span><span class="st0">&quot;text/javascript&quot;</span> <span class="kw3">charset</span><span class="sy0">=</span><span class="st0">&quot;utf-8&quot;</span>&gt;&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/script.html"><span class="kw2">script</span></a>&gt;</span>&nbsp; <br />
<br />
<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/html.html"><span class="kw2">html</span></a>&gt;</span></div></td></tr></tbody></table></div>
<p>&#160;</p>
<h3>The CSS</h3>
<p>We aren&#8217;t going to do anything too difficult here. Here is a list of what was done:</p>
<ul>
<li>Center the website </li>
<li>Give the header a height and a background image </li>
<li>Style and position the text within the header </li>
<li>Create a shadow overlay </li>
<li>Give basic style to the header and navigation bar. </li>
</ul>
<p>Here is the <strong>CSS</strong>:</p>
<div class="codecolorer-container css " style="overflow:auto;white-space:nowrap;width:580px"><table cellspacing="0" cellpadding="0"><tbody><tr><td class="line-numbers"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br /></div></td><td><div class="css codecolorer" style="font-family:Monaco,Lucida Console,monospace">body<span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw1">background-color</span><span class="sy0">:</span> <span class="re0">#000</span><span class="sy0">;</span><br />
<span class="br0">&#125;</span><br />
<br />
<span class="coMULTI">/* Center the website */</span><br />
<span class="re0">#wrapper</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw1">width</span><span class="sy0">:</span><span class="re3">920px</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="kw1">margin</span><span class="sy0">:</span><span class="nu0">0</span> <span class="kw2">auto</span><span class="sy0">;</span><br />
<span class="br0">&#125;</span><br />
<br />
<span class="coMULTI">/* Give the header a height and a background image */</span><br />
<span class="re0">#header</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw1">height</span><span class="sy0">:</span><span class="re3">300px</span><span class="sy0">;</span> <br />
&nbsp; &nbsp; <span class="kw1">background</span><span class="sy0">:</span> <span class="re0">#000</span> <span class="kw2">url</span><span class="br0">&#40;</span><span class="co2">background.jpg</span><span class="br0">&#41;</span> <span class="kw2">repeat-y</span> <span class="kw2">scroll</span> <span class="kw1">left</span> <span class="kw1">top</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="kw1">text-align</span><span class="sy0">:</span><span class="kw2">center</span><span class="sy0">;</span><br />
<span class="br0">&#125;</span><br />
<br />
<span class="coMULTI">/* Create a Shadow Overlay */</span> <br />
<span class="re0">#header</span> div<span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw1">width</span><span class="sy0">:</span><span class="re3">920px</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="kw1">height</span><span class="sy0">:</span><span class="re3">300px</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="kw1">background</span><span class="sy0">:</span> <span class="kw2">transparent</span> <span class="kw2">url</span><span class="br0">&#40;</span><span class="co2">overlay.png</span><span class="br0">&#41;</span> <span class="kw2">no-repeat</span> <span class="kw2">scroll</span> <span class="kw1">left</span> <span class="kw1">top</span><span class="sy0">;</span><br />
<span class="br0">&#125;</span><br />
<br />
<span class="coMULTI">/* Vertically position header text and style it*/</span><br />
<span class="re0">#header</span> h1<span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw1">padding-top</span><span class="sy0">:</span><span class="re3">125px</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="kw1">font-family</span><span class="sy0">:</span> Arial<span class="sy0">,</span> <span class="st0">&quot;MS Trebuchet&quot;</span><span class="sy0">,</span> <span class="kw2">sans-serif</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="kw1">color</span><span class="sy0">:</span><span class="kw2">white</span><span class="sy0">;</span><br />
<span class="br0">&#125;</span><br />
<br />
<span class="coMULTI">/* Give basic styles to the body and the navigation */</span><br />
<span class="re0">#body</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw1">background-color</span><span class="sy0">:</span><span class="re0">#efefef</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="kw1">height</span><span class="sy0">:</span><span class="re3">500px</span><span class="sy0">;</span><br />
<span class="br0">&#125;</span><br />
<span class="re0">#nav</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw1">height</span><span class="sy0">:</span><span class="re3">35px</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="kw1">background-color</span><span class="sy0">:</span> <span class="re0">#111</span><span class="sy0">;</span><br />
<span class="br0">&#125;</span></div></td></tr></tbody></table></div>
<p>&#160;</p>
<p>Just a note, the png transparency won’t work in IE6.&#160; If you choose to optimize for IE6 you will need to add this piece of code to use the overlay.</p>
<p><strong>HTML</strong>:</p>
<div class="codecolorer-container html4strict " style="overflow:auto;white-space:nowrap;width:580px"><table cellspacing="0" cellpadding="0"><tbody><tr><td class="line-numbers"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br /></div></td><td><div class="html4strict codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="sc-1">&lt;!--[if lte IE 6]&gt;</span><br />
<span class="sc-1">&nbsp; &nbsp; &lt;style type=&quot;text/css&quot; media=&quot;screen&quot;&gt;</span><br />
<span class="sc-1">&nbsp; &nbsp; &nbsp; &nbsp; #header div{</span><br />
<span class="sc-1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; background-image: none;</span><br />
<span class="sc-1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='overlay.png', sizingMethod='scale');</span><br />
<span class="sc-1">&nbsp; &nbsp; &nbsp; &nbsp; }</span><br />
<span class="sc-1">&nbsp; &nbsp; &lt;/style&gt;</span><br />
<span class="sc-1">&lt;![endif]--&gt;</span></div></td></tr></tbody></table></div>
<p>&#160;</p>
<h3>The jQuery</h3>
</p>
<p>There are a couple ways of animating the background with jQuery.&#160; You can use the jQuery plugin that allows you to animate the CSS background-position attribute.&#160; This is the same plugin we used for <a title="How to create a table row highlighter using jQuery" href="http://www.devirtuoso.com/2009/06/how-to-create-a-table-row-highlighter-using-jquery/" target="_blank">making a table row highlighter in jQuery</a>. I opted not to use this as I found the performance was lagging.&#160; Instead I went with an interval that calls a function repeatedly.&#160; It’s a little uglier to look at but the performance is a lot better.</p>
<p>Here is the <strong>jQuery</strong>:</p>
<div class="codecolorer-container javascript " style="overflow:auto;white-space:nowrap;width:580px"><table cellspacing="0" cellpadding="0"><tbody><tr><td class="line-numbers"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br /></div></td><td><div class="javascript codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="kw2">var</span> scrollSpeed <span class="sy0">=</span> <span class="nu0">70</span><span class="sy0">;</span> &nbsp; &nbsp; &nbsp; <span class="co1">// Speed in milliseconds</span><br />
<span class="kw2">var</span> step <span class="sy0">=</span> <span class="nu0">1</span><span class="sy0">;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// How many pixels to move per step</span><br />
<span class="kw2">var</span> current <span class="sy0">=</span> <span class="nu0">0</span><span class="sy0">;</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// The current pixel row</span><br />
<span class="kw2">var</span> imageHeight <span class="sy0">=</span> <span class="nu0">4300</span><span class="sy0">;</span> &nbsp; &nbsp; <span class="co1">// Background image height</span><br />
<span class="kw2">var</span> headerHeight <span class="sy0">=</span> <span class="nu0">300</span><span class="sy0">;</span> &nbsp; &nbsp; <span class="co1">// How tall the header is.</span><br />
<br />
<span class="co1">//The pixel row where to start a new loop</span><br />
<span class="kw2">var</span> restartPosition <span class="sy0">=</span> <span class="sy0">-</span><span class="br0">&#40;</span>imageHeight <span class="sy0">-</span> headerHeight<span class="br0">&#41;</span><span class="sy0">;</span><br />
<br />
<span class="kw2">function</span> scrollBg<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span class="co1">//Go to next pixel row.</span><br />
&nbsp; &nbsp; current <span class="sy0">-=</span> step<span class="sy0">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span class="co1">//If at the end of the image, then go to the top.</span><br />
&nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>current <span class="sy0">==</span> restartPosition<span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; current <span class="sy0">=</span> <span class="nu0">0</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span class="co1">//Set the CSS of the header.</span><br />
&nbsp; &nbsp; $<span class="br0">&#40;</span><span class="st0">'#header'</span><span class="br0">&#41;</span>.<span class="me1">css</span><span class="br0">&#40;</span><span class="st0">&quot;background-position&quot;</span><span class="sy0">,</span><span class="st0">&quot;0 &quot;</span><span class="sy0">+</span>current<span class="sy0">+</span><span class="st0">&quot;px&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <br />
<span class="br0">&#125;</span><br />
<br />
<span class="co1">//Calls the scrolling function repeatedly</span><br />
<span class="kw2">var</span> init <span class="sy0">=</span> setInterval<span class="br0">&#40;</span><span class="st0">&quot;scrollBg()&quot;</span><span class="sy0">,</span> scrollSpeed<span class="br0">&#41;</span><span class="sy0">;</span></div></td></tr></tbody></table></div>
<p>&#160;</p>
<h3>Bring it All Together</h3>
<p>That’s all there is to it.&#160; Here is the code all together.</p>
<div class="codecolorer-container html4strict " style="overflow:auto;white-space:nowrap;width:580px"><table cellspacing="0" cellpadding="0"><tbody><tr><td class="line-numbers"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br />83<br />84<br />85<br />86<br />87<br />88<br />89<br />90<br />91<br />92<br />93<br />94<br />95<br />96<br />97<br />98<br />99<br />100<br />101<br />102<br />103<br />104<br />105<br />106<br />107<br />108<br />109<br />110<br />111<br />112<br />113<br />114<br />115<br />116<br />117<br />118<br /></div></td><td><div class="html4strict codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="sc0">&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot;</span><br />
<span class="sc0">&quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&quot;&gt;</span><br />
<span class="sc2">&lt;<a href="http://december.com/html/4/element/html.html"><span class="kw2">html</span></a>&gt;</span><br />
<span class="sc2">&lt;<a href="http://december.com/html/4/element/head.html"><span class="kw2">head</span></a>&gt;</span><br />
<span class="sc2">&lt;<a href="http://december.com/html/4/element/meta.html"><span class="kw2">meta</span></a> <span class="kw3">http-equiv</span><span class="sy0">=</span><span class="st0">&quot;Content-type&quot;</span> <span class="kw3">content</span><span class="sy0">=</span><span class="st0">&quot;text/html; charset=utf-8&quot;</span> <span class="sy0">/</span>&gt;</span><br />
<span class="sc2">&lt;<a href="http://december.com/html/4/element/title.html"><span class="kw2">title</span></a>&gt;</span>Animated Header<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/title.html"><span class="kw2">title</span></a>&gt;</span><br />
<span class="sc2">&lt;<a href="http://december.com/html/4/element/style.html"><span class="kw2">style</span></a> <span class="kw3">type</span><span class="sy0">=</span><span class="st0">&quot;text/css&quot;</span> <span class="kw3">media</span><span class="sy0">=</span><span class="st0">&quot;screen&quot;</span>&gt;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; body{<br />
&nbsp; &nbsp; &nbsp; &nbsp; background-color: #000;<br />
&nbsp; &nbsp; }<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; /* Center the website */<br />
&nbsp; &nbsp; #wrapper{<br />
&nbsp; &nbsp; &nbsp; &nbsp; width:920px;<br />
&nbsp; &nbsp; &nbsp; &nbsp; margin:0 auto;<br />
&nbsp; &nbsp; }<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; /* Give the header a height and a background image */<br />
&nbsp; &nbsp; #header{<br />
&nbsp; &nbsp; &nbsp; &nbsp; height:300px; <br />
&nbsp; &nbsp; &nbsp; &nbsp; background: #000 url(background.jpg) repeat-y scroll left top;<br />
&nbsp; &nbsp; &nbsp; &nbsp; text-align:center;<br />
&nbsp; &nbsp; }<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; /* Create a Shadow Overlay */ <br />
&nbsp; &nbsp; #header div{<br />
&nbsp; &nbsp; &nbsp; &nbsp; width:920px;<br />
&nbsp; &nbsp; &nbsp; &nbsp; height:300px;<br />
&nbsp; &nbsp; &nbsp; &nbsp; background: transparent url(overlay.png) no-repeat scroll left top;<br />
&nbsp; &nbsp; }<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; /* Vertically position header text and style it*/<br />
&nbsp; &nbsp; #header h1{<br />
&nbsp; &nbsp; &nbsp; &nbsp; padding-top:125px;<br />
&nbsp; &nbsp; &nbsp; &nbsp; font-family: Arial, &quot;MS Trebuchet&quot;, sans-serif;<br />
&nbsp; &nbsp; &nbsp; &nbsp; color:white;<br />
&nbsp; &nbsp; }<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; /* Give basic styles to the body and the navigation */<br />
&nbsp; &nbsp; #body{<br />
&nbsp; &nbsp; &nbsp; &nbsp; background-color:#efefef;<br />
&nbsp; &nbsp; &nbsp; &nbsp; height:500px;<br />
&nbsp; &nbsp; }<br />
&nbsp; &nbsp; #nav{<br />
&nbsp; &nbsp; &nbsp; &nbsp; height:35px;<br />
&nbsp; &nbsp; &nbsp; &nbsp; background-color: #111;<br />
&nbsp; &nbsp; }<br />
&nbsp; &nbsp; <br />
<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/style.html"><span class="kw2">style</span></a>&gt;</span><br />
<br />
<span class="sc-1">&lt;!--[if lte IE 6]&gt;</span><br />
<span class="sc-1">&nbsp; &nbsp; &lt;style type=&quot;text/css&quot; media=&quot;screen&quot;&gt;</span><br />
<span class="sc-1">&nbsp; &nbsp; &nbsp; &nbsp; #header div{</span><br />
<span class="sc-1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; background-image: none;</span><br />
<span class="sc-1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='overlay.png', sizingMethod='scale');</span><br />
<span class="sc-1">&nbsp; &nbsp; &nbsp; &nbsp; }</span><br />
<span class="sc-1">&nbsp; &nbsp; &lt;/style&gt;</span><br />
<span class="sc-1">&lt;![endif]--&gt;</span><br />
<br />
<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/head.html"><span class="kw2">head</span></a>&gt;</span><br />
<br />
<span class="sc2">&lt;<a href="http://december.com/html/4/element/body.html"><span class="kw2">body</span></a>&gt;</span><br />
&nbsp; &nbsp; <br />
<span class="sc2">&lt;<a href="http://december.com/html/4/element/div.html"><span class="kw2">div</span></a> <span class="kw3">id</span><span class="sy0">=</span><span class="st0">&quot;wrapper&quot;</span>&gt;</span><br />
&nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/div.html"><span class="kw2">div</span></a> <span class="kw3">id</span><span class="sy0">=</span><span class="st0">&quot;header&quot;</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc-1">&lt;!-- Div is for Shadow Overlay--&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/div.html"><span class="kw2">div</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/h1.html"><span class="kw2">h1</span></a>&gt;</span>Animated Header Background<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/h1.html"><span class="kw2">h1</span></a>&gt;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/div.html"><span class="kw2">div</span></a>&gt;</span>&nbsp; <br />
&nbsp; &nbsp; <span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/div.html"><span class="kw2">div</span></a>&gt;</span><br />
&nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/div.html"><span class="kw2">div</span></a> <span class="kw3">id</span><span class="sy0">=</span><span class="st0">&quot;nav&quot;</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc-1">&lt;!-- Navigation Goes HERE --&gt;</span><br />
&nbsp; &nbsp; <span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/div.html"><span class="kw2">div</span></a>&gt;</span><br />
&nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/div.html"><span class="kw2">div</span></a> <span class="kw3">id</span><span class="sy0">=</span><span class="st0">&quot;body&quot;</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc-1">&lt;!-- Body Content Goes HERE --&gt;</span><br />
&nbsp; &nbsp; <span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/div.html"><span class="kw2">div</span></a>&gt;</span><br />
<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/div.html"><span class="kw2">div</span></a>&gt;</span><br />
<br />
<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/body.html"><span class="kw2">body</span></a>&gt;</span> &nbsp; &nbsp; <br />
<br />
<span class="sc-1">&lt;!-- Import jQuery--&gt;</span><br />
<span class="sc2">&lt;<a href="http://december.com/html/4/element/script.html"><span class="kw2">script</span></a> <span class="kw3">src</span><span class="sy0">=</span><span class="st0">&quot;http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js&quot;</span> <span class="kw3">type</span><span class="sy0">=</span><span class="st0">&quot;text/javascript&quot;</span> <span class="kw3">charset</span><span class="sy0">=</span><span class="st0">&quot;utf-8&quot;</span>&gt;&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/script.html"><span class="kw2">script</span></a>&gt;</span><br />
<br />
<span class="sc2">&lt;<a href="http://december.com/html/4/element/script.html"><span class="kw2">script</span></a> <span class="kw3">type</span><span class="sy0">=</span><span class="st0">&quot;text/javascript&quot;</span> <span class="kw3">charset</span><span class="sy0">=</span><span class="st0">&quot;utf-8&quot;</span>&gt;</span><br />
<br />
&nbsp; &nbsp; var scrollSpeed = 70; &nbsp; &nbsp; &nbsp; // Speed in milliseconds<br />
&nbsp; &nbsp; var step = 1; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // How many pixels to move per step<br />
&nbsp; &nbsp; var current = 0;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // The current pixel row<br />
&nbsp; &nbsp; var imageHeight = 4300; &nbsp; &nbsp; // Background image height<br />
&nbsp; &nbsp; var headerHeight = 300; &nbsp; &nbsp; // How tall the header is.<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; //The pixel row where to start a new loop<br />
&nbsp; &nbsp; var restartPosition = -(imageHeight - headerHeight);<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; function scrollBg(){<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; //Go to next pixel row.<br />
&nbsp; &nbsp; &nbsp; &nbsp; current -= step;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; //If at the end of the image, then go to the top.<br />
&nbsp; &nbsp; &nbsp; &nbsp; if (current == restartPosition){<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; current = 0;<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; //Set the CSS of the header.<br />
&nbsp; &nbsp; &nbsp; &nbsp; $('#header').css(&quot;background-position&quot;,&quot;0 &quot;+current+&quot;px&quot;);<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; }<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; //Calls the scrolling function repeatedly<br />
&nbsp; &nbsp; var init = setInterval(&quot;scrollBg()&quot;, scrollSpeed);<br />
&nbsp; &nbsp; <br />
<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/script.html"><span class="kw2">script</span></a>&gt;</span> &nbsp; <br />
<br />
<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/html.html"><span class="kw2">html</span></a>&gt;</span></div></td></tr></tbody></table></div>
<p>&#160;</p>
<div class="resources"><a class="Download" href="http://www.devirtuoso.com/Examples/jQuery-Animated-Header/example.zip" target="_blank">Download</a><a class="Example" href="http://www.devirtuoso.com/Examples/jQuery-Animated-Header/" target="_blank">Example</a></div>
<p>&#160;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.devirtuoso.com/2009/07/how-to-build-an-animated-header-in-jquery/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>How to Build a CSS Image Viewer the Clever Way</title>
		<link>http://www.devirtuoso.com/2009/07/how-to-build-a-css-image-viewer-the-clever-way/</link>
		<comments>http://www.devirtuoso.com/2009/07/how-to-build-a-css-image-viewer-the-clever-way/#comments</comments>
		<pubDate>Sat, 25 Jul 2009 12:44:38 +0000</pubDate>
		<dc:creator>Shawn</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[Front End Development]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[web development]]></category>

		<guid isPermaLink="false">http://www.devirtuoso.com/?p=745</guid>
		<description><![CDATA[Image Viewers are fairly common on websites now-a-days. Most use some form of JavaScript to change images, some use Flash. This is a problem if the user doesn’t have either enabled on their browser.&#160; In this tutorial we’ll cover how to create an image viewer with only using CSS and HTML.

What We Are Building
We be [...]]]></description>
			<content:encoded><![CDATA[<p>Image Viewers are fairly common on websites now-a-days. Most use some form of JavaScript to change images, some use Flash. This is a problem if the user doesn’t have either enabled on their browser.&#160; In this tutorial we’ll cover how to create <strong>an image viewer with only using CSS and HTML</strong>.</p>
<p><span id="more-745"></span></p>
<h3>What We Are Building</h3>
<p>We be making a <strong>simple image viewer</strong> that has 4 tabs on the left and a main picture on the right.&#160; When the user clicks on one of the tabs it shows the new image.    </p>
<div class="resources"><a title="CSS Image Viewer Download" href="http://www.devirtuoso.com/Examples/CSS-Image-Viewer/CSS-Image-Viewer.zip" class="Download" target="_blank">Download</a><a title="CSS Image Viewer" href="http://www.devirtuoso.com/Examples/CSS-Image-Viewer/" target="_blank" class="Example">Example</a></div>
<p><a title="CSS Image Viewer" href="http://www.devirtuoso.com/Examples/CSS-Image-Viewer/" target="_blank"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://www.devirtuoso.com/wp-content/uploads/2009/07/image27.png" width="563" height="363" /></a> </p>
<p>&#160;</p>
<h3>Prepping the Images</h3>
<p>First thing we’ll need are images.&#160; In this example I’ve used landscape images, but this could be promotional content, or whatever you like.&#160; I made the main image 500&#215;300, and the tabs 75&#215;125.&#160; I just picked a size for the main image, than divided the height by how many tabs I wanted. (e.g.. 300 / 4 = 75)&#160; This gives me the height of my tabs. The width of tab was arbitrary, I just resized the main image to the height of 75 and the width is whatever it falls at, in this case 125.</p>
<p>&#160;</p>
<h3>The Theory</h3>
<p>The theory behind how this is all going to work really isn’t that difficult.&#160; We’re going to use anchor tags to jump from one image to the next. This is much like a “Back to Top” link that jumps to the top of the page when you click on it.&#160; The only difference is the images are going to be scrolling within a div wrapper instead up jumping up and down the page.</p>
<p>&#160;</p>
<p><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://www.devirtuoso.com/wp-content/uploads/2009/07/image28.png" width="605" height="746" /> </p>
<p>&#160;</p>
<h3>The HTML</h3>
<p>The HTML itself is pretty simple.&#160; For the tabs it’s just an unordered list, with images inside of anchor tags. For the images they’re all wrapped in a div (this is important as we are going to hide the overflow so it only displays your selected image) Also each individual image is wrapped in a div along with a named anchor tag.&#160; These divs are there incase you want to use background images instead of regular images, we really don’t need them in this instance, they’re just there incase we change our mind.</p>
<p>Here is the <strong>HTML</strong>:</p>
<div class="codecolorer-container html4strict " style="overflow:auto;white-space:nowrap;width:580px"><table cellspacing="0" cellpadding="0"><tbody><tr><td class="line-numbers"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br /></div></td><td><div class="html4strict codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="sc2">&lt;<a href="http://december.com/html/4/element/div.html"><span class="kw2">div</span></a> <span class="kw3">id</span><span class="sy0">=</span><span class="st0">&quot;wrapper&quot;</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc-1">&lt;!-- Tabs --&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/ul.html"><span class="kw2">ul</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;&lt;<a href="http://december.com/html/4/element/a.html"><span class="kw2">a</span></a> <span class="kw3">href</span><span class="sy0">=</span><span class="st0">&quot;#image1&quot;</span> <span class="kw3">id</span><span class="sy0">=</span><span class="st0">&quot;tab1&quot;</span>&gt;&lt;<a href="http://december.com/html/4/element/img.html"><span class="kw2">img</span></a> <span class="kw3">src</span><span class="sy0">=</span><span class="st0">&quot;tab1.jpg&quot;</span> <span class="kw3">alt</span><span class="sy0">=</span><span class="st0">&quot;&quot;</span> <span class="kw3">title</span><span class="sy0">=</span><span class="st0">&quot;&quot;</span> <span class="sy0">/</span>&gt;&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/a.html"><span class="kw2">a</span></a>&gt;&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;&lt;<a href="http://december.com/html/4/element/a.html"><span class="kw2">a</span></a> <span class="kw3">href</span><span class="sy0">=</span><span class="st0">&quot;#image2&quot;</span> <span class="kw3">id</span><span class="sy0">=</span><span class="st0">&quot;tab2&quot;</span>&gt;&lt;<a href="http://december.com/html/4/element/img.html"><span class="kw2">img</span></a> <span class="kw3">src</span><span class="sy0">=</span><span class="st0">&quot;tab2.jpg&quot;</span> <span class="kw3">alt</span><span class="sy0">=</span><span class="st0">&quot;&quot;</span> <span class="kw3">title</span><span class="sy0">=</span><span class="st0">&quot;&quot;</span> <span class="sy0">/</span>&gt;&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/a.html"><span class="kw2">a</span></a>&gt;&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;&lt;<a href="http://december.com/html/4/element/a.html"><span class="kw2">a</span></a> <span class="kw3">href</span><span class="sy0">=</span><span class="st0">&quot;#image3&quot;</span> <span class="kw3">id</span><span class="sy0">=</span><span class="st0">&quot;tab3&quot;</span>&gt;&lt;<a href="http://december.com/html/4/element/img.html"><span class="kw2">img</span></a> <span class="kw3">src</span><span class="sy0">=</span><span class="st0">&quot;tab3.jpg&quot;</span> <span class="kw3">alt</span><span class="sy0">=</span><span class="st0">&quot;&quot;</span> <span class="kw3">title</span><span class="sy0">=</span><span class="st0">&quot;&quot;</span> <span class="sy0">/</span>&gt;&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/a.html"><span class="kw2">a</span></a>&gt;&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;&lt;<a href="http://december.com/html/4/element/a.html"><span class="kw2">a</span></a> <span class="kw3">href</span><span class="sy0">=</span><span class="st0">&quot;#image4&quot;</span> <span class="kw3">id</span><span class="sy0">=</span><span class="st0">&quot;tab4&quot;</span>&gt;&lt;<a href="http://december.com/html/4/element/img.html"><span class="kw2">img</span></a> <span class="kw3">src</span><span class="sy0">=</span><span class="st0">&quot;tab4.jpg&quot;</span> <span class="kw3">alt</span><span class="sy0">=</span><span class="st0">&quot;&quot;</span> <span class="kw3">title</span><span class="sy0">=</span><span class="st0">&quot;&quot;</span> <span class="sy0">/</span>&gt;&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/a.html"><span class="kw2">a</span></a>&gt;&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/ul.html"><span class="kw2">ul</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc-1">&lt;!-- Images --&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/div.html"><span class="kw2">div</span></a> <span class="kw3">id</span><span class="sy0">=</span><span class="st0">&quot;images&quot;</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/div.html"><span class="kw2">div</span></a>&gt;&lt;<a href="http://december.com/html/4/element/a.html"><span class="kw2">a</span></a> <span class="kw3">name</span><span class="sy0">=</span><span class="st0">&quot;image1&quot;</span>&gt;&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/a.html"><span class="kw2">a</span></a>&gt;&lt;<a href="http://december.com/html/4/element/img.html"><span class="kw2">img</span></a> <span class="kw3">src</span><span class="sy0">=</span><span class="st0">&quot;image1.jpg&quot;</span> <span class="kw3">alt</span><span class="sy0">=</span><span class="st0">&quot;&quot;</span> <span class="kw3">title</span><span class="sy0">=</span><span class="st0">&quot;&quot;</span> <span class="sy0">/</span>&gt;&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/div.html"><span class="kw2">div</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/div.html"><span class="kw2">div</span></a>&gt;&lt;<a href="http://december.com/html/4/element/a.html"><span class="kw2">a</span></a> <span class="kw3">name</span><span class="sy0">=</span><span class="st0">&quot;image2&quot;</span>&gt;&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/a.html"><span class="kw2">a</span></a>&gt;&lt;<a href="http://december.com/html/4/element/img.html"><span class="kw2">img</span></a> <span class="kw3">src</span><span class="sy0">=</span><span class="st0">&quot;image2.jpg&quot;</span> <span class="kw3">alt</span><span class="sy0">=</span><span class="st0">&quot;&quot;</span> <span class="kw3">title</span><span class="sy0">=</span><span class="st0">&quot;&quot;</span> <span class="sy0">/</span>&gt;&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/div.html"><span class="kw2">div</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/div.html"><span class="kw2">div</span></a>&gt;&lt;<a href="http://december.com/html/4/element/a.html"><span class="kw2">a</span></a> <span class="kw3">name</span><span class="sy0">=</span><span class="st0">&quot;image3&quot;</span>&gt;&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/a.html"><span class="kw2">a</span></a>&gt;&lt;<a href="http://december.com/html/4/element/img.html"><span class="kw2">img</span></a> <span class="kw3">src</span><span class="sy0">=</span><span class="st0">&quot;image3.jpg&quot;</span> <span class="kw3">alt</span><span class="sy0">=</span><span class="st0">&quot;&quot;</span> <span class="kw3">title</span><span class="sy0">=</span><span class="st0">&quot;&quot;</span> <span class="sy0">/</span>&gt;&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/div.html"><span class="kw2">div</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/div.html"><span class="kw2">div</span></a>&gt;&lt;<a href="http://december.com/html/4/element/a.html"><span class="kw2">a</span></a> <span class="kw3">name</span><span class="sy0">=</span><span class="st0">&quot;image4&quot;</span>&gt;&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/a.html"><span class="kw2">a</span></a>&gt;&lt;<a href="http://december.com/html/4/element/img.html"><span class="kw2">img</span></a> <span class="kw3">src</span><span class="sy0">=</span><span class="st0">&quot;image4.jpg&quot;</span> <span class="kw3">alt</span><span class="sy0">=</span><span class="st0">&quot;&quot;</span> <span class="kw3">title</span><span class="sy0">=</span><span class="st0">&quot;&quot;</span> <span class="sy0">/</span>&gt;&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/div.html"><span class="kw2">div</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/div.html"><span class="kw2">div</span></a>&gt;</span><br />
&nbsp; &nbsp; <span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/div.html"><span class="kw2">div</span></a>&gt;</span></div></td></tr></tbody></table></div>
<p>&#160;</p>
<h3>The CSS</h3>
<p>What we’re going to do with the CSS is setup the tabs so they sit to the left and are stacked on top of one another.&#160; We’re also going to make it so the tabs originally sit at an opacity of 40%, then when a user rolls over the tab it will change to 100% opacity.&#160; Probably the most important part of the CSS will be for div wrapping the images.&#160; We just have to make sure the overflow is set to hidden.</p>
<p>Here is the <strong>CSS</strong>:</p>
<div class="codecolorer-container css " style="overflow:auto;white-space:nowrap;width:580px"><table cellspacing="0" cellpadding="0"><tbody><tr><td class="line-numbers"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br /></div></td><td><div class="css codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="coMULTI">/* CSS Reset */</span><br />
&nbsp; &nbsp; <span class="sy0">*</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">margin</span><span class="sy0">:</span> <span class="nu0">0</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">padding</span><span class="sy0">:</span> <span class="nu0">0</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">border</span><span class="sy0">:</span> <span class="nu0">0</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">outline</span><span class="sy0">:</span> <span class="nu0">0</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span class="coMULTI">/* Setup Tabs */</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; ul<span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">background</span><span class="sy0">:</span><span class="re0">#000</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">width</span><span class="sy0">:</span><span class="re3">125px</span><span class="sy0">;</span> <span class="coMULTI">/* Width of Tab Image */</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">float</span><span class="sy0">:</span> <span class="kw1">left</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">list-style</span><span class="sy0">:</span> <span class="kw2">none</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">border-right</span><span class="sy0">:</span><span class="re3">8px</span> <span class="kw2">solid</span> <span class="kw1">black</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; ul li<span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">height</span><span class="sy0">:</span><span class="re3">75px</span><span class="sy0">;</span> <span class="coMULTI">/* Height of Tab Image */</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span class="coMULTI">/* Setup Tab so normal opacity is 40 and rollover is 100 */</span><br />
&nbsp; &nbsp; ul li a img<span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="coMULTI">/* for IE */</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; -ms-filter<span class="sy0">:</span><span class="st0">&quot;progid:DXImageTransform.Microsoft.Alpha(Opacity=40)&quot;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; filter<span class="sy0">:</span>alpha<span class="br0">&#40;</span>opacity<span class="sy0">=</span><span class="nu0">40</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="coMULTI">/* CSS3 standard */</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; opacity<span class="sy0">:</span><span class="nu0">0.4</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span class="coMULTI">/* Change Opacity to 100% on roll over */</span><br />
&nbsp; &nbsp; ul li a<span class="re2">:hover </span>img<span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="coMULTI">/* for IE */</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; -ms-filter<span class="sy0">:</span><span class="st0">&quot;progid:DXImageTransform.Microsoft.Alpha(Opacity=100)&quot;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; filter<span class="sy0">:</span>alpha<span class="br0">&#40;</span>opacity<span class="sy0">=</span><span class="nu0">100</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="coMULTI">/* CSS3 standard */</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; opacity<span class="sy0">:</span><span class="nu0">1.0</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
<br />
&nbsp; &nbsp; <span class="coMULTI">/* Places images to the right of the tabs,<br />
&nbsp; &nbsp; and hides non selected images */</span><br />
&nbsp; &nbsp; <span class="re0">#images</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">width</span><span class="sy0">:</span><span class="re3">500px</span><span class="sy0">;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">height</span><span class="sy0">:</span><span class="re3">300px</span><span class="sy0">;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">overflow</span><span class="sy0">:</span><span class="kw2">hidden</span><span class="sy0">;</span> &nbsp;<span class="coMULTI">/* Hides the non selected images */</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">float</span><span class="sy0">:</span><span class="kw1">left</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span class="coMULTI">/* Places a black border around the entire viewer<br />
&nbsp; &nbsp; and centers it on the screen */</span><br />
&nbsp; &nbsp; <span class="re0">#wrapper</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">width</span><span class="sy0">:</span><span class="re3">633px</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">height</span><span class="sy0">:</span><span class="re3">300px</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">border</span><span class="sy0">:</span><span class="re3">8px</span> <span class="kw2">solid</span> <span class="kw1">black</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">margin</span><span class="sy0">:</span><span class="re3">0px</span> <span class="kw2">auto</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span></div></td></tr></tbody></table></div>
<p>&#160;</p>
<h3>Putting it All Together</h3>
<p>The last thing we need to do is put the HTML and CSS together.&#160; Of course you change around the appearance of where the tabs sit and how many tabs there are.&#160; The important thing to take from this tutorial is the idea of using anchor tags as a means of switching images.</p>
<p>Here is all the code together:</p>
<div class="codecolorer-container css " style="overflow:auto;white-space:nowrap;width:580px"><table cellspacing="0" cellpadding="0"><tbody><tr><td class="line-numbers"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br />83<br />84<br />85<br />86<br />87<br />88<br />89<br />90<br />91<br />92<br />93<br />94<br />95<br />96<br /></div></td><td><div class="css codecolorer" style="font-family:Monaco,Lucida Console,monospace">&lt;!DOCTYPE html PUBLIC <span class="st0">&quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&quot;</span><span class="sy0">&gt;</span><br />
&nbsp; &nbsp; &lt;html<span class="sy0">&gt;</span><br />
&nbsp; &nbsp; &lt;head<span class="sy0">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;meta http-equiv<span class="sy0">=</span><span class="st0">&quot;Content-type&quot;</span> <span class="kw1">content</span><span class="sy0">=</span><span class="st0">&quot;text/html; charset=utf-8&quot;</span> /<span class="sy0">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;title<span class="sy0">&gt;</span>Image Viewer&lt;/title<span class="sy0">&gt;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;style type<span class="sy0">=</span><span class="st0">&quot;text/css&quot;</span> media<span class="sy0">=</span><span class="st0">&quot;screen&quot;</span><span class="sy0">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="coMULTI">/* CSS Reset */</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sy0">*</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">margin</span><span class="sy0">:</span> <span class="nu0">0</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">padding</span><span class="sy0">:</span> <span class="nu0">0</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">border</span><span class="sy0">:</span> <span class="nu0">0</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">outline</span><span class="sy0">:</span> <span class="nu0">0</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="coMULTI">/* Setup Tabs */</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; ul<span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">background</span><span class="sy0">:</span><span class="re0">#000</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">width</span><span class="sy0">:</span><span class="re3">125px</span><span class="sy0">;</span> <span class="coMULTI">/* Width of Tab Image */</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">float</span><span class="sy0">:</span> <span class="kw1">left</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">list-style</span><span class="sy0">:</span> <span class="kw2">none</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">border-right</span><span class="sy0">:</span><span class="re3">8px</span> <span class="kw2">solid</span> <span class="kw1">black</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; ul li<span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">height</span><span class="sy0">:</span><span class="re3">75px</span><span class="sy0">;</span> <span class="coMULTI">/* Height of Tab Image */</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="coMULTI">/* Setup Tab so normal opacity is 40 and rollover is 100 */</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; ul li a img<span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="coMULTI">/* for IE */</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -ms-filter<span class="sy0">:</span><span class="st0">&quot;progid:DXImageTransform.Microsoft.Alpha(Opacity=40)&quot;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; filter<span class="sy0">:</span>alpha<span class="br0">&#40;</span>opacity<span class="sy0">=</span><span class="nu0">40</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="coMULTI">/* CSS3 standard */</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; opacity<span class="sy0">:</span><span class="nu0">0.4</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="coMULTI">/* Change Opacity to 100% on roll over */</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; ul li a<span class="re2">:hover </span>img<span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="coMULTI">/* for IE */</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -ms-filter<span class="sy0">:</span><span class="st0">&quot;progid:DXImageTransform.Microsoft.Alpha(Opacity=100)&quot;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; filter<span class="sy0">:</span>alpha<span class="br0">&#40;</span>opacity<span class="sy0">=</span><span class="nu0">100</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="coMULTI">/* CSS3 standard */</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; opacity<span class="sy0">:</span><span class="nu0">1.0</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="coMULTI">/* Places images to the right of the tabs,<br />
&nbsp; &nbsp; &nbsp; &nbsp; and hides non selected images */</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">#images</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">width</span><span class="sy0">:</span><span class="re3">500px</span><span class="sy0">;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">height</span><span class="sy0">:</span><span class="re3">300px</span><span class="sy0">;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">overflow</span><span class="sy0">:</span><span class="kw2">hidden</span><span class="sy0">;</span> &nbsp;<span class="coMULTI">/* Hides the non selected images */</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">float</span><span class="sy0">:</span><span class="kw1">left</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="coMULTI">/* Places a black border around the entire viewer<br />
&nbsp; &nbsp; &nbsp; &nbsp; and centers it on the screen */</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">#wrapper</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">width</span><span class="sy0">:</span><span class="re3">633px</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">height</span><span class="sy0">:</span><span class="re3">300px</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">border</span><span class="sy0">:</span><span class="re3">8px</span> <span class="kw2">solid</span> <span class="kw1">black</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">margin</span><span class="sy0">:</span><span class="re3">0px</span> <span class="kw2">auto</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;/style<span class="sy0">&gt;</span><br />
<br />
&nbsp; &nbsp; &lt;/head<span class="sy0">&gt;</span><br />
&nbsp; &nbsp; &lt;body<span class="sy0">&gt;</span><br />
<br />
&nbsp; &nbsp; &lt;div id<span class="sy0">=</span><span class="st0">&quot;wrapper&quot;</span><span class="sy0">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;!-- Tabs --<span class="sy0">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;ul<span class="sy0">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;li<span class="sy0">&gt;</span>&lt;a href<span class="sy0">=</span><span class="st0">&quot;#image1&quot;</span> id<span class="sy0">=</span><span class="st0">&quot;tab1&quot;</span><span class="sy0">&gt;</span>&lt;img src<span class="sy0">=</span><span class="st0">&quot;tab1.jpg&quot;</span> alt<span class="sy0">=</span><span class="st0">&quot;&quot;</span> title<span class="sy0">=</span><span class="st0">&quot;&quot;</span> /<span class="sy0">&gt;</span>&lt;/a<span class="sy0">&gt;</span>&lt;/li<span class="sy0">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;li<span class="sy0">&gt;</span>&lt;a href<span class="sy0">=</span><span class="st0">&quot;#image2&quot;</span> id<span class="sy0">=</span><span class="st0">&quot;tab2&quot;</span><span class="sy0">&gt;</span>&lt;img src<span class="sy0">=</span><span class="st0">&quot;tab2.jpg&quot;</span> alt<span class="sy0">=</span><span class="st0">&quot;&quot;</span> title<span class="sy0">=</span><span class="st0">&quot;&quot;</span> /<span class="sy0">&gt;</span>&lt;/a<span class="sy0">&gt;</span>&lt;/li<span class="sy0">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;li<span class="sy0">&gt;</span>&lt;a href<span class="sy0">=</span><span class="st0">&quot;#image3&quot;</span> id<span class="sy0">=</span><span class="st0">&quot;tab3&quot;</span><span class="sy0">&gt;</span>&lt;img src<span class="sy0">=</span><span class="st0">&quot;tab3.jpg&quot;</span> alt<span class="sy0">=</span><span class="st0">&quot;&quot;</span> title<span class="sy0">=</span><span class="st0">&quot;&quot;</span> /<span class="sy0">&gt;</span>&lt;/a<span class="sy0">&gt;</span>&lt;/li<span class="sy0">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;li<span class="sy0">&gt;</span>&lt;a href<span class="sy0">=</span><span class="st0">&quot;#image4&quot;</span> id<span class="sy0">=</span><span class="st0">&quot;tab4&quot;</span><span class="sy0">&gt;</span>&lt;img src<span class="sy0">=</span><span class="st0">&quot;tab4.jpg&quot;</span> alt<span class="sy0">=</span><span class="st0">&quot;&quot;</span> title<span class="sy0">=</span><span class="st0">&quot;&quot;</span> /<span class="sy0">&gt;</span>&lt;/a<span class="sy0">&gt;</span>&lt;/li<span class="sy0">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;/ul<span class="sy0">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;!-- Images --<span class="sy0">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;div id<span class="sy0">=</span><span class="st0">&quot;images&quot;</span><span class="sy0">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;div<span class="sy0">&gt;</span>&lt;a name<span class="sy0">=</span><span class="st0">&quot;image1&quot;</span><span class="sy0">&gt;</span>&lt;/a<span class="sy0">&gt;</span>&lt;img src<span class="sy0">=</span><span class="st0">&quot;image1.jpg&quot;</span> alt<span class="sy0">=</span><span class="st0">&quot;&quot;</span> title<span class="sy0">=</span><span class="st0">&quot;&quot;</span> /<span class="sy0">&gt;</span>&lt;/div<span class="sy0">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;div<span class="sy0">&gt;</span>&lt;a name<span class="sy0">=</span><span class="st0">&quot;image2&quot;</span><span class="sy0">&gt;</span>&lt;/a<span class="sy0">&gt;</span>&lt;img src<span class="sy0">=</span><span class="st0">&quot;image2.jpg&quot;</span> alt<span class="sy0">=</span><span class="st0">&quot;&quot;</span> title<span class="sy0">=</span><span class="st0">&quot;&quot;</span> /<span class="sy0">&gt;</span>&lt;/div<span class="sy0">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;div<span class="sy0">&gt;</span>&lt;a name<span class="sy0">=</span><span class="st0">&quot;image3&quot;</span><span class="sy0">&gt;</span>&lt;/a<span class="sy0">&gt;</span>&lt;img src<span class="sy0">=</span><span class="st0">&quot;image3.jpg&quot;</span> alt<span class="sy0">=</span><span class="st0">&quot;&quot;</span> title<span class="sy0">=</span><span class="st0">&quot;&quot;</span> /<span class="sy0">&gt;</span>&lt;/div<span class="sy0">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;div<span class="sy0">&gt;</span>&lt;a name<span class="sy0">=</span><span class="st0">&quot;image4&quot;</span><span class="sy0">&gt;</span>&lt;/a<span class="sy0">&gt;</span>&lt;img src<span class="sy0">=</span><span class="st0">&quot;image4.jpg&quot;</span> alt<span class="sy0">=</span><span class="st0">&quot;&quot;</span> title<span class="sy0">=</span><span class="st0">&quot;&quot;</span> /<span class="sy0">&gt;</span>&lt;/div<span class="sy0">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;/div<span class="sy0">&gt;</span><br />
&nbsp; &nbsp; &lt;/div<span class="sy0">&gt;</span>&nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &lt;/body<span class="sy0">&gt;</span><br />
&nbsp; &nbsp; &lt;/html<span class="sy0">&gt;</span></div></td></tr></tbody></table></div>
<p>&#160;</p>
<div class="resources"><a title="CSS Image Viewer Download" href="http://www.devirtuoso.com/Examples/CSS-Image-Viewer/CSS-Image-Viewer.zip" target="_blank" class="Download">Download</a><a title="CSS Image Viewer" href="http://www.devirtuoso.com/Examples/CSS-Image-Viewer/" target="_blank" class="Example">Example</a></div>
<p>&#160;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.devirtuoso.com/2009/07/how-to-build-a-css-image-viewer-the-clever-way/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
	</channel>
</rss>
