<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Devirtuoso</title>
	
	<link>http://www.devirtuoso.com</link>
	<description>Web Development Wickedness</description>
	<lastBuildDate>Tue, 24 Jan 2012 17:16:01 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/Devirtuoso" /><feedburner:info uri="devirtuoso" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><feedburner:feedFlare href="http://add.my.yahoo.com/rss?url=http%3A%2F%2Ffeeds.feedburner.com%2FDevirtuoso" src="http://us.i1.yimg.com/us.yimg.com/i/us/my/addtomyyahoo4.gif">Subscribe with My Yahoo!</feedburner:feedFlare><feedburner:feedFlare href="http://www.newsgator.com/ngs/subscriber/subext.aspx?url=http%3A%2F%2Ffeeds.feedburner.com%2FDevirtuoso" src="http://www.newsgator.com/images/ngsub1.gif">Subscribe with NewsGator</feedburner:feedFlare><feedburner:feedFlare href="http://feeds.my.aol.com/add.jsp?url=http%3A%2F%2Ffeeds.feedburner.com%2FDevirtuoso" src="http://o.aolcdn.com/favorites.my.aol.com/webmaster/ffclient/webroot/locale/en-US/images/myAOLButtonSmall.gif">Subscribe with My AOL</feedburner:feedFlare><feedburner:feedFlare href="http://www.bloglines.com/sub/http://feeds.feedburner.com/Devirtuoso" src="http://www.bloglines.com/images/sub_modern11.gif">Subscribe with Bloglines</feedburner:feedFlare><feedburner:feedFlare href="http://www.netvibes.com/subscribe.php?url=http%3A%2F%2Ffeeds.feedburner.com%2FDevirtuoso" src="http://www.netvibes.com/img/add2netvibes.gif">Subscribe with Netvibes</feedburner:feedFlare><feedburner:feedFlare href="http://fusion.google.com/add?feedurl=http%3A%2F%2Ffeeds.feedburner.com%2FDevirtuoso" src="http://buttons.googlesyndication.com/fusion/add.gif">Subscribe with Google</feedburner:feedFlare><feedburner:feedFlare href="http://www.pageflakes.com/subscribe.aspx?url=http%3A%2F%2Ffeeds.feedburner.com%2FDevirtuoso" src="http://www.pageflakes.com/ImageFile.ashx?instanceId=Static_4&amp;fileName=ATP_blu_91x17.gif">Subscribe with Pageflakes</feedburner:feedFlare><feedburner:feedFlare href="http://www.plusmo.com/add?url=http%3A%2F%2Ffeeds.feedburner.com%2FDevirtuoso" src="http://plusmo.com/res/graphics/fbplusmo.gif">Subscribe with Plusmo</feedburner:feedFlare><feedburner:feedFlare href="http://www.thefreedictionary.com/_/hp/AddRSS.aspx?http%3A%2F%2Ffeeds.feedburner.com%2FDevirtuoso" src="http://img.tfd.com/hp/addToTheFreeDictionary.gif">Subscribe with The Free Dictionary</feedburner:feedFlare><feedburner:feedFlare href="http://www.bitty.com/manual/?contenttype=rssfeed&amp;contentvalue=http%3A%2F%2Ffeeds.feedburner.com%2FDevirtuoso" src="http://www.bitty.com/img/bittychicklet_91x17.gif">Subscribe with Bitty Browser</feedburner:feedFlare><feedburner:feedFlare href="http://www.newsalloy.com/?rss=http%3A%2F%2Ffeeds.feedburner.com%2FDevirtuoso" src="http://www.newsalloy.com/subrss3.gif">Subscribe with NewsAlloy</feedburner:feedFlare><feedburner:feedFlare href="http://www.live.com/?add=http%3A%2F%2Ffeeds.feedburner.com%2FDevirtuoso" src="http://tkfiles.storage.msn.com/x1piYkpqHC_35nIp1gLE68-wvzLZO8iXl_JMledmJQXP-XTBOLfmQv4zhj4MhcWEJh_GtoBIiAl1Mjh-ndp9k47If7hTaFno0mxW9_i3p_5qQw">Subscribe with Live.com</feedburner:feedFlare><feedburner:feedFlare href="http://mix.excite.eu/add?feedurl=http%3A%2F%2Ffeeds.feedburner.com%2FDevirtuoso" src="http://image.excite.co.uk/mix/addtomix.gif">Subscribe with Excite MIX</feedburner:feedFlare><feedburner:feedFlare href="http://download.attensa.com/app/get_attensa.html?feedurl=http%3A%2F%2Ffeeds.feedburner.com%2FDevirtuoso" src="http://www.attensa.com/blogs/attensa/WindowsLiveWriter/BadgeredintoBadges_10C02/attensa_feed_button5.gif">Subscribe with Attensa for Outlook</feedburner:feedFlare><feedburner:feedFlare href="http://www.webwag.com/wwgthis.php?url=http%3A%2F%2Ffeeds.feedburner.com%2FDevirtuoso" src="http://www.webwag.com/images/wwgthis.gif">Subscribe with Webwag</feedburner:feedFlare><feedburner:feedFlare href="http://www.podcastready.com/oneclick_bookmark.php?url=http%3A%2F%2Ffeeds.feedburner.com%2FDevirtuoso" src="http://www.podcastready.com/images/podcastready_button.gif">Subscribe with Podcast Ready</feedburner:feedFlare><feedburner:feedFlare href="http://www.flurry.com/pushRssFeed.do?r=fb&amp;url=http%3A%2F%2Ffeeds.feedburner.com%2FDevirtuoso" src="http://www.flurry.com/images/flurry_rss_logo2.gif">Subscribe with Flurry</feedburner:feedFlare><feedburner:feedFlare href="http://www.wikio.com/subscribe?url=http%3A%2F%2Ffeeds.feedburner.com%2FDevirtuoso" src="http://www.wikio.com/shared/img/add2wikio.gif">Subscribe with Wikio</feedburner:feedFlare><feedburner:feedFlare href="http://www.dailyrotation.com/index.php?feed=http%3A%2F%2Ffeeds.feedburner.com%2FDevirtuoso" src="http://www.dailyrotation.com/rss-dr2.gif">Subscribe with Daily Rotation</feedburner:feedFlare><item>
		<title>Triggering Navigation with Scrolling in JQuery</title>
		<link>http://feedproxy.google.com/~r/Devirtuoso/~3/Gfvb4gYS8Wg/</link>
		<comments>http://www.devirtuoso.com/2012/01/triggering-navigation-with-scrolling-in-jquery/#comments</comments>
		<pubDate>Tue, 24 Jan 2012 17:16:01 +0000</pubDate>
		<dc:creator>Shawn</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[Front End Development]]></category>
		<category><![CDATA[How to]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[JQuery]]></category>
		<category><![CDATA[Navigation]]></category>
		<category><![CDATA[Scrolling]]></category>

		<guid isPermaLink="false">http://www.devirtuoso.com/?p=1447</guid>
		<description><![CDATA[Scrolling as your sites main source of navigation is all the rage. With the amount of one page sites out there I thought it would be helpful to show how to trigger your navigation to changed based on how far you&#8217;ve scrolled down. What we&#8217;re building We&#8217;ll be creating a simple 1 page site. Actually [...]]]></description>
			<content:encoded><![CDATA[<p>Scrolling as your sites main source of navigation is all the rage.  With the amount of one page sites out there I thought it would be helpful to show how to trigger your navigation to changed based on how far you&#8217;ve scrolled down.<br />
<span id="more-1447"></span></p>
<h3>What we&#8217;re building</h3>
<p>We&#8217;ll be creating a simple 1 page site.  Actually we&#8217;ll just be stealing the code from the previous post on <a href="http://www.devirtuoso.com/2011/11/smooth-scrolling-in-jquery/">Smooth Scrolling in Jquery</a>, and adding in the navigation triggering bits.</p>
<div class="resources"><a class="Download" href="http://devirtuoso.com/Examples/ScrollTriggerNav/scrollTriggerNav.zip" target="_blank">Download</a> <a class="Example" href="http://www.devirtuoso.com/Examples/ScrollTriggerNav/" target="_blank">Example</a></div>
<h3>Steal the Previous Code</h3>
<p>We&#8217;re just going to steal the HTML and CSS from the previous post <a href="http://www.devirtuoso.com/2011/11/smooth-scrolling-in-jquery/" target="_blank">Smooth Scrolling in Jquery</a>.  There is nothing special, it&#8217;s just a navigation and a bunch of sections with a header and some text in them.  The headers have unique ids so we can reference them with the jQuery.  We&#8217;re more or less going to get rid of the jQuery and start a new.</p>
<p>Here is what we&#8217;re starting off with:</p>
<div class="codecolorer-container html4strict default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><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 /></div></td><td><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #00bbdd;">&lt;!DOCTYPE HTML&gt;</span><br />
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/html.html"><span style="color: #000000; font-weight: bold;">html</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/head.html"><span style="color: #000000; font-weight: bold;">head</span></a>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/meta.html"><span style="color: #000000; font-weight: bold;">meta</span></a> <span style="color: #000066;">charset</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;UTF-8&quot;</span>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/title.html"><span style="color: #000000; font-weight: bold;">title</span></a>&gt;</span>Smooth Scrolling<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/title.html"><span style="color: #000000; font-weight: bold;">title</span></a>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/style.html"><span style="color: #000000; font-weight: bold;">style</span></a> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/css&quot;</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; .container{<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; width:300px;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; margin:0 auto;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; .section{<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; margin-top:60px;<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; .navigation{<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; position: fixed;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; background:white;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; padding:20px 20px;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; width:100%;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; margin-top:0px;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; top:0px;<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/style.html"><span style="color: #000000; font-weight: bold;">style</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/head.html"><span style="color: #000000; font-weight: bold;">head</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/body.html"><span style="color: #000000; font-weight: bold;">body</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;container&quot;</span>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;navigation&quot;</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/a.html"><span style="color: #000000; font-weight: bold;">a</span></a> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#html&quot;</span>&gt;</span>HTML<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/a.html"><span style="color: #000000; font-weight: bold;">a</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/a.html"><span style="color: #000000; font-weight: bold;">a</span></a> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#javascript&quot;</span>&gt;</span>JavaScript<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/a.html"><span style="color: #000000; font-weight: bold;">a</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/a.html"><span style="color: #000000; font-weight: bold;">a</span></a> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#jquery&quot;</span>&gt;</span>jQuery<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/a.html"><span style="color: #000000; font-weight: bold;">a</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/a.html"><span style="color: #000000; font-weight: bold;">a</span></a> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#php&quot;</span>&gt;</span>PHP<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/a.html"><span style="color: #000000; font-weight: bold;">a</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/a.html"><span style="color: #000000; font-weight: bold;">a</span></a> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#css&quot;</span>&gt;</span>CSS<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/a.html"><span style="color: #000000; font-weight: bold;">a</span></a>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;section&quot;</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/h1.html"><span style="color: #000000; font-weight: bold;">h1</span></a> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;html&quot;</span>&gt;</span>HTML<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/h1.html"><span style="color: #000000; font-weight: bold;">h1</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><span style="color: #808080; font-style: italic;">&lt;!--Your HTML Content Goes HERE --&gt;</span><span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;section&quot;</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/h1.html"><span style="color: #000000; font-weight: bold;">h1</span></a> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;javascript&quot;</span>&gt;</span>JavaScript<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/h1.html"><span style="color: #000000; font-weight: bold;">h1</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><span style="color: #808080; font-style: italic;">&lt;!--Your HTML Content Goes HERE --&gt;</span><span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;section&quot;</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/h1.html"><span style="color: #000000; font-weight: bold;">h1</span></a> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;jquery&quot;</span>&gt;</span>jQuery<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/h1.html"><span style="color: #000000; font-weight: bold;">h1</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><span style="color: #808080; font-style: italic;">&lt;!--Your HTML Content Goes HERE --&gt;</span><span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;section&quot;</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/h1.html"><span style="color: #000000; font-weight: bold;">h1</span></a> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;php&quot;</span>&gt;</span>PHP<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/h1.html"><span style="color: #000000; font-weight: bold;">h1</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><span style="color: #808080; font-style: italic;">&lt;!--Your HTML Content Goes HERE --&gt;</span><span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;section&quot;</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/h1.html"><span style="color: #000000; font-weight: bold;">h1</span></a> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;css&quot;</span>&gt;</span>CSS<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/h1.html"><span style="color: #000000; font-weight: bold;">h1</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><span style="color: #808080; font-style: italic;">&lt;!--Your HTML Content Goes HERE --&gt;</span><span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span>&nbsp; &nbsp; &nbsp; <br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://ajax.googleapis.com/ajax/libs/jquery/1.6/jquery.min.js&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a>&gt;</span><br />
&nbsp; &nbsp; // JavaScript Will go Here<br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/body.html"><span style="color: #000000; font-weight: bold;">body</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/html.html"><span style="color: #000000; font-weight: bold;">html</span></a>&gt;</span></div></td></tr></tbody></table></div>
<h3>The New CSS</h3>
<p>In new found code aquired by a five finger discount needs some styling.  Right now the navigation is plain and you can&#8217;t tell when an item is selected so we&#8217;re just going to add an .active class and perhaps beautify the list a bit.</p>
<div class="codecolorer-container css default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><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="css codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #808080; font-style: italic;">/*<br />
Regular state of naviation<br />
*/</span><br />
a<span style="color: #3333ff;">:link</span><span style="color: #00AA00;">,</span><br />
a<span style="color: #3333ff;">:hover</span><span style="color: #00AA00;">,</span><br />
a<span style="color: #3333ff;">:visited</span><span style="color: #00AA00;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">text-decoration</span><span style="color: #00AA00;">:</span><span style="color: #993333;">none</span><span style="color: #00AA00;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#000</span><span style="color: #00AA00;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #933;">3px</span><span style="color: #00AA00;">;</span><br />
<span style="color: #00AA00;">&#125;</span><br />
<br />
<span style="color: #808080; font-style: italic;">/*<br />
Active state of navigation<br />
*/</span><br />
<span style="color: #6666ff;">.active</span><span style="color: #3333ff;">:link</span><span style="color: #00AA00;">,</span><br />
<span style="color: #6666ff;">.active</span><span style="color: #3333ff;">:hover</span><span style="color: #00AA00;">,</span><br />
<span style="color: #6666ff;">.active</span><span style="color: #3333ff;">:visited<br />
</span><span style="color: #00AA00;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#fff</span><span style="color: #00AA00;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#000060</span><span style="color: #00AA00;">;</span><br />
<span style="color: #00AA00;">&#125;</span><br />
<br />
<span style="color: #808080; font-style: italic;">/*<br />
Make the font of the list a little nicer to look at.<br />
*/</span><br />
<span style="color: #00AA00;">*</span><span style="color: #00AA00;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">font-family</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">sans-serif</span><span style="color: #00AA00;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#666</span><span style="color: #00AA00;">;</span><br />
<span style="color: #00AA00;">&#125;</span></div></td></tr></tbody></table></div>
<h3>The JQuery</h3>
<p>The first thing we need to know is how far each section is from the top.  So we&#8217;re going to write a function that we can pass in a navigation item and it will tell us how far that section is from the top.  Because we have our navigation at the top, we&#8217;ll have to make sure that the section triggers the change just before it reaches the navigation.  We&#8217;ll just subtract the height of the nav from the distance from the top.</p>
<p><img src="http://www.devirtuoso.com/wp-content/uploads/2012/01/imgScrollTriggerExplination.png" alt="Navigation Trigger Scrolling" /></p>
<div class="codecolorer-container javascript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><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 /></div></td><td><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #006600; font-style: italic;">//Get Sections top position</span><br />
<span style="color: #003366; font-weight: bold;">function</span> getTargetTop<span style="color: #009900;">&#40;</span>elem<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//gets the id of the section header</span><br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//from the navigation's href e.g. (&quot;#html&quot;)</span><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> id <span style="color: #339933;">=</span> elem.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;href&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//Height of the navigation</span><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> offset <span style="color: #339933;">=</span> <span style="color: #CC0000;">60</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//Gets the distance from the top and </span><br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//subtracts the height of the nav.</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">return</span> $<span style="color: #009900;">&#40;</span>id<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">offset</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">top</span> <span style="color: #339933;">-</span> offset<span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>Now that we can pull where each section is, we can now setup our navigation to scroll to a section when clicked.</p>
<div class="codecolorer-container javascript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><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="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #006600; font-style: italic;">//Smooth scroll when user click link that starts with #</span><br />
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'a[href^=&quot;#&quot;]'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>event<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//gets the distance from the top of the </span><br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//section refenced in the href.</span><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> target <span style="color: #339933;">=</span> getTargetTop<span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//scrolls to that section.</span><br />
&nbsp; &nbsp; $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'html, body'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">animate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>scrollTop<span style="color: #339933;">:</span>target<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">500</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//prevent the browser from jumping down to section.</span><br />
&nbsp; &nbsp; event.<span style="color: #660066;">preventDefault</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>That takes care of the nav, but now comes the meat and potatoes.  The scrolling now has to trigger the navigation to change. We&#8217;ll create a function that goes through every section and sees if it&#8217;s at the top yet.  It&#8217;ll except 1 parameter which specifies how far the user has scrolled.</p>
<div class="codecolorer-container javascript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><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="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #006600; font-style: italic;">//Pulling sections from main nav.</span><br />
<span style="color: #003366; font-weight: bold;">var</span> sections <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'a[href^=&quot;#&quot;]'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #006600; font-style: italic;">// Go through each section to see if it's at the top.</span><br />
<span style="color: #006600; font-style: italic;">// if it is add an active class</span><br />
<span style="color: #003366; font-weight: bold;">function</span> checkSectionSelected<span style="color: #009900;">&#40;</span>scrolledTo<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//How close the top has to be to the section.</span><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> threshold <span style="color: #339933;">=</span> <span style="color: #CC0000;">100</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> i<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span>i <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> sections.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//get next nav item</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> section <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span>sections<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//get the distance from top</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> target <span style="color: #339933;">=</span> getTargetTop<span style="color: #009900;">&#40;</span>section<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//Check if section is at the top of the page.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>scrolledTo <span style="color: #339933;">&gt;</span> target <span style="color: #339933;">-</span> threshold <span style="color: #339933;">&amp;&amp;</span> scrolledTo <span style="color: #339933;">&lt;</span> target <span style="color: #339933;">+</span> threshold<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//remove all selected elements</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sections.<span style="color: #660066;">removeClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;active&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//add current selected element.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; section.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;active&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>The last thing we need to do is call the function when someone scrolls and when the page is first loaded.</p>
<div class="codecolorer-container javascript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br /></div></td><td><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #006600; font-style: italic;">//Check if page is already scrolled to a section.</span><br />
checkSectionSelected<span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span>window<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">scrollTop</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
$<span style="color: #009900;">&#40;</span>window<span style="color: #009900;">&#41;</span>.<span style="color: #000066;">scroll</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; checkSectionSelected<span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span>window<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">scrollTop</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<h3>That&#8217;s it!</h3>
<p>Now you have yourself a pretty sweet scrolling site.  You can also use this same principle to animate items on your page.  Too fun.</p>
<p>Here is all the code all together:</p>
<div class="codecolorer-container html4strict default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><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 />119<br />120<br />121<br />122<br />123<br />124<br />125<br />126<br />127<br />128<br />129<br />130<br />131<br />132<br />133<br />134<br />135<br />136<br />137<br />138<br />139<br />140<br />141<br />142<br />143<br />144<br />145<br />146<br />147<br />148<br />149<br />150<br />151<br />152<br />153<br />154<br />155<br />156<br />157<br />158<br />159<br />160<br /></div></td><td><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #00bbdd;">&lt;!DOCTYPE HTML&gt;</span><br />
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/html.html"><span style="color: #000000; font-weight: bold;">html</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/head.html"><span style="color: #000000; font-weight: bold;">head</span></a>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/meta.html"><span style="color: #000000; font-weight: bold;">meta</span></a> <span style="color: #000066;">charset</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;UTF-8&quot;</span>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/title.html"><span style="color: #000000; font-weight: bold;">title</span></a>&gt;</span>Smooth Scrolling<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/title.html"><span style="color: #000000; font-weight: bold;">title</span></a>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/style.html"><span style="color: #000000; font-weight: bold;">style</span></a> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/css&quot;</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; .container{<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; width:300px;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; margin:0 auto;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; .section{<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; margin-top:60px;<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; .navigation{<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; position: fixed;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; background:white;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; padding:20px 20px;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; width:100%;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; margin-top:0px;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; top:0px;<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; a:link,<br />
&nbsp; &nbsp; &nbsp; &nbsp; a:hover,<br />
&nbsp; &nbsp; &nbsp; &nbsp; a:visited{<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; text-decoration:none;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; color: #000;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; padding:3px;<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; .active:link,<br />
&nbsp; &nbsp; &nbsp; &nbsp; .active:hover,<br />
&nbsp; &nbsp; &nbsp; &nbsp; .active:visited<br />
&nbsp; &nbsp; &nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; color: #fff;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; background: #000060;<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; *{<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; font-family: sans-serif;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; color: #666;<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/style.html"><span style="color: #000000; font-weight: bold;">style</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/head.html"><span style="color: #000000; font-weight: bold;">head</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/body.html"><span style="color: #000000; font-weight: bold;">body</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;container&quot;</span>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;navigation&quot;</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/a.html"><span style="color: #000000; font-weight: bold;">a</span></a> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#html&quot;</span>&gt;</span>HTML<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/a.html"><span style="color: #000000; font-weight: bold;">a</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/a.html"><span style="color: #000000; font-weight: bold;">a</span></a> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#javascript&quot;</span>&gt;</span>JavaScript<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/a.html"><span style="color: #000000; font-weight: bold;">a</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/a.html"><span style="color: #000000; font-weight: bold;">a</span></a> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#jquery&quot;</span>&gt;</span>jQuery<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/a.html"><span style="color: #000000; font-weight: bold;">a</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/a.html"><span style="color: #000000; font-weight: bold;">a</span></a> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#php&quot;</span>&gt;</span>PHP<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/a.html"><span style="color: #000000; font-weight: bold;">a</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/a.html"><span style="color: #000000; font-weight: bold;">a</span></a> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#css&quot;</span>&gt;</span>CSS<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/a.html"><span style="color: #000000; font-weight: bold;">a</span></a>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;section&quot;</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/h1.html"><span style="color: #000000; font-weight: bold;">h1</span></a> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;html&quot;</span>&gt;</span>HTML<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/h1.html"><span style="color: #000000; font-weight: bold;">h1</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><span style="color: #808080; font-style: italic;">&lt;!--Your HTML Content Goes HERE --&gt;</span><span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;section&quot;</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/h1.html"><span style="color: #000000; font-weight: bold;">h1</span></a> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;javascript&quot;</span>&gt;</span>JavaScript<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/h1.html"><span style="color: #000000; font-weight: bold;">h1</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><span style="color: #808080; font-style: italic;">&lt;!--Your HTML Content Goes HERE --&gt;</span><span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;section&quot;</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/h1.html"><span style="color: #000000; font-weight: bold;">h1</span></a> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;jquery&quot;</span>&gt;</span>jQuery<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/h1.html"><span style="color: #000000; font-weight: bold;">h1</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><span style="color: #808080; font-style: italic;">&lt;!--Your HTML Content Goes HERE --&gt;</span><span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;section&quot;</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/h1.html"><span style="color: #000000; font-weight: bold;">h1</span></a> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;php&quot;</span>&gt;</span>PHP<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/h1.html"><span style="color: #000000; font-weight: bold;">h1</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><span style="color: #808080; font-style: italic;">&lt;!--Your HTML Content Goes HERE --&gt;</span><span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;section&quot;</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/h1.html"><span style="color: #000000; font-weight: bold;">h1</span></a> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;css&quot;</span>&gt;</span>CSS<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/h1.html"><span style="color: #000000; font-weight: bold;">h1</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><span style="color: #808080; font-style: italic;">&lt;!--Your HTML Content Goes HERE --&gt;</span><span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span>&nbsp; &nbsp; &nbsp; <br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://ajax.googleapis.com/ajax/libs/jquery/1.6/jquery.min.js&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a>&gt;</span><br />
&nbsp; &nbsp; $(document).ready(function() {<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; //Get Sections top position<br />
&nbsp; &nbsp; &nbsp; &nbsp; function getTargetTop(elem){<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //gets the id of the section header<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //from the navigation's href e.g. (&quot;#html&quot;)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var id = elem.attr(&quot;href&quot;);<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //Height of the navigation<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var offset = 60;<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //Gets the distance from the top and <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //subtracts the height of the nav.<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return $(id).offset().top - offset;<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; //Smooth scroll when user click link that starts with #<br />
&nbsp; &nbsp; &nbsp; &nbsp; $('a[href^=&quot;#&quot;]').click(function(event) {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //gets the distance from the top of the <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //section refenced in the href.<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var target = getTargetTop($(this));<br />
<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //scrolls to that section.<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $('html, body').animate({scrollTop:target}, 500);<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //prevent the browser from jumping down to section.<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; event.preventDefault();<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; });<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; //Pulling sections from main nav.<br />
&nbsp; &nbsp; &nbsp; &nbsp; var sections = $('a[href^=&quot;#&quot;]');<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; // Go through each section to see if it's at the top.<br />
&nbsp; &nbsp; &nbsp; &nbsp; // if it is add an active class<br />
&nbsp; &nbsp; &nbsp; &nbsp; function checkSectionSelected(scrolledTo){<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //How close the top has to be to the section.<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var threshold = 100;<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var i;<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for (i = 0; i <span style="color: #009900;">&lt; sections.length; i++<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></span><br />
<span style="color: #009900;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><br />
<span style="color: #009900;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">//</span>get next nav item</span><br />
<span style="color: #009900;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var section <span style="color: #66cc66;">=</span> $<span style="color: #66cc66;">&#40;</span>sections<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>;</span><br />
<br />
<span style="color: #009900;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">//</span>get the distance from top</span><br />
<span style="color: #009900;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var <span style="color: #000066;">target</span> <span style="color: #66cc66;">=</span> getTargetTop<span style="color: #66cc66;">&#40;</span>section<span style="color: #66cc66;">&#41;</span>;</span><br />
<span style="color: #009900;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><br />
<span style="color: #009900;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">//</span>Check if section is at the top of the page.</span><br />
<span style="color: #009900;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if <span style="color: #66cc66;">&#40;</span>scrolledTo &gt;</span> target - threshold <span style="color: #ddbb00;">&amp;&amp; scrolledTo &lt; target + threshold) {</span><br />
<br />
<span style="color: #ddbb00;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //remove all selected elements</span><br />
<span style="color: #ddbb00;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sections.removeClass(&quot;active&quot;);</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //add current selected element.<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; section.addClass(&quot;active&quot;);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; };<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; //Check if page is already scrolled to a section.<br />
&nbsp; &nbsp; &nbsp; &nbsp; checkSectionSelected($(window).scrollTop());<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; $(window).scroll(function(e){<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; checkSectionSelected($(window).scrollTop())<br />
&nbsp; &nbsp; &nbsp; &nbsp; });<br />
<br />
<br />
<br />
&nbsp; &nbsp; });<br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/body.html"><span style="color: #000000; font-weight: bold;">body</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/html.html"><span style="color: #000000; font-weight: bold;">html</span></a>&gt;</span></div></td></tr></tbody></table></div>
<div class="resources"><a class="Download" href="http://devirtuoso.com/Examples/ScrollTriggerNav/scrollTriggerNav.zip" target="_blank">Download</a> <a class="Example" href="http://www.devirtuoso.com/Examples/ScrollTriggerNav/" target="_blank">Example</a></div>

<p><a href="http://feedads.g.doubleclick.net/~a/ORMIfVYln1zievGM6WDaw-7X9Ig/0/da"><img src="http://feedads.g.doubleclick.net/~a/ORMIfVYln1zievGM6WDaw-7X9Ig/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/ORMIfVYln1zievGM6WDaw-7X9Ig/1/da"><img src="http://feedads.g.doubleclick.net/~a/ORMIfVYln1zievGM6WDaw-7X9Ig/1/di" border="0" ismap="true"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/Devirtuoso?a=Gfvb4gYS8Wg:qHOHgjYJ5jI:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/Devirtuoso?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Devirtuoso?a=Gfvb4gYS8Wg:qHOHgjYJ5jI:TzevzKxY174"><img src="http://feeds.feedburner.com/~ff/Devirtuoso?d=TzevzKxY174" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Devirtuoso?a=Gfvb4gYS8Wg:qHOHgjYJ5jI:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/Devirtuoso?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Devirtuoso?a=Gfvb4gYS8Wg:qHOHgjYJ5jI:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/Devirtuoso?i=Gfvb4gYS8Wg:qHOHgjYJ5jI:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Devirtuoso?a=Gfvb4gYS8Wg:qHOHgjYJ5jI:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/Devirtuoso?i=Gfvb4gYS8Wg:qHOHgjYJ5jI:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Devirtuoso?a=Gfvb4gYS8Wg:qHOHgjYJ5jI:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/Devirtuoso?i=Gfvb4gYS8Wg:qHOHgjYJ5jI:F7zBnMyn0Lo" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/Devirtuoso/~4/Gfvb4gYS8Wg" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.devirtuoso.com/2012/01/triggering-navigation-with-scrolling-in-jquery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.devirtuoso.com/2012/01/triggering-navigation-with-scrolling-in-jquery/</feedburner:origLink></item>
		<item>
		<title>Smooth Scrolling in jQuery</title>
		<link>http://feedproxy.google.com/~r/Devirtuoso/~3/No_OI5-kbNs/</link>
		<comments>http://www.devirtuoso.com/2011/11/smooth-scrolling-in-jquery/#comments</comments>
		<pubDate>Wed, 30 Nov 2011 16:04:40 +0000</pubDate>
		<dc:creator>Shawn</dc:creator>
				<category><![CDATA[Flash]]></category>
		<category><![CDATA[Front End Development]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[JQuery]]></category>
		<category><![CDATA[Scrolling]]></category>

		<guid isPermaLink="false">http://www.devirtuoso.com/?p=1434</guid>
		<description><![CDATA[Single page websites seem to be all the rage now a days. Scrolling effects seem to be in high demand. So in this post I&#8217;ll show you how to create a smooth scrolling page with jQuery. What are we building? We&#8217;ll be creating our own fansy smansy website. The nav will sit fixed at the [...]]]></description>
			<content:encoded><![CDATA[<p>Single page websites seem to be all the rage now a days.  Scrolling effects seem to be in high demand.  So in this post I&#8217;ll show you how to create a smooth scrolling page with jQuery.</p>
<p><span id="more-1434"></span></p>
<h3>What are we building?</h3>
<p>
	We&#8217;ll be creating our own fansy smansy website.  The nav will sit fixed at the top.  Once we click on a nav item it will scroll down to the section.  Best of all, if JavaScript is shut off, it will degrade gracefull and just jump down to the section.
</p>
<div class="resources"><a class="Download" href="http://devirtuoso.com/Examples/SmoothScroll/smoothScroll.zip" target="_blank">Download</a> <a class="Example" href="http://www.devirtuoso.com/Examples/SmoothScroll/" target="_blank">Example</a></div>
<h3>The HTML : Content</h3>
<p>First thing we need is some content to scroll.  This can be anything as long as their is enough of it to scroll&#8230;.otherwise this tutorial is pointless <img src='http://www.devirtuoso.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />   At the top of each section we&#8217;ll need to specify an id (we&#8217;ll be using this for our navigation).  It can be on anything. Really just put the id on what you want to appear at the top of the page. For this example I put it on the header tags.</p>
<div class="codecolorer-container html4strict default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><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 /></div></td><td><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;container&quot;</span>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;section&quot;</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/h1.html"><span style="color: #000000; font-weight: bold;">h1</span></a> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;html&quot;</span>&gt;</span>HTML<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/h1.html"><span style="color: #000000; font-weight: bold;">h1</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><span style="color: #808080; font-style: italic;">&lt;!--Your HTML Content Goes HERE --&gt;</span><span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;section&quot;</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/h1.html"><span style="color: #000000; font-weight: bold;">h1</span></a> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;css&quot;</span>&gt;</span>CSS<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/h1.html"><span style="color: #000000; font-weight: bold;">h1</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><span style="color: #808080; font-style: italic;">&lt;!--Your HTML Content Goes HERE --&gt;</span><span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;section&quot;</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/h1.html"><span style="color: #000000; font-weight: bold;">h1</span></a> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;php&quot;</span>&gt;</span>PHP<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/h1.html"><span style="color: #000000; font-weight: bold;">h1</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><span style="color: #808080; font-style: italic;">&lt;!--Your HTML Content Goes HERE --&gt;</span><span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;section&quot;</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/h1.html"><span style="color: #000000; font-weight: bold;">h1</span></a> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;javascript&quot;</span>&gt;</span>JavaScript<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/h1.html"><span style="color: #000000; font-weight: bold;">h1</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><span style="color: #808080; font-style: italic;">&lt;!--Your HTML Content Goes HERE --&gt;</span><span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;section&quot;</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/h1.html"><span style="color: #000000; font-weight: bold;">h1</span></a> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;jquery&quot;</span>&gt;</span>jQuery<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/h1.html"><span style="color: #000000; font-weight: bold;">h1</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><span style="color: #808080; font-style: italic;">&lt;!--Your HTML Content Goes HERE --&gt;</span><span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span></div></td></tr></tbody></table></div>
<h3>The HTML : Navigation</h3>
<p>Now that we know what the ids are for each section we can go ahead and use those to create a navigation.</p>
<div class="codecolorer-container html4strict default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br /></div></td><td><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;navigation&quot;</span>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/a.html"><span style="color: #000000; font-weight: bold;">a</span></a> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#html&quot;</span>&gt;</span>HTML<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/a.html"><span style="color: #000000; font-weight: bold;">a</span></a>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/a.html"><span style="color: #000000; font-weight: bold;">a</span></a> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#css&quot;</span>&gt;</span>CSS<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/a.html"><span style="color: #000000; font-weight: bold;">a</span></a>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/a.html"><span style="color: #000000; font-weight: bold;">a</span></a> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#php&quot;</span>&gt;</span>PHP<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/a.html"><span style="color: #000000; font-weight: bold;">a</span></a>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/a.html"><span style="color: #000000; font-weight: bold;">a</span></a> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#javascript&quot;</span>&gt;</span>JavaScript<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/a.html"><span style="color: #000000; font-weight: bold;">a</span></a>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/a.html"><span style="color: #000000; font-weight: bold;">a</span></a> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#jquery&quot;</span>&gt;</span>jQuery<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/a.html"><span style="color: #000000; font-weight: bold;">a</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span></div></td></tr></tbody></table></div>
<p>Now just having this when we click on the navigation it should take us down to our desired location.</p>
<h3>The CSS</h3>
<p>Nothing to Crazy here.  The most important part is the navigation.  The position:fixed attribute keeps it at the top.  And the margin top on the section class just make sure the content isn&#8217;t below the navigation when first loading the page.</p>
<div class="codecolorer-container css default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><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 /></div></td><td><div class="css codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&lt;style<span style="color: #00AA00;">&gt;</span><br />
<br />
<span style="color: #808080; font-style: italic;">/* Made the container thin <br />
so I didn't have to come up <br />
with too much content */</span><br />
.container<span style="color: #00AA00;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">300px</span><span style="color: #00AA00;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span> <span style="color: #993333;">auto</span><span style="color: #00AA00;">;</span><br />
&nbsp; &nbsp; <br />
<span style="color: #00AA00;">&#125;</span><br />
<span style="color: #808080; font-style: italic;">/* So the sections don't fall<br />
underneath the navigation */</span><br />
.section<span style="color: #00AA00;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">margin-top</span><span style="color: #00AA00;">:</span><span style="color: #933;">60px</span><span style="color: #00AA00;">;</span><br />
<span style="color: #00AA00;">&#125;</span><br />
<span style="color: #808080; font-style: italic;">/* <br />
1. Keeps the position at the top of the page.<br />
2. Adds a background so you can't see text<br />
&nbsp; &nbsp;underneath the nav.<br />
3. Adds a little padding for breathing room.<br />
*/</span><br />
.navigation<span style="color: #00AA00;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">fixed</span><span style="color: #00AA00;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #993333;">white</span><span style="color: #00AA00;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #933;">20px</span> <span style="color: #933;">20px</span><span style="color: #00AA00;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">100%</span><span style="color: #00AA00;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">margin-top</span><span style="color: #00AA00;">:</span><span style="color: #933;">0px</span><span style="color: #00AA00;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">:</span><span style="color: #933;">0px</span><span style="color: #00AA00;">;</span><br />
<span style="color: #00AA00;">&#125;</span><br />
&lt;/style<span style="color: #00AA00;">&gt;</span></div></td></tr></tbody></table></div>
<h3>The jQuery (aka The Magic behind smooth scrolling)</h3>
<p>The jQuery isn&#8217;t overly complicated.  We&#8217;re just going to use the animate function to a specific location over time.  Now we get that location by referencing the item that has the id that the href of our navigation points to.  So if our navigation points to &#8220;#css&#8221;, then we&#8217;ll get the position of the item that has the id of &#8220;css&#8221;</p>
<div class="codecolorer-container javascript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><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 /></div></td><td><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #339933;">&lt;</span>script<span style="color: #339933;">&gt;</span><br />
$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">// Click event for any anchor tag that's href starts with #</span><br />
&nbsp; &nbsp; $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'a[href^=&quot;#&quot;]'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>event<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">// The id of the section we want to go to.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> id <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;href&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">// An offset to push the content down from the top.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> offset <span style="color: #339933;">=</span> <span style="color: #CC0000;">60</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">// Our scroll target : the top position of the</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">// section that has the id referenced by our href.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> target <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span>id<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">offset</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">top</span> <span style="color: #339933;">-</span> offset<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">// The magic...smooth scrollin' goodness.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'html, body'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">animate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>scrollTop<span style="color: #339933;">:</span>target<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">500</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//prevent the page from jumping down to our section.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; event.<span style="color: #660066;">preventDefault</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></div></td></tr></tbody></table></div>
<h3>Putting it all together</h3>
<p>Here is everything all in one.</p>
<p>Enjoy!</p>
<div class="codecolorer-container html4strict default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><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="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #00bbdd;">&lt;!DOCTYPE HTML&gt;</span><br />
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/html.html"><span style="color: #000000; font-weight: bold;">html</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/head.html"><span style="color: #000000; font-weight: bold;">head</span></a>&gt;</span><br />
<br />
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/meta.html"><span style="color: #000000; font-weight: bold;">meta</span></a> <span style="color: #000066;">charset</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;UTF-8&quot;</span>&gt;</span><br />
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/title.html"><span style="color: #000000; font-weight: bold;">title</span></a>&gt;</span>Smooth Scrolling<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/title.html"><span style="color: #000000; font-weight: bold;">title</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/style.html"><span style="color: #000000; font-weight: bold;">style</span></a>&gt;</span><br />
<br />
/* Made the container thin <br />
so I didn't have to come up <br />
with too much content */<br />
.container{<br />
&nbsp; &nbsp; width:300px;<br />
&nbsp; &nbsp; margin:0 auto;<br />
&nbsp; &nbsp; <br />
}<br />
/* So the sections don't fall<br />
underneath the navigation */<br />
.section{<br />
&nbsp; &nbsp; margin-top:60px;<br />
}<br />
/* <br />
1. Keeps the position at the top of the page.<br />
2. Adds a background so you can't see text<br />
&nbsp; &nbsp;underneath the nav.<br />
3. Adds a little padding for breathing room.<br />
*/<br />
.navigation{<br />
&nbsp; &nbsp; position: fixed;<br />
&nbsp; &nbsp; background:white;<br />
&nbsp; &nbsp; padding:20px 20px;<br />
&nbsp; &nbsp; width:100%;<br />
&nbsp; &nbsp; margin-top:0px;<br />
&nbsp; &nbsp; top:0px;<br />
}<br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/style.html"><span style="color: #000000; font-weight: bold;">style</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/head.html"><span style="color: #000000; font-weight: bold;">head</span></a>&gt;</span><br />
<br />
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/body.html"><span style="color: #000000; font-weight: bold;">body</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;container&quot;</span>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;navigation&quot;</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/a.html"><span style="color: #000000; font-weight: bold;">a</span></a> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#html&quot;</span>&gt;</span>HTML<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/a.html"><span style="color: #000000; font-weight: bold;">a</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/a.html"><span style="color: #000000; font-weight: bold;">a</span></a> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#css&quot;</span>&gt;</span>CSS<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/a.html"><span style="color: #000000; font-weight: bold;">a</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/a.html"><span style="color: #000000; font-weight: bold;">a</span></a> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#php&quot;</span>&gt;</span>PHP<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/a.html"><span style="color: #000000; font-weight: bold;">a</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/a.html"><span style="color: #000000; font-weight: bold;">a</span></a> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#javascript&quot;</span>&gt;</span>JavaScript<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/a.html"><span style="color: #000000; font-weight: bold;">a</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/a.html"><span style="color: #000000; font-weight: bold;">a</span></a> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#jquery&quot;</span>&gt;</span>jQuery<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/a.html"><span style="color: #000000; font-weight: bold;">a</span></a>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;section&quot;</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/h1.html"><span style="color: #000000; font-weight: bold;">h1</span></a> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;html&quot;</span>&gt;</span>HTML<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/h1.html"><span style="color: #000000; font-weight: bold;">h1</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><span style="color: #808080; font-style: italic;">&lt;!--Your HTML Content Goes HERE --&gt;</span><span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;section&quot;</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/h1.html"><span style="color: #000000; font-weight: bold;">h1</span></a> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;css&quot;</span>&gt;</span>CSS<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/h1.html"><span style="color: #000000; font-weight: bold;">h1</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><span style="color: #808080; font-style: italic;">&lt;!--Your HTML Content Goes HERE --&gt;</span><span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;section&quot;</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/h1.html"><span style="color: #000000; font-weight: bold;">h1</span></a> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;php&quot;</span>&gt;</span>PHP<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/h1.html"><span style="color: #000000; font-weight: bold;">h1</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><span style="color: #808080; font-style: italic;">&lt;!--Your HTML Content Goes HERE --&gt;</span><span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;section&quot;</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/h1.html"><span style="color: #000000; font-weight: bold;">h1</span></a> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;javascript&quot;</span>&gt;</span>JavaScript<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/h1.html"><span style="color: #000000; font-weight: bold;">h1</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><span style="color: #808080; font-style: italic;">&lt;!--Your HTML Content Goes HERE --&gt;</span><span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;section&quot;</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/h1.html"><span style="color: #000000; font-weight: bold;">h1</span></a> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;jquery&quot;</span>&gt;</span>jQuery<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/h1.html"><span style="color: #000000; font-weight: bold;">h1</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><span style="color: #808080; font-style: italic;">&lt;!--Your HTML Content Goes HERE --&gt;</span><span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span><br />
<br />
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a>&gt;</span><br />
$(document).ready(function() {<br />
<br />
&nbsp; &nbsp; // Click event for any anchor tag that's href starts with #<br />
&nbsp; &nbsp; $('a[href^=&quot;#&quot;]').click(function(event) {<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; // The id of the section we want to go to.<br />
&nbsp; &nbsp; &nbsp; &nbsp; var id = $(this).attr(&quot;href&quot;);<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; // An offset to push the content down from the top.<br />
&nbsp; &nbsp; &nbsp; &nbsp; var offset = 60;<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; // Our scroll target : the top position of the<br />
&nbsp; &nbsp; &nbsp; &nbsp; // section that has the id referenced by our href.<br />
&nbsp; &nbsp; &nbsp; &nbsp; var target = $(id).offset().top - offset;<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; // The magic...smooth scrollin' goodness.<br />
&nbsp; &nbsp; &nbsp; &nbsp; $('html, body').animate({scrollTop:target}, 500);<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; //prevent the page from jumping down to our section.<br />
&nbsp; &nbsp; &nbsp; &nbsp; event.preventDefault();<br />
&nbsp; &nbsp; });<br />
});<br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a>&gt;</span><br />
<br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/body.html"><span style="color: #000000; font-weight: bold;">body</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/html.html"><span style="color: #000000; font-weight: bold;">html</span></a>&gt;</span></div></td></tr></tbody></table></div>
<div class="resources"><a class="Download" href="http://devirtuoso.com/Examples/SmoothScroll/smoothScroll.zip" target="_blank">Download</a> <a class="Example" href="http://www.devirtuoso.com/Examples/SmoothScroll/" target="_blank">Example</a></div>

<p><a href="http://feedads.g.doubleclick.net/~a/BZmn1GHqir7dLVA3iFdoX10RfKs/0/da"><img src="http://feedads.g.doubleclick.net/~a/BZmn1GHqir7dLVA3iFdoX10RfKs/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/BZmn1GHqir7dLVA3iFdoX10RfKs/1/da"><img src="http://feedads.g.doubleclick.net/~a/BZmn1GHqir7dLVA3iFdoX10RfKs/1/di" border="0" ismap="true"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/Devirtuoso?a=No_OI5-kbNs:NIhT8v4aB1g:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/Devirtuoso?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Devirtuoso?a=No_OI5-kbNs:NIhT8v4aB1g:TzevzKxY174"><img src="http://feeds.feedburner.com/~ff/Devirtuoso?d=TzevzKxY174" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Devirtuoso?a=No_OI5-kbNs:NIhT8v4aB1g:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/Devirtuoso?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Devirtuoso?a=No_OI5-kbNs:NIhT8v4aB1g:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/Devirtuoso?i=No_OI5-kbNs:NIhT8v4aB1g:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Devirtuoso?a=No_OI5-kbNs:NIhT8v4aB1g:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/Devirtuoso?i=No_OI5-kbNs:NIhT8v4aB1g:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Devirtuoso?a=No_OI5-kbNs:NIhT8v4aB1g:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/Devirtuoso?i=No_OI5-kbNs:NIhT8v4aB1g:F7zBnMyn0Lo" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/Devirtuoso/~4/No_OI5-kbNs" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.devirtuoso.com/2011/11/smooth-scrolling-in-jquery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.devirtuoso.com/2011/11/smooth-scrolling-in-jquery/</feedburner:origLink></item>
		<item>
		<title>Good list of RSS feeds to follow for Web Developers</title>
		<link>http://feedproxy.google.com/~r/Devirtuoso/~3/tkDTPM0P2bk/</link>
		<comments>http://www.devirtuoso.com/2011/11/good-list-of-rss-feeds-to-follow-for-web-developers/#comments</comments>
		<pubDate>Mon, 28 Nov 2011 15:43:27 +0000</pubDate>
		<dc:creator>Shawn</dc:creator>
				<category><![CDATA[Freebie]]></category>
		<category><![CDATA[Front End Development]]></category>
		<category><![CDATA[paul irish]]></category>
		<category><![CDATA[RSS]]></category>
		<category><![CDATA[web standards]]></category>

		<guid isPermaLink="false">http://www.devirtuoso.com/?p=1427</guid>
		<description><![CDATA[Paul Irish recently posted a list of his rss feeds that he follows.  I thought I&#8217;d spread the love and share it with you as it&#8217;s a pretty great list. Be sure to check out his list for: Front end Development Web Standards Also be sure to subscribe to his blog, he has some pretty [...]]]></description>
			<content:encoded><![CDATA[<p>Paul Irish recently posted a list of his <a title="Paul Irish's RSS feeds" href="http://paulirish.com/2011/web-browser-frontend-and-standards-feeds-to-follow/" target="_blank">rss feeds </a>that he follows.  I thought I&#8217;d spread the love and share it with you as it&#8217;s a <a title="Developer RSS Feed List" href="http://www.google.com/reader/bundle/user%2F11165870484951445324%2Fbundle%2Ffrontend-standards%2Bbrowsers" target="_blank">pretty great list</a>.</p>
<p><span id="more-1427"></span>Be sure to check out his list for:</p>
<ol>
<li><a title="Frontend Development RSS feeds." href="http://www.google.com/reader/bundle/user%2F11165870484951445324%2Fbundle%2Ffrontend" target="_blank">Front end Development</a></li>
<li><a title="Web Standards RSS feeds" href="http://www.google.com/reader/bundle/user%2F11165870484951445324%2Fbundle%2Ffrontend-standards%2Bbrowsers" target="_blank">Web Standards</a></li>
</ol>
<p>Also be sure to subscribe to his <a title="Paul Irish's blog" href="http://paulirish.com/" target="_blank">blog</a>, he has some pretty cool videos.</p>
<p>Enjoy.</p>

<p><a href="http://feedads.g.doubleclick.net/~a/uIynf1IaTr12T7M_cL5GTUWQyY8/0/da"><img src="http://feedads.g.doubleclick.net/~a/uIynf1IaTr12T7M_cL5GTUWQyY8/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/uIynf1IaTr12T7M_cL5GTUWQyY8/1/da"><img src="http://feedads.g.doubleclick.net/~a/uIynf1IaTr12T7M_cL5GTUWQyY8/1/di" border="0" ismap="true"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/Devirtuoso?a=tkDTPM0P2bk:RSKVmZIMrfw:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/Devirtuoso?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Devirtuoso?a=tkDTPM0P2bk:RSKVmZIMrfw:TzevzKxY174"><img src="http://feeds.feedburner.com/~ff/Devirtuoso?d=TzevzKxY174" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Devirtuoso?a=tkDTPM0P2bk:RSKVmZIMrfw:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/Devirtuoso?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Devirtuoso?a=tkDTPM0P2bk:RSKVmZIMrfw:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/Devirtuoso?i=tkDTPM0P2bk:RSKVmZIMrfw:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Devirtuoso?a=tkDTPM0P2bk:RSKVmZIMrfw:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/Devirtuoso?i=tkDTPM0P2bk:RSKVmZIMrfw:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Devirtuoso?a=tkDTPM0P2bk:RSKVmZIMrfw:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/Devirtuoso?i=tkDTPM0P2bk:RSKVmZIMrfw:F7zBnMyn0Lo" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/Devirtuoso/~4/tkDTPM0P2bk" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.devirtuoso.com/2011/11/good-list-of-rss-feeds-to-follow-for-web-developers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.devirtuoso.com/2011/11/good-list-of-rss-feeds-to-follow-for-web-developers/</feedburner:origLink></item>
		<item>
		<title>Creating an Image Mask with HTML 5 Canvas</title>
		<link>http://feedproxy.google.com/~r/Devirtuoso/~3/myDqDaK7K_I/</link>
		<comments>http://www.devirtuoso.com/2011/09/creating-an-image-mask-with-html-5-canvas/#comments</comments>
		<pubDate>Thu, 22 Sep 2011 19:25:04 +0000</pubDate>
		<dc:creator>Shawn</dc:creator>
				<category><![CDATA[Front End Development]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Canvas]]></category>
		<category><![CDATA[HTML 5]]></category>

		<guid isPermaLink="false">http://www.devirtuoso.com/?p=1415</guid>
		<description><![CDATA[Sometimes it&#8217;s handy to be able to mask an image without having to take it into Photoshop. In this tutorial I&#8217;ll show you how to make a mask using HTML 5 canvas and a bit of javascript. What we&#8217;re building We&#8217;re going to mask an image with a circle that we create. Pretty simple, but [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes it&#8217;s handy to be able to mask an image without having to take it into Photoshop.  In this tutorial I&#8217;ll show you how to make a mask using HTML 5 canvas and a bit of javascript.<br />
<span id="more-1415"></span></p>
<h3>What we&#8217;re building</h3>
<p>We&#8217;re going to mask an image with a circle that we create.  Pretty simple, but it gets the point across I think.</p>
<h2 style="color:red;">Sorry IE users, this probably won&#8217;t work for you.</h2>
<div class="resources"><a class="Download" href="http://devirtuoso.com/Examples/HTML5ImageMask/html5ImageMask.zip" target="_blank">Download</a> <a class="Example" href="http://www.devirtuoso.com/Examples/HTML5ImageMask/" target="_blank">Example</a></div>
<h3>The HTML</h3>
<p>We just need a canvas, and an image.  We&#8217;re going to place the image inside the canvas incase the browser doesn&#8217;t support the canvas.  This way instead of masking it, it will just display the regular image.</p>
<div class="codecolorer-container html4strict default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><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 /></div></td><td><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #00bbdd;">&lt;!DOCTYPE HTML&gt;</span><br />
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/html.html"><span style="color: #000000; font-weight: bold;">html</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/head.html"><span style="color: #000000; font-weight: bold;">head</span></a>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/meta.html"><span style="color: #000000; font-weight: bold;">meta</span></a> <span style="color: #000066;">charset</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;UTF-8&quot;</span>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/title.html"><span style="color: #000000; font-weight: bold;">title</span></a>&gt;</span>Image Mask<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/title.html"><span style="color: #000000; font-weight: bold;">title</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/head.html"><span style="color: #000000; font-weight: bold;">head</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/body.html"><span style="color: #000000; font-weight: bold;">body</span></a>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">&lt;!-- If the browser doesn't support canvas, just the image will be displayed. --&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;canvas <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;stage&quot;</span>&gt;&lt;<a href="http://december.com/html/4/element/img.html"><span style="color: #000000; font-weight: bold;">img</span></a> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;test.jpg&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;image&quot;</span> <span style="color: #000066;">alt</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #66cc66;">/</span>&gt;&lt;<span style="color: #66cc66;">/</span>canvas&gt;</span><br />
<br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/body.html"><span style="color: #000000; font-weight: bold;">body</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/html.html"><span style="color: #000000; font-weight: bold;">html</span></a>&gt;</span></div></td></tr></tbody></table></div>
<h3>The JavaScript</h3>
<p>The magic that makes the mask work in canvas is the context&#8217;s method called clip.  This just tells the canvas to hide everything outside of the shape just defined.  Which is perfect for making a mask.</p>
<p><strong>Here is the JavaScript:</strong></p>
<div class="codecolorer-container javascript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><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="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">window.<span style="color: #000066;">onload</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//Setup the canvas.</span><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> canvas <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;stage&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>canvas.<span style="color: #660066;">getContext</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> ctx <span style="color: #339933;">=</span> canvas.<span style="color: #660066;">getContext</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;2d&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//Load the image.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> img <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;image&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//Set the canvas to the size of the image.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; canvas.<span style="color: #660066;">width</span> <span style="color: #339933;">=</span> img.<span style="color: #660066;">width</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; canvas.<span style="color: #660066;">height</span> <span style="color: #339933;">=</span> img.<span style="color: #660066;">height</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//Draw the Circle Mask.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; ctx.<span style="color: #660066;">fillStyle</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;#f30&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; ctx.<span style="color: #660066;">beginPath</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">// (centerX, centerY, radius, starting angle, end angle, counter clockwise)</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; ctx.<span style="color: #660066;">arc</span><span style="color: #009900;">&#40;</span>img.<span style="color: #660066;">width</span> <span style="color: #339933;">/</span> <span style="color: #CC0000;">2</span><span style="color: #339933;">,</span>img.<span style="color: #660066;">height</span> <span style="color: #339933;">/</span> <span style="color: #CC0000;">2</span><span style="color: #339933;">,</span>img.<span style="color: #660066;">width</span> <span style="color: #339933;">/</span> <span style="color: #CC0000;">2</span><span style="color: #339933;">,</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span>Math.<span style="color: #660066;">PI</span> <span style="color: #339933;">*</span> <span style="color: #CC0000;">2</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; ctx.<span style="color: #660066;">fill</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//Makes the circle into a mask.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; ctx.<span style="color: #660066;">clip</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//Draws image.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; ctx.<span style="color: #660066;">drawImage</span><span style="color: #009900;">&#40;</span>img<span style="color: #339933;">,</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>So after loading in the image, we create a circle that we&#8217;ll use as the mask.  Directly after we set the clip which does it&#8217;s magic. We then load the image into the canvas, when we do so it gets masked by the circle that we created earlier.</p>
<h3>That&#8217;s it</h3>
<p><strong>Here it is all together:</strong></p>
<div class="codecolorer-container html4strict default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><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 /></div></td><td><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #00bbdd;">&lt;!DOCTYPE HTML&gt;</span><br />
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/html.html"><span style="color: #000000; font-weight: bold;">html</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/head.html"><span style="color: #000000; font-weight: bold;">head</span></a>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/meta.html"><span style="color: #000000; font-weight: bold;">meta</span></a> <span style="color: #000066;">charset</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;UTF-8&quot;</span>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/title.html"><span style="color: #000000; font-weight: bold;">title</span></a>&gt;</span>Image Mask<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/title.html"><span style="color: #000000; font-weight: bold;">title</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/head.html"><span style="color: #000000; font-weight: bold;">head</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/body.html"><span style="color: #000000; font-weight: bold;">body</span></a>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">&lt;!-- If the browser doesn't support canvas, just the image will be displayed. --&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;canvas <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;stage&quot;</span>&gt;&lt;<a href="http://december.com/html/4/element/img.html"><span style="color: #000000; font-weight: bold;">img</span></a> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;mask.jpg&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;image&quot;</span> <span style="color: #000066;">alt</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #66cc66;">/</span>&gt;&lt;<span style="color: #66cc66;">/</span>canvas&gt;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; window.onload = function (){<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //Setup the canvas.<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var canvas = document.getElementById(&quot;stage&quot;);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (canvas.getContext) {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var ctx = canvas.getContext(&quot;2d&quot;);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //Load the image.<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var img = document.getElementById(&quot;image&quot;);<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //Set the canvas to the size of the image.<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; canvas.width = img.width;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; canvas.height = img.height;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //Draw the Circle Mask.<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ctx.fillStyle = &quot;#f30&quot;;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ctx.beginPath();<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // (centerX, centerY, radius, starting angle, end angle, counter clockwise)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ctx.arc(img.width / 2,img.height / 2,img.width / 2,0,Math.PI * 2, false);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ctx.fill();<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //Makes the circle into a mask.<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ctx.clip();<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //Draws image.<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ctx.drawImage(img,0,0);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; };<br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/body.html"><span style="color: #000000; font-weight: bold;">body</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/html.html"><span style="color: #000000; font-weight: bold;">html</span></a>&gt;</span></div></td></tr></tbody></table></div>
<p>Not much too this one.  If you want it to get working in IE you&#8217;ll have to find a Canvas polyfill to help you out. The most notable one is probably <a href="http://code.google.com/p/explorercanvas/" target="_blank">explorercanvas</a>.  Enjoy.</p>
<div class="resources"><a class="Download" href="http://devirtuoso.com/Examples/HTML5ImageMask/html5ImageMask.zip" target="_blank">Download</a> <a class="Example" href="http://www.devirtuoso.com/Examples/HTML5ImageMask/" target="_blank">Example</a></div>

<p><a href="http://feedads.g.doubleclick.net/~a/d9OY2SDwo69jmpXXGSkRYQb_S9g/0/da"><img src="http://feedads.g.doubleclick.net/~a/d9OY2SDwo69jmpXXGSkRYQb_S9g/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/d9OY2SDwo69jmpXXGSkRYQb_S9g/1/da"><img src="http://feedads.g.doubleclick.net/~a/d9OY2SDwo69jmpXXGSkRYQb_S9g/1/di" border="0" ismap="true"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/Devirtuoso?a=myDqDaK7K_I:ptrA0fjfuFM:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/Devirtuoso?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Devirtuoso?a=myDqDaK7K_I:ptrA0fjfuFM:TzevzKxY174"><img src="http://feeds.feedburner.com/~ff/Devirtuoso?d=TzevzKxY174" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Devirtuoso?a=myDqDaK7K_I:ptrA0fjfuFM:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/Devirtuoso?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Devirtuoso?a=myDqDaK7K_I:ptrA0fjfuFM:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/Devirtuoso?i=myDqDaK7K_I:ptrA0fjfuFM:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Devirtuoso?a=myDqDaK7K_I:ptrA0fjfuFM:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/Devirtuoso?i=myDqDaK7K_I:ptrA0fjfuFM:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Devirtuoso?a=myDqDaK7K_I:ptrA0fjfuFM:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/Devirtuoso?i=myDqDaK7K_I:ptrA0fjfuFM:F7zBnMyn0Lo" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/Devirtuoso/~4/myDqDaK7K_I" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.devirtuoso.com/2011/09/creating-an-image-mask-with-html-5-canvas/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.devirtuoso.com/2011/09/creating-an-image-mask-with-html-5-canvas/</feedburner:origLink></item>
		<item>
		<title>Minify and Gzip CSS in JavaScript</title>
		<link>http://feedproxy.google.com/~r/Devirtuoso/~3/-710RG944b8/</link>
		<comments>http://www.devirtuoso.com/2011/09/minify-and-gzip-css-an-javascript/#comments</comments>
		<pubDate>Wed, 21 Sep 2011 13:30:03 +0000</pubDate>
		<dc:creator>Shawn</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[development Tools]]></category>
		<category><![CDATA[Front End Development]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[compress]]></category>
		<category><![CDATA[gzip]]></category>
		<category><![CDATA[minify]]></category>

		<guid isPermaLink="false">http://www.devirtuoso.com/?p=1404</guid>
		<description><![CDATA[Found a pretty cool site.  It allows users to minify and compress both their CSS and JavaScript. So I thought I would just share it with you so you can bask in it&#8217;s speed inducing glory. zBugs Although still in beta at this point in time, zBugs has an easy to use interface which makes [...]]]></description>
			<content:encoded><![CDATA[<p>Found a pretty cool site.  It allows users to minify and compress both their CSS and JavaScript. So I thought I would just share it with you so you can bask in it&#8217;s speed inducing glory.<span id="more-1404"></span></p>
<h3>zBugs</h3>
<p>Although still in beta at this point in time, zBugs has an easy to use interface which makes compressing and minifying easy.  The coolest thing of all, if you sign up they give you a FREE CDN link to your compressed and minified files&#8230;..SWEEET.  They also have an xml sitemap generator, which is handy. Be sure to check them out, well worth the look in my humble opinion.</p>
<p><a title="zBugs - Minify and Compress CSS and JavaScript" href="http://www.zbugs.com" target="_blank">http://www.zbugs.com</a></p>
<p><a href="http://www.zbugs.com"><img class="alignnone size-full wp-image-1405" title="zBugs" src="http://www.devirtuoso.com/wp-content/uploads/2011/09/zBugs.jpg" alt="zBugs - Minify and Compress CSS and JavaScipt" width="500" height="210" /></a></p>

<p><a href="http://feedads.g.doubleclick.net/~a/thvGGnRwD1ZajzMt34BnbyJ_tlo/0/da"><img src="http://feedads.g.doubleclick.net/~a/thvGGnRwD1ZajzMt34BnbyJ_tlo/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/thvGGnRwD1ZajzMt34BnbyJ_tlo/1/da"><img src="http://feedads.g.doubleclick.net/~a/thvGGnRwD1ZajzMt34BnbyJ_tlo/1/di" border="0" ismap="true"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/Devirtuoso?a=-710RG944b8:Px_-FRbX3OY:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/Devirtuoso?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Devirtuoso?a=-710RG944b8:Px_-FRbX3OY:TzevzKxY174"><img src="http://feeds.feedburner.com/~ff/Devirtuoso?d=TzevzKxY174" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Devirtuoso?a=-710RG944b8:Px_-FRbX3OY:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/Devirtuoso?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Devirtuoso?a=-710RG944b8:Px_-FRbX3OY:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/Devirtuoso?i=-710RG944b8:Px_-FRbX3OY:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Devirtuoso?a=-710RG944b8:Px_-FRbX3OY:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/Devirtuoso?i=-710RG944b8:Px_-FRbX3OY:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Devirtuoso?a=-710RG944b8:Px_-FRbX3OY:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/Devirtuoso?i=-710RG944b8:Px_-FRbX3OY:F7zBnMyn0Lo" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/Devirtuoso/~4/-710RG944b8" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.devirtuoso.com/2011/09/minify-and-gzip-css-an-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.devirtuoso.com/2011/09/minify-and-gzip-css-an-javascript/</feedburner:origLink></item>
		<item>
		<title>Working with images and HTML5 Canvas locally</title>
		<link>http://feedproxy.google.com/~r/Devirtuoso/~3/b8L1UET9RUM/</link>
		<comments>http://www.devirtuoso.com/2011/09/working-with-images-and-html5-canvas-locally/#comments</comments>
		<pubDate>Fri, 16 Sep 2011 19:47:31 +0000</pubDate>
		<dc:creator>Shawn</dc:creator>
				<category><![CDATA[Front End Development]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[base64 images]]></category>
		<category><![CDATA[Canvas]]></category>
		<category><![CDATA[HTML 5]]></category>

		<guid isPermaLink="false">http://www.devirtuoso.com/?p=1392</guid>
		<description><![CDATA[A problem that I often run into with while working locally with Canvas is the security error that comes with working with images on my local machine or cross domain. This post will give you a work around that will work if in a bind. The Error If you ever come across : Uncaught Error: [...]]]></description>
			<content:encoded><![CDATA[<p>A problem that I often run into with while working locally with Canvas is the security error that comes with working with images on my local machine or cross domain.  This post will give you a work around that will work if in a bind.<br />
<span id="more-1392"></span></p>
<h2>The Error</h2>
<p>If you ever come across : Uncaught Error: SECURITY_ERR: DOM Exception 18 , you&#8217;re not alone.  This error is triggered if you&#8217;re trying to get the imageData from an image that lives on your machine, or cross domain&#8230;.good times.  Kind of a pain&#8230;of course most errors are <img src='http://www.devirtuoso.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />  </p>
<p>Here is an example that will make the error trigger.</p>
<div class="codecolorer-container html4strict default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><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 /></div></td><td><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/img.html"><span style="color: #000000; font-weight: bold;">img</span></a> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;test.jpg&quot;</span> <span style="color: #000066;">alt</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;&quot;</span> &nbsp;<span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;image&quot;</span><span style="color: #66cc66;">/</span>&gt;</span><br />
<br />
<span style="color: #009900;">&lt;canvas <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;stage&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span>canvas&gt;</span><br />
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a>&gt;</span><br />
&nbsp; &nbsp; var canvas = document.getElementById(&quot;stage&quot;);<br />
&nbsp; &nbsp; var image = document.getElementById(&quot;image&quot;);<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; if (canvas.getContext) {<br />
&nbsp; &nbsp; &nbsp; &nbsp; var context = canvas.getContext(&quot;2d&quot;);<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; image.onload = function (){<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;canvas.width = image.width;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;canvas.height = image.height;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;context.drawImage(image,0,0);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //You will get an ERROR -&gt; Uncaught Error: SECURITY_ERR: DOM Exception 18<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var imageData = context.getImageData(0,0,image.width,image.height);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; console.log(imageData);<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; }<br />
&nbsp; &nbsp; <br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a>&gt;</span></div></td></tr></tbody></table></div>
<h2>The Solution</h2>
<p>I&#8217;m sure there are a couple of ways to handle this but the one I came across was to encode the image into base64.  This way the image is embedded right into your html page.  Preventing the browser from having to go off site to get your image.</p>
<p>Fantastic news right&#8230;.but how do I use a base64 image?  In any img&#8217;s src you can put a data source in place of the image&#8217;s path.  This is what one might look like:</p>
<div class="codecolorer-container html4strict default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/img.html"><span style="color: #000000; font-weight: bold;">img</span></a> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;data:image/jpeg;base64,iVBORw0KGgoAAAANSUhEUgAAADIA...really long string&quot;</span> <span style="color: #000066;">alt</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span></div></td></tr></tbody></table></div>
<p><img src="http://www.devirtuoso.com/wp-content/uploads/2011/09/base64Image.png" alt="base64 image explination" /></p>
<p>Here is a <a href="http://www.greywyvern.com/code/php/binary2base64" target="_blank">handy tool</a> to help you encode your images.</p>
<p>So now to get the earlier code working, we just have to replace the image&#8217;s src information with the base64 image data we got from the site.</p>
<p>Here is that in all it&#8217;s glory:</p>
<div class="codecolorer-container html4strict default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><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 /></div></td><td><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/img.html"><span style="color: #000000; font-weight: bold;">img</span></a> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;data:image/jpeg;base64,/9j/4AAQSkZJRgABAgAAZABkAAD/7AA...&quot;</span> <span style="color: #000066;">alt</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;&quot;</span> &nbsp;<span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;image&quot;</span><span style="color: #66cc66;">/</span>&gt;</span><br />
<br />
<span style="color: #009900;">&lt;canvas <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;stage&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span>canvas&gt;</span><br />
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a>&gt;</span><br />
&nbsp; &nbsp; var canvas = document.getElementById(&quot;stage&quot;);<br />
&nbsp; &nbsp; var image = document.getElementById(&quot;image&quot;);<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; if (canvas.getContext) {<br />
&nbsp; &nbsp; &nbsp; &nbsp; var context = canvas.getContext(&quot;2d&quot;);<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; image.onload = function (){<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;canvas.width = image.width;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;canvas.height = image.height;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;context.drawImage(image,0,0);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //This works now because of our image's source is now embedded.<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var imageData = context.getImageData(0,0,image.width,image.height);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; console.log(imageData);<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; }<br />
&nbsp; &nbsp; <br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a>&gt;</span></div></td></tr></tbody></table></div>
<div class="resources"><a class="Download" href="http://devirtuoso.com/Examples/Base64Image/base64Image.zip" target="_blank">Download</a> <a class="Example" href="http://www.devirtuoso.com/Examples/Base64Image" target="_blank">Example</a></div>
<p>Of course once you push it to a server you&#8217;d probably want to change this, as it blows up the size of the image by quite a bit.  The fix isn&#8217;t pretty, but at least you&#8217;ll be able to work locally in all your canvas-y goodness.</p>

<p><a href="http://feedads.g.doubleclick.net/~a/5ISiroarl3VN6u3Gbmezch45gPY/0/da"><img src="http://feedads.g.doubleclick.net/~a/5ISiroarl3VN6u3Gbmezch45gPY/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/5ISiroarl3VN6u3Gbmezch45gPY/1/da"><img src="http://feedads.g.doubleclick.net/~a/5ISiroarl3VN6u3Gbmezch45gPY/1/di" border="0" ismap="true"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/Devirtuoso?a=b8L1UET9RUM:5i1aWYH-wDs:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/Devirtuoso?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Devirtuoso?a=b8L1UET9RUM:5i1aWYH-wDs:TzevzKxY174"><img src="http://feeds.feedburner.com/~ff/Devirtuoso?d=TzevzKxY174" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Devirtuoso?a=b8L1UET9RUM:5i1aWYH-wDs:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/Devirtuoso?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Devirtuoso?a=b8L1UET9RUM:5i1aWYH-wDs:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/Devirtuoso?i=b8L1UET9RUM:5i1aWYH-wDs:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Devirtuoso?a=b8L1UET9RUM:5i1aWYH-wDs:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/Devirtuoso?i=b8L1UET9RUM:5i1aWYH-wDs:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Devirtuoso?a=b8L1UET9RUM:5i1aWYH-wDs:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/Devirtuoso?i=b8L1UET9RUM:5i1aWYH-wDs:F7zBnMyn0Lo" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/Devirtuoso/~4/b8L1UET9RUM" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.devirtuoso.com/2011/09/working-with-images-and-html5-canvas-locally/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.devirtuoso.com/2011/09/working-with-images-and-html5-canvas-locally/</feedburner:origLink></item>
		<item>
		<title>Creating a 3D Scrolling Carousel with CSS3 and JQuery</title>
		<link>http://feedproxy.google.com/~r/Devirtuoso/~3/EOC_X0fzSUI/</link>
		<comments>http://www.devirtuoso.com/2011/09/creating-a-3d-scrolling-carousel-with-css3-and-jquery/#comments</comments>
		<pubDate>Wed, 14 Sep 2011 18:57:36 +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[CSS3]]></category>
		<category><![CDATA[JQuery]]></category>

		<guid isPermaLink="false">http://www.devirtuoso.com/?p=1371</guid>
		<description><![CDATA[How do you make your CSS3 awesome? By creating something 3D of course. I thought that was a given This tutorial will show how to do just that&#8230;.awesomify your CSS3. CSS3 Scrolling Carousel What we&#8217;re trying to build here is a carousel that scrolls when the user uses the browser&#8217;s scroll bar. Allowing the user [...]]]></description>
			<content:encoded><![CDATA[<p>How do you make your CSS3 awesome? By creating something 3D of course. I thought that was a given <img src='http://www.devirtuoso.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />  This tutorial will show how to do just that&#8230;.awesomify your CSS3.<br />
<span id="more-1371"></span></p>
<h3>CSS3 Scrolling Carousel</h3>
<p>What we&#8217;re trying to build here is a carousel that scrolls when the user uses the browser&#8217;s scroll bar.  Allowing the user to navigate in a way they&#8217;re already familiar with.</p>
<h2 style="color:red">Note: This will only work with webkit browsers (I found Chrome to be finicky, works on mac&#8230;not so much on pc). Safari is your best bet. Transform 3D still isn&#8217;t fully supported yet.</h2>
<p></p>
<div class="resources"><a class="Download" href="http://devirtuoso.com/Examples/CSS3Carousel/css3Carousel.zip" target="_blank">Download</a> <a class="Example" href="http://www.devirtuoso.com/Examples/CSS3Carousel">Example</a></div>
<h3>The HTML</h3>
<p>Really we just need something to scroll, and a container to hold everything pretty simple HTML.  We&#8217;re just going to make sure each item has a class associated with it so we can reference it later in jQuery.</p>
<div class="codecolorer-container html4strict default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><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="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #00bbdd;">&lt;!DOCTYPE HTML&gt;</span><br />
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/html.html"><span style="color: #000000; font-weight: bold;">html</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/head.html"><span style="color: #000000; font-weight: bold;">head</span></a>&gt;</span><br />
&nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/meta.html"><span style="color: #000000; font-weight: bold;">meta</span></a> <span style="color: #000066;">charset</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;UTF-8&quot;</span>&gt;</span><br />
&nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/title.html"><span style="color: #000000; font-weight: bold;">title</span></a>&gt;</span>3d Carousel<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/title.html"><span style="color: #000000; font-weight: bold;">title</span></a>&gt;</span><br />
&nbsp; <br />
&nbsp; <span style="color: #808080; font-style: italic;">&lt;!-- CSS will go here --&gt;</span><br />
&nbsp; <br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/head.html"><span style="color: #000000; font-weight: bold;">head</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/body.html"><span style="color: #000000; font-weight: bold;">body</span></a>&gt;</span><br />
&nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;main&quot;</span>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;slide1&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;slide&quot;</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; Slide 1<br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;slide2&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;slide&quot;</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; Slide 2<br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;slide3&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;slide&quot;</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; Slide 3<br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;slide4&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;slide&quot;</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; Slide 4<br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;slide5&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;slide&quot;</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; Slide 5<br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;slide6&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;slide&quot;</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; Slide 6<br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span><br />
<br />
&nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span><br />
&nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js&quot;</span> &gt;&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a>&gt;</span><br />
&nbsp; <span style="color: #808080; font-style: italic;">&lt;!-- jQuery will go here --&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/body.html"><span style="color: #000000; font-weight: bold;">body</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/html.html"><span style="color: #000000; font-weight: bold;">html</span></a>&gt;</span></div></td></tr></tbody></table></div>
<h3>The CSS</h3>
<p>There are 3 important things that are going to happen in the CSS.</p>
<ol>
<li>Give the body a big min-height to enable scrolling.</li>
<li>Give our main container a fixed position so it doesn&#8217;t move when we scroll and setting the transform style so it acts like a 3d space. (Things closer to the user are in front of things further away)</li>
<li>Setup each slide to be position absolute to move freely.</li>
</ol>
<p>Most of the heavy lifting will be done in the jQuery.  The CSS will just set up each slide so it can move freely in 3d space, and make sure the screen has a scroll bar.  The jQuery will link the scroll bar to the each slide.</p>
<div class="codecolorer-container css default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><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 /></div></td><td><div class="css codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">body<span style="color: #00AA00;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/* Enable the scroll bar */</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">min-height</span><span style="color: #00AA00;">:</span><span style="color: #933;">5000px</span><span style="color: #00AA00;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/* Centering the carousel */</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">200px</span><span style="color: #00AA00;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span><span style="color: #933;">30px</span> <span style="color: #993333;">auto</span> <span style="color: #933;">0px</span><span style="color: #00AA00;">;</span><br />
<span style="color: #00AA00;">&#125;</span><br />
<br />
<span style="color: #cc00cc;">#main</span><span style="color: #00AA00;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/* Make sure everything works in a 3d space. */</span><br />
&nbsp; &nbsp; -webkit-transform-style<span style="color: #00AA00;">:</span> preserve-3d<span style="color: #00AA00;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/* Adjusting the perspective...make it look more roundish */</span><br />
&nbsp; &nbsp; -webkit-perspective<span style="color: #00AA00;">:</span> <span style="color: #933;">1800px</span><span style="color: #00AA00;">;</span> <br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/* Rotating the angle a bit so it isn't face on */</span> &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; -webkit-transform<span style="color: #00AA00;">:</span> rotateY<span style="color: #00AA00;">&#40;</span>10deg<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/* Make sure the carousel doesn't move when we scroll */</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">fixed</span><span style="color: #00AA00;">;</span><br />
<span style="color: #00AA00;">&#125;</span><br />
.slide<span style="color: #00AA00;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/* Make sure it can move freely */</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span><span style="color: #993333;">absolute</span><span style="color: #00AA00;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">block</span><span style="color: #00AA00;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/* Set the dimensions */</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">200px</span><span style="color: #00AA00;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">200px</span><span style="color: #00AA00;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/* Positioning text in the middle of the box */</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">text-align</span><span style="color: #00AA00;">:</span><span style="color: #993333;">center</span><span style="color: #00AA00;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">line-height</span><span style="color: #00AA00;">:</span><span style="color: #933;">200px</span><span style="color: #00AA00;">;</span><br />
<br />
<br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/* An easing effect*/</span><br />
&nbsp; &nbsp; -webkit-transition<span style="color: #00AA00;">:</span> all 800ms cubic-bezier<span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">0.260</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">0.860</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">0.440</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">0.985</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span> <br />
<br />
<span style="color: #00AA00;">&#125;</span><br />
<br />
<span style="color: #808080; font-style: italic;">/*<br />
* Change the colors of each slide so we can tell them apart.<br />
*/</span><br />
<br />
<span style="color: #cc00cc;">#slide1</span><span style="color: #00AA00;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #993333;">green</span><span style="color: #00AA00;">;</span> &nbsp;<br />
<span style="color: #00AA00;">&#125;</span> &nbsp; &nbsp;<br />
<span style="color: #cc00cc;">#slide2</span><span style="color: #00AA00;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">blue</span><span style="color: #00AA00;">;</span> &nbsp;<br />
<span style="color: #00AA00;">&#125;</span> &nbsp; &nbsp;<br />
<span style="color: #cc00cc;">#slide3</span><span style="color: #00AA00;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span>pink<span style="color: #00AA00;">;</span> &nbsp;<br />
<span style="color: #00AA00;">&#125;</span> &nbsp; &nbsp;<br />
<span style="color: #cc00cc;">#slide4</span><span style="color: #00AA00;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span>orange<span style="color: #00AA00;">;</span> &nbsp;<br />
<span style="color: #00AA00;">&#125;</span> &nbsp; &nbsp;<br />
<span style="color: #cc00cc;">#slide5</span><span style="color: #00AA00;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #993333;">silver</span><span style="color: #00AA00;">;</span> &nbsp;<br />
<span style="color: #00AA00;">&#125;</span> &nbsp; &nbsp;<br />
<span style="color: #cc00cc;">#slide6</span><span style="color: #00AA00;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #993333;">purple</span><span style="color: #00AA00;">;</span> &nbsp;<br />
<span style="color: #00AA00;">&#125;</span></div></td></tr></tbody></table></div>
<p>A couple of things that were used that might need some explanation.  </p>
<ol>
<li>-webkit-perspective: 1800px; &#8211; The -webkit-perspective adjusts how the 3d will look, or in camera terms what kind of lens. Do we want it to look fish eye or relatively flat.</li>
<li>-webkit-transform: rotateY(10deg); &#8211; This just rotates everything along the y axis.</li>
<li>-webkit-transition: all 800ms cubic-bezier(0.260, 0.860, 0.440, 0.985);  &#8211; cubic-bezier just creates a nice easing effect after a user stops scrolling.  You can play around with the values to get it how you want it to look.  This was just used to increase the geekiness of the code. <img src='http://www.devirtuoso.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </li>
</ol>
<h3>The JQuery</h3>
<p>So here comes the cool part. The JQuery sets up each slide on the carousel. Once a user scrolls, it then updates each slide in the carousel, rotating it accordingly.</p>
<div class="codecolorer-container javascript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><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 /></div></td><td><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; <br />
&nbsp; <span style="color: #006600; font-style: italic;">//Go through each slide.</span><br />
&nbsp; $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.slide'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>index<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//Figure out how many slides, then give each slide a slice of the pie.</span><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> length <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.slide'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">length</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> degree <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #CC0000;">360</span> <span style="color: #339933;">/</span> length<span style="color: #009900;">&#41;</span> <span style="color: #339933;">|</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//Set the slide's reference to the starting point on the carousel.</span><br />
&nbsp; &nbsp; $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;data&quot;</span><span style="color: #339933;">,</span>degree <span style="color: #339933;">*</span> index<span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//Position the slide on the carousel using css</span><br />
&nbsp; &nbsp; $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><span style="color: #3366CC;">&quot;-webkit-transform&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">'translate3d(0,100%,0) rotateX('</span><span style="color: #339933;">+</span>degree <span style="color: #339933;">*</span> index<span style="color: #339933;">+</span><span style="color: #3366CC;">'deg) translate3d(0,100%,0)'</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; <br />
&nbsp; <br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//When the window scrolls....</span><br />
&nbsp; &nbsp; $<span style="color: #009900;">&#40;</span>window<span style="color: #009900;">&#41;</span>.<span style="color: #000066;">scroll</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//Figure out how far down we've scrolled. (Value from 0 - 1)</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> percent <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">scrollTop</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> <span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'body'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">height</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> $<span style="color: #009900;">&#40;</span>window<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">height</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//The new rotation based on how far down the user scrolled</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; degrees <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>percent <span style="color: #339933;">*</span> <span style="color: #CC0000;">360</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">|</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//Go through each slide..</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.slide'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>index<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> startDegree <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;data&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//Add the degrees to whatever the starting point was.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> val <span style="color: #339933;">=</span> degrees <span style="color: #339933;">+</span> parseInt<span style="color: #009900;">&#40;</span>startDegree<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//Apply the css</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><span style="color: #3366CC;">&quot;-webkit-transform&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">'translate3d(0,100%,0) rotateX('</span><span style="color: #339933;">+</span>val<span style="color: #339933;">+</span><span style="color: #3366CC;">'deg) translate3d(0,100%,0)'</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <br />
&nbsp; <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>A little explanation. We first figure out where each slide should be on the carousel, by figuring out how many degrees should separate each slide.  So we divide 360 degrees by how many slides we have.  That should tell us where on the circle each slide should reside.</p>
<p><img src="http://www.devirtuoso.com/wp-content/uploads/2011/09/degrees.png" alt="Degrees around the carousel" /></p>
<p>As for the CSS transform, we first position the slide in the center of the carousel.  Rotate the slide to the desired degree.  Then push it away from the center along the axis that it was rotated.</p>
<p><img src="http://www.devirtuoso.com/wp-content/uploads/2011/09/cssTransformation.png" alt="css webkit transform explination" /></p>
<h3>That&#8217;s it</h3>
<p>Feel free to play around with the values.  You can easily change it from verticle to horizontal by playing around with the axis it rotates and which direction it is pushed with the translate3d.  Have fun with it!</p>
<p>Here is everything all together:</p>
<div class="codecolorer-container html4strict default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><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 />119<br />120<br />121<br />122<br />123<br />124<br />125<br />126<br />127<br />128<br />129<br />130<br />131<br />132<br />133<br />134<br />135<br />136<br />137<br />138<br />139<br />140<br />141<br />142<br />143<br />144<br />145<br />146<br />147<br />148<br />149<br />150<br />151<br />152<br /></div></td><td><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #00bbdd;">&lt;!DOCTYPE HTML&gt;</span><br />
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/html.html"><span style="color: #000000; font-weight: bold;">html</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/head.html"><span style="color: #000000; font-weight: bold;">head</span></a>&gt;</span><br />
&nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/meta.html"><span style="color: #000000; font-weight: bold;">meta</span></a> <span style="color: #000066;">charset</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;UTF-8&quot;</span>&gt;</span><br />
&nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/title.html"><span style="color: #000000; font-weight: bold;">title</span></a>&gt;</span>3d Carousel<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/title.html"><span style="color: #000000; font-weight: bold;">title</span></a>&gt;</span><br />
&nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/style.html"><span style="color: #000000; font-weight: bold;">style</span></a>&gt;</span><br />
&nbsp; <br />
&nbsp; body{<br />
&nbsp; &nbsp; &nbsp; /* Enable the scroll bar */<br />
&nbsp; &nbsp; &nbsp; min-height:5000px;<br />
<br />
&nbsp; &nbsp; &nbsp; /* Centering the carousel */<br />
&nbsp; &nbsp; &nbsp; width:200px;<br />
&nbsp; &nbsp; &nbsp; margin:30px auto 0px;<br />
&nbsp; &nbsp; &nbsp; <br />
&nbsp; }<br />
<br />
&nbsp; #main{<br />
&nbsp; &nbsp; &nbsp; /* Make sure everything works in a 3d space. */<br />
&nbsp; &nbsp; &nbsp; -webkit-transform-style: preserve-3d;<br />
<br />
&nbsp; &nbsp; &nbsp; /* Adjusting the perspective...make it look more roundish */<br />
&nbsp; &nbsp; &nbsp; -webkit-perspective: 1800px; <br />
<br />
&nbsp; &nbsp; &nbsp; /* Rotating the angle a bit so it isn't face on */ &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; -webkit-transform: rotateY(10deg);<br />
<br />
&nbsp; &nbsp; &nbsp; /* Make sure the carousel doesn't move when we scroll */<br />
&nbsp; &nbsp; &nbsp; position: fixed;<br />
&nbsp; }<br />
&nbsp; .slide{<br />
&nbsp; &nbsp; &nbsp; /* Make sure it can move freely */<br />
&nbsp; &nbsp; &nbsp; position:absolute;<br />
&nbsp; &nbsp; &nbsp; display:block;<br />
<br />
&nbsp; &nbsp; &nbsp; /* Set the dimensions */<br />
&nbsp; &nbsp; &nbsp; width:200px;<br />
&nbsp; &nbsp; &nbsp; height:200px;<br />
<br />
&nbsp; &nbsp; &nbsp; /* Positioning text in the middle of the box */<br />
&nbsp; &nbsp; &nbsp; text-align:center;<br />
&nbsp; &nbsp; &nbsp; line-height:200px;<br />
<br />
<br />
&nbsp; &nbsp; &nbsp; /* An easing effect*/<br />
&nbsp; &nbsp; &nbsp; -webkit-transition: all 800ms cubic-bezier(0.260, 0.860, 0.440, 0.985); <br />
<br />
&nbsp; }<br />
<br />
&nbsp; /*<br />
&nbsp; * Change the colors of each slide so we can tell them apart.<br />
&nbsp; */<br />
<br />
&nbsp; #slide1{<br />
&nbsp; &nbsp; &nbsp; background:green; &nbsp;<br />
&nbsp; } &nbsp; &nbsp;<br />
&nbsp; #slide2{<br />
&nbsp; &nbsp; &nbsp; background:blue; &nbsp;<br />
&nbsp; } &nbsp; &nbsp;<br />
&nbsp; #slide3{<br />
&nbsp; &nbsp; &nbsp; background:pink; &nbsp;<br />
&nbsp; } &nbsp; &nbsp;<br />
&nbsp; #slide4{<br />
&nbsp; &nbsp; &nbsp; background:orange; &nbsp;<br />
&nbsp; } &nbsp; &nbsp;<br />
&nbsp; #slide5{<br />
&nbsp; &nbsp; &nbsp; background:silver; &nbsp;<br />
&nbsp; } &nbsp; &nbsp;<br />
&nbsp; #slide6{<br />
&nbsp; &nbsp; &nbsp; background:purple; &nbsp;<br />
&nbsp; }<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <br />
&nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/style.html"><span style="color: #000000; font-weight: bold;">style</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/head.html"><span style="color: #000000; font-weight: bold;">head</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/body.html"><span style="color: #000000; font-weight: bold;">body</span></a>&gt;</span><br />
&nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;main&quot;</span>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;slide1&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;slide&quot;</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; Slide 1<br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;slide2&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;slide&quot;</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; Slide 2<br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;slide3&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;slide&quot;</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; Slide 3<br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;slide4&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;slide&quot;</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; Slide 4<br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;slide5&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;slide&quot;</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; Slide 5<br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;slide6&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;slide&quot;</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; Slide 6<br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span><br />
<br />
&nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span><br />
&nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js&quot;</span> &gt;&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a>&gt;</span><br />
&nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a>&gt;</span><br />
&nbsp; &nbsp; $(document).ready(function() {<br />
&nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; //Go through each slide.<br />
&nbsp; &nbsp; &nbsp; $('.slide').each(function(index) {<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; //Figure out how many slides, then give each slide a slice of the pie.<br />
&nbsp; &nbsp; &nbsp; &nbsp; var length = $('.slide').length;<br />
&nbsp; &nbsp; &nbsp; &nbsp; var degree = (360 / length) | 0;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; //Set a reference to the starting point on the carousel.<br />
&nbsp; &nbsp; &nbsp; &nbsp; $(this).attr(&quot;data&quot;,degree * index)<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; //Position the slide on the carousel using css<br />
&nbsp; &nbsp; &nbsp; &nbsp; //-webkit-transform: Pushes the whole carousel down from top : Rotates the carousel : The radius of the carousel<br />
&nbsp; &nbsp; &nbsp; &nbsp; $(this).css({&quot;-webkit-transform&quot;: 'translate3d(0,100%,0) rotateX('+degree * index+'deg) translate3d(0,100%,0)'});<br />
&nbsp; &nbsp; &nbsp; });<br />
&nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; //When the window scrolls....<br />
&nbsp; &nbsp; &nbsp; &nbsp; $(window).scroll(function(e) {<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //Figure out how far down we've scrolled. (Value from 0 - 1)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var percent = (($(this).scrollTop()) / ($('body').height() - $(window).height()));<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //The new rotation based on how far down the user scrolled<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; degrees = (percent * 360) | 0;<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //Go through each slide..<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $('.slide').each(function(index) {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var startDegree = $(this).attr(&quot;data&quot;);<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //Add the degrees to whatever the starting point was.<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var val = degrees + parseInt(startDegree);<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //Apply the css<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //-webkit-transform: Pushes the whole carousel down from top : Rotates the carousel : The keeps the radius of the carousel<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $(this).css({&quot;-webkit-transform&quot;: 'translate3d(0,100%,0) rotateX('+val+'deg) translate3d(0,100%,0)'});<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; });<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; });<br />
&nbsp; &nbsp; });<br />
&nbsp; &nbsp; <br />
&nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/body.html"><span style="color: #000000; font-weight: bold;">body</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/html.html"><span style="color: #000000; font-weight: bold;">html</span></a>&gt;</span></div></td></tr></tbody></table></div>
<div class="resources"><a class="Download" href="http://devirtuoso.com/Examples/CSS3Carousel/css3Carousel.zip" target="_blank">Download</a> <a class="Example" href="http://www.devirtuoso.com/Examples/CSS3Carousel">Example</a></div>

<p><a href="http://feedads.g.doubleclick.net/~a/6laPT9CHcvCwc_B0Y7t3e-wmaco/0/da"><img src="http://feedads.g.doubleclick.net/~a/6laPT9CHcvCwc_B0Y7t3e-wmaco/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/6laPT9CHcvCwc_B0Y7t3e-wmaco/1/da"><img src="http://feedads.g.doubleclick.net/~a/6laPT9CHcvCwc_B0Y7t3e-wmaco/1/di" border="0" ismap="true"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/Devirtuoso?a=EOC_X0fzSUI:8AfS_iyixF4:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/Devirtuoso?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Devirtuoso?a=EOC_X0fzSUI:8AfS_iyixF4:TzevzKxY174"><img src="http://feeds.feedburner.com/~ff/Devirtuoso?d=TzevzKxY174" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Devirtuoso?a=EOC_X0fzSUI:8AfS_iyixF4:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/Devirtuoso?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Devirtuoso?a=EOC_X0fzSUI:8AfS_iyixF4:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/Devirtuoso?i=EOC_X0fzSUI:8AfS_iyixF4:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Devirtuoso?a=EOC_X0fzSUI:8AfS_iyixF4:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/Devirtuoso?i=EOC_X0fzSUI:8AfS_iyixF4:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Devirtuoso?a=EOC_X0fzSUI:8AfS_iyixF4:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/Devirtuoso?i=EOC_X0fzSUI:8AfS_iyixF4:F7zBnMyn0Lo" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/Devirtuoso/~4/EOC_X0fzSUI" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.devirtuoso.com/2011/09/creating-a-3d-scrolling-carousel-with-css3-and-jquery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.devirtuoso.com/2011/09/creating-a-3d-scrolling-carousel-with-css3-and-jquery/</feedburner:origLink></item>
		<item>
		<title>Canvas Image Manipulation Experiment</title>
		<link>http://feedproxy.google.com/~r/Devirtuoso/~3/QI2BeqOEeB0/</link>
		<comments>http://www.devirtuoso.com/2011/09/canvas-image-manipulation-experiment/#comments</comments>
		<pubDate>Fri, 09 Sep 2011 16:17:32 +0000</pubDate>
		<dc:creator>Shawn</dc:creator>
				<category><![CDATA[Experimental]]></category>
		<category><![CDATA[Front End Development]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Labs]]></category>
		<category><![CDATA[Canvas]]></category>
		<category><![CDATA[HTML 5]]></category>

		<guid isPermaLink="false">http://www.devirtuoso.com/?p=1350</guid>
		<description><![CDATA[There are plenty of cool things that HTML 5 has to offer. Here lies an experiment with the canvas and image manipulation. Oh what FUN! Canvas Experiment (Best viewed on Chrome / Safari) Just a brief description of what I built. We first pull in all the image data, and convert them to particles. Then [...]]]></description>
			<content:encoded><![CDATA[<p>There are plenty of cool things that <strong>HTML 5</strong> has to offer.  Here lies an experiment with the <strong>canvas</strong> and image manipulation. Oh what FUN!<br />
<span id="more-1350"></span></p>
<h2>Canvas Experiment (Best viewed on Chrome / Safari)</h2>
<p>Just a brief description of what I built.  We first pull in all the image data, and convert them to particles.  Then let the playing happen.  In this case I just made the particles jump away from the mouse, then jump back.  I heavily commented the code to help you look through it.</p>
<p><a class="Example" href="http://devirtuoso.com/Examples/ImageManipulation/" target="_blank"><img src="http://www.devirtuoso.com/wp-content/uploads/2011/09/imageManipulation.png" alt="Canvas Image Manipulation" /></a></p>
<h3 style="color: red;">Does not work locally! Image needs to be on server somewhere.</h3>
<p>If you try to load in a local image or an image from another domain you will get a javascript security error.  To get around this you can encode the image into base64.  <a href="http://www.greywyvern.com/code/php/binary2base64" target="_blank">Here is a handy tool for that&#8230;.very simple to use.</a></p>
<div class="resources"><a class="Download" href="http://devirtuoso.com/Examples/ImageManipulation/imageManipulation.zip" target="_blank">Download</a> <a class="Example" href="http://devirtuoso.com/Examples/ImageManipulation/" target="_blank">Example</a></div>
<p><a href="http://jsfiddle.net/devirtuoso/m2bbZ/embedded/result/" target="_blank">Play with the code on JSFiddle</a></p>
<div class="codecolorer-container html4strict default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><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 /></div></td><td><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #00bbdd;">&lt;!DOCTYPE HTML&gt;</span><br />
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/html.html"><span style="color: #000000; font-weight: bold;">html</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/head.html"><span style="color: #000000; font-weight: bold;">head</span></a>&gt;</span><br />
&nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/meta.html"><span style="color: #000000; font-weight: bold;">meta</span></a> <span style="color: #000066;">charset</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;UTF-8&quot;</span>&gt;</span><br />
&nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/title.html"><span style="color: #000000; font-weight: bold;">title</span></a>&gt;</span>Canvas Image<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/title.html"><span style="color: #000000; font-weight: bold;">title</span></a>&gt;</span><br />
&nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/style.html"><span style="color: #000000; font-weight: bold;">style</span></a>&gt;</span><br />
&nbsp; body{<br />
&nbsp; &nbsp; background:black;<br />
&nbsp; }<br />
&nbsp; &nbsp; canvas{<br />
&nbsp; &nbsp; &nbsp; width:900px;<br />
&nbsp; &nbsp; &nbsp; height:200px;<br />
&nbsp; &nbsp; &nbsp; background:none;<br />
&nbsp; &nbsp; }<br />
&nbsp; &nbsp; #canvasSource{<br />
&nbsp; &nbsp; &nbsp; display:none;<br />
&nbsp; &nbsp; }<br />
&nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/style.html"><span style="color: #000000; font-weight: bold;">style</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/head.html"><span style="color: #000000; font-weight: bold;">head</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/body.html"><span style="color: #000000; font-weight: bold;">body</span></a>&gt;</span><br />
&nbsp; &nbsp; <br />
<span style="color: #808080; font-style: italic;">&lt;!-- HTML Code --&gt;</span><br />
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/img.html"><span style="color: #000000; font-weight: bold;">img</span></a> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;canvasSource&quot;</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;picture.png&quot;</span> <span style="color: #000066;">alt</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Canvas Source&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span><br />
<br />
<span style="color: #009900;">&lt;canvas <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;area&quot;</span> <span style="color: #000066;">width</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;900&quot;</span> <span style="color: #000066;">height</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;200&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span>canvas&gt;</span><br />
<br />
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js&quot;</span> &gt;&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a>&gt;</span><br />
<br />
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a>&gt;</span><br />
//Image Manipulation Javascript will go here.<br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a>&gt;</span><br />
<br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/body.html"><span style="color: #000000; font-weight: bold;">body</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/html.html"><span style="color: #000000; font-weight: bold;">html</span></a>&gt;</span></div></td></tr></tbody></table></div>
<div class="codecolorer-container javascript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><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 />119<br />120<br />121<br />122<br />123<br />124<br />125<br />126<br />127<br />128<br />129<br />130<br />131<br />132<br />133<br />134<br />135<br />136<br />137<br />138<br />139<br />140<br />141<br />142<br />143<br />144<br />145<br />146<br />147<br />148<br />149<br />150<br />151<br />152<br />153<br />154<br />155<br />156<br />157<br />158<br />159<br />160<br />161<br />162<br />163<br />164<br />165<br />166<br />167<br />168<br />169<br />170<br />171<br />172<br />173<br />174<br />175<br />176<br />177<br />178<br />179<br />180<br />181<br />182<br />183<br />184<br />185<br />186<br />187<br />188<br />189<br />190<br />191<br />192<br />193<br />194<br />195<br />196<br />197<br />198<br />199<br />200<br />201<br />202<br />203<br />204<br />205<br />206<br />207<br />208<br />209<br />210<br />211<br />212<br />213<br />214<br />215<br />216<br />217<br />218<br />219<br />220<br />221<br />222<br />223<br />224<br />225<br />226<br />227<br />228<br />229<br />230<br />231<br />232<br />233<br />234<br />235<br />236<br />237<br />238<br />239<br />240<br />241<br />242<br />243<br />244<br />245<br />246<br />247<br />248<br />249<br />250<br />251<br />252<br />253<br />254<br />255<br />256<br />257<br />258<br />259<br />260<br />261<br />262<br />263<br />264<br />265<br />266<br />267<br />268<br />269<br />270<br />271<br />272<br />273<br />274<br />275<br />276<br />277<br />278<br />279<br />280<br />281<br />282<br />283<br />284<br />285<br />286<br />287<br />288<br />289<br />290<br />291<br />292<br />293<br />294<br />295<br />296<br />297<br />298<br />299<br />300<br />301<br />302<br />303<br />304<br />305<br /></div></td><td><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">window.<span style="color: #000066;">onload</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">/**<br />
&nbsp; &nbsp; * Checks if a pixel is white or not<br />
&nbsp; &nbsp; * @param {Object} pixel A pixel with an rgb value<br />
&nbsp; &nbsp; * @returns Is the pixel white or not.<br />
&nbsp; &nbsp; * @type Boolean<br />
&nbsp; &nbsp; */</span><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">function</span> isPixelWhite <span style="color: #009900;">&#40;</span>pixel<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #009900;">&#40;</span>pixel.<span style="color: #660066;">r</span> <span style="color: #339933;">&gt;</span> <span style="color: #CC0000;">50</span> <span style="color: #339933;">&amp;&amp;</span> pixel.<span style="color: #660066;">g</span> <span style="color: #339933;">&gt;</span> <span style="color: #CC0000;">50</span> <span style="color: #339933;">&amp;&amp;</span> pixel.<span style="color: #660066;">b</span> <span style="color: #339933;">&gt;</span> <span style="color: #CC0000;">50</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">/**<br />
&nbsp; &nbsp; * Converts an rgb value to hex<br />
&nbsp; &nbsp; * @param {Number} R The red value<br />
&nbsp; &nbsp; * @param {Number} G The green value<br />
&nbsp; &nbsp; * @param {Number} B The blue value<br />
&nbsp; &nbsp; * @returns A hex value based on the rgb given<br />
&nbsp; &nbsp; * @type String<br />
&nbsp; &nbsp; */</span><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">function</span> rgbToHex<span style="color: #009900;">&#40;</span>R<span style="color: #339933;">,</span>G<span style="color: #339933;">,</span>B<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">return</span> toHex<span style="color: #009900;">&#40;</span>R<span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span>toHex<span style="color: #009900;">&#40;</span>G<span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span>toHex<span style="color: #009900;">&#40;</span>B<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">/**<br />
&nbsp; &nbsp; * convert value from 0-255 to hex.<br />
&nbsp; &nbsp; * @param {Number} n Number between 0 and 255<br />
&nbsp; &nbsp; * @returns Hex value<br />
&nbsp; &nbsp; * @type String<br />
&nbsp; &nbsp; */</span><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">function</span> toHex<span style="color: #009900;">&#40;</span>n<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;n <span style="color: #339933;">=</span> parseInt<span style="color: #009900;">&#40;</span>n<span style="color: #339933;">,</span><span style="color: #CC0000;">10</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>isNaN<span style="color: #009900;">&#40;</span>n<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #3366CC;">&quot;00&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;n <span style="color: #339933;">=</span> Math.<span style="color: #660066;">max</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span>Math.<span style="color: #660066;">min</span><span style="color: #009900;">&#40;</span>n<span style="color: #339933;">,</span><span style="color: #CC0000;">255</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #3366CC;">&quot;0123456789ABCDEF&quot;</span>.<span style="color: #660066;">charAt</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>n<span style="color: #339933;">-</span>n<span style="color: #339933;">%</span>16<span style="color: #009900;">&#41;</span><span style="color: #339933;">/</span><span style="color: #CC0000;">16</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;0123456789ABCDEF&quot;</span>.<span style="color: #660066;">charAt</span><span style="color: #009900;">&#40;</span>n<span style="color: #339933;">%</span>16<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">/**<br />
&nbsp; &nbsp; * Extends an array with the given options<br />
&nbsp; &nbsp; * @param {Object} obj The main object<br />
&nbsp; &nbsp; * @param {Object} extObj The extending object<br />
&nbsp; &nbsp; * @returns The merged objects<br />
&nbsp; &nbsp; * @type Object<br />
&nbsp; &nbsp; */</span><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> extend <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>obj<span style="color: #339933;">,</span> extObj<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #003366; font-weight: bold;">var</span> i<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span>i <span style="color: #000066; font-weight: bold;">in</span> extObj<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>extObj<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;obj<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> extObj<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066; font-weight: bold;">return</span> obj<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">/**<br />
&nbsp; &nbsp; * Pixel Class<br />
&nbsp; &nbsp; * @author Shawn<br />
&nbsp; &nbsp; */</span><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> Particle <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>options<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//Default Values</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> params <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>color<span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;#fff&quot;</span><span style="color: #339933;">,</span>x<span style="color: #339933;">:</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> y<span style="color: #339933;">:</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span>width<span style="color: #339933;">:</span><span style="color: #CC0000;">1</span><span style="color: #339933;">,</span> height<span style="color: #339933;">:</span><span style="color: #CC0000;">1</span><span style="color: #339933;">,</span> angle<span style="color: #339933;">:</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> speed<span style="color: #339933;">:</span><span style="color: #CC0000;">3</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; params <span style="color: #339933;">=</span> extend<span style="color: #009900;">&#40;</span>params<span style="color: #339933;">,</span>options<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//Init Variables</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">color</span> <span style="color: #339933;">=</span> params.<span style="color: #660066;">color</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">x</span> <span style="color: #339933;">=</span> params.<span style="color: #660066;">x</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">y</span> <span style="color: #339933;">=</span> params.<span style="color: #660066;">y</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">originalX</span> <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">x</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">originalY</span> <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">y</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">width</span> <span style="color: #339933;">=</span> params.<span style="color: #660066;">width</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">height</span> <span style="color: #339933;">=</span> params.<span style="color: #660066;">height</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">angle</span> <span style="color: #339933;">=</span> params.<span style="color: #660066;">angle</span> <span style="color: #339933;">*</span> <span style="color: #009900;">&#40;</span> Math.<span style="color: #660066;">PI</span> <span style="color: #339933;">/</span> <span style="color: #CC0000;">180</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">speed</span> <span style="color: #339933;">=</span> params.<span style="color: #660066;">speed</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">/**<br />
&nbsp; &nbsp; * Sets x,y value based on current angle.<br />
&nbsp; &nbsp; * @returns <br />
&nbsp; &nbsp; * @type Void<br />
&nbsp; &nbsp; */</span><br />
&nbsp; &nbsp; Particle.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">getVector</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">x</span> <span style="color: #339933;">=</span> Math.<span style="color: #660066;">cos</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">angle</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">y</span> <span style="color: #339933;">=</span> Math.<span style="color: #660066;">sin</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">angle</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">/**<br />
&nbsp; &nbsp; * Sets the current angle<br />
&nbsp; &nbsp; * @param {Number} angle Angle to set it at<br />
&nbsp; &nbsp; * @returns Angle given, but rounded<br />
&nbsp; &nbsp; * @type Number<br />
&nbsp; &nbsp; */</span><br />
&nbsp; &nbsp; Particle.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">setAngle</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>angle<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//Convert to radians, so it's useful.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">angle</span> <span style="color: #339933;">=</span> angle <span style="color: #339933;">*</span> <span style="color: #009900;">&#40;</span> Math.<span style="color: #660066;">PI</span> <span style="color: #339933;">/</span> <span style="color: #CC0000;">180</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">return</span> angle <span style="color: #339933;">|</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">/**<br />
&nbsp; &nbsp; * Gets the current angle<br />
&nbsp; &nbsp; * @returns The current angle<br />
&nbsp; &nbsp; * @type Number<br />
&nbsp; &nbsp; */</span><br />
&nbsp; &nbsp; Particle.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">getAngle</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//Converts angle from radians to angle then rounds it.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">angle</span> <span style="color: #339933;">/</span> <span style="color: #009900;">&#40;</span> Math.<span style="color: #660066;">PI</span> <span style="color: #339933;">/</span> <span style="color: #CC0000;">180</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">|</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">/**<br />
&nbsp; &nbsp; * Emits particles<br />
&nbsp; &nbsp; * @author Shawn<br />
&nbsp; &nbsp; * @requires Particle<br />
&nbsp; &nbsp; */</span><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> Emitter <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//Initial values.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">maxParticles</span> <span style="color: #339933;">=</span> <span style="color: #CC0000;">20000</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">particles</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">active</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">x</span> <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">y</span> <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">/**<br />
&nbsp; &nbsp; * Adds a particle to the emitter<br />
&nbsp; &nbsp; * @param {Object} options Particle options<br />
&nbsp; &nbsp; * @returns The particle just added<br />
&nbsp; &nbsp; * @type Particle<br />
&nbsp; &nbsp; */</span><br />
&nbsp; &nbsp; Emitter.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">addParticle</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>options<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//Make sure there is less particles than the max amount</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">particles</span>.<span style="color: #660066;">length</span> <span style="color: #339933;">&lt;</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">maxParticles</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//Set particle default values.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> params <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>color<span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;#fff&quot;</span><span style="color: #339933;">,</span>x<span style="color: #339933;">:</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">x</span><span style="color: #339933;">,</span>y<span style="color: #339933;">:</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">y</span><span style="color: #339933;">,</span> width<span style="color: #339933;">:</span><span style="color: #CC0000;">1</span><span style="color: #339933;">,</span>height<span style="color: #339933;">:</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; params <span style="color: #339933;">=</span> extend<span style="color: #009900;">&#40;</span>params<span style="color: #339933;">,</span>options<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//Add particle to emitter.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> p <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Particle<span style="color: #009900;">&#40;</span>params<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; p.<span style="color: #660066;">id</span> <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">particles</span>.<span style="color: #660066;">length</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">particles</span>.<span style="color: #660066;">push</span><span style="color: #009900;">&#40;</span>p<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">return</span> p<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">/**<br />
&nbsp; &nbsp; * Gets a particle at a given identifier<br />
&nbsp; &nbsp; * @param {Number} id Particles identifier<br />
&nbsp; &nbsp; * @returns A particle<br />
&nbsp; &nbsp; * @type Particle<br />
&nbsp; &nbsp; */</span><br />
&nbsp; &nbsp; Emitter.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">getParticle</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>id<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">particles</span><span style="color: #009900;">&#91;</span>id<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">/**<br />
&nbsp; &nbsp; * Get how many particles there are.<br />
&nbsp; &nbsp; * @returns Number of particles<br />
&nbsp; &nbsp; * @type Number<br />
&nbsp; &nbsp; */</span><br />
&nbsp; &nbsp; Emitter.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">getLength</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">particles</span>.<span style="color: #660066;">length</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp;<span style="color: #006600; font-style: italic;">/**<br />
&nbsp; &nbsp;* Paul Irish's method for requesting animation frame<br />
&nbsp; &nbsp;* @returns Animation Frame<br />
&nbsp; &nbsp;* @type Function<br />
&nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; window.<span style="color: #660066;">requestAnimFrame</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">return</span> &nbsp;window.<span style="color: #660066;">requestAnimationFrame</span> &nbsp; &nbsp; &nbsp; <span style="color: #339933;">||</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; window.<span style="color: #660066;">webkitRequestAnimationFrame</span> <span style="color: #339933;">||</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; window.<span style="color: #660066;">mozRequestAnimationFrame</span> &nbsp; &nbsp;<span style="color: #339933;">||</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; window.<span style="color: #660066;">oRequestAnimationFrame</span> &nbsp; &nbsp; &nbsp;<span style="color: #339933;">||</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; window.<span style="color: #660066;">msRequestAnimationFrame</span> &nbsp; &nbsp; <span style="color: #339933;">||</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #006600; font-style: italic;">/* function */</span> callback<span style="color: #339933;">,</span> <span style="color: #006600; font-style: italic;">/* DOMElement */</span> element<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; window.<span style="color: #660066;">setTimeout</span><span style="color: #009900;">&#40;</span>callback<span style="color: #339933;">,</span> <span style="color: #CC0000;">1000</span> <span style="color: #339933;">/</span> <span style="color: #CC0000;">60</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//Setup canvas.</span><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> canvas <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;area&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> ctx <span style="color: #339933;">=</span> canvas.<span style="color: #660066;">getContext</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;2d&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> image <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;canvasSource&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; ctx.<span style="color: #660066;">drawImage</span><span style="color: #009900;">&#40;</span>image<span style="color: #339933;">,</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//get Image data.</span><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> imgData <span style="color: #339933;">=</span> ctx.<span style="color: #660066;">getImageData</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">900</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">200</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> pixels <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> init <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> mouseX<span style="color: #339933;">,</span> mouseY <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> affecetedArea <span style="color: #339933;">=</span> <span style="color: #CC0000;">70</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> emit <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Emitter<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> i<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//Create a particle based on the image data.</span><br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//Image data is ordered like r,g,b,a,r,g,b,a...need to count by 4</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span>i<span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> imgData.<span style="color: #660066;">data</span>.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">+=</span><span style="color: #CC0000;">4</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> pixel <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; pixel.<span style="color: #660066;">r</span> <span style="color: #339933;">=</span> imgData.<span style="color: #660066;">data</span><span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; pixel.<span style="color: #660066;">g</span> <span style="color: #339933;">=</span> imgData.<span style="color: #660066;">data</span><span style="color: #009900;">&#91;</span>i<span style="color: #339933;">+</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; pixel.<span style="color: #660066;">b</span> <span style="color: #339933;">=</span> imgData.<span style="color: #660066;">data</span><span style="color: #009900;">&#91;</span>i<span style="color: #339933;">+</span><span style="color: #CC0000;">2</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; pixel.<span style="color: #660066;">index</span> <span style="color: #339933;">=</span> i <span style="color: #339933;">/</span> <span style="color: #CC0000;">4</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//Setup columns and rows</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; pixel.<span style="color: #660066;">x</span> <span style="color: #339933;">=</span> pixel.<span style="color: #660066;">index</span> <span style="color: #339933;">%</span> <span style="color: #CC0000;">900</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; pixel.<span style="color: #660066;">y</span> <span style="color: #339933;">=</span> Math.<span style="color: #660066;">floor</span><span style="color: #009900;">&#40;</span>pixel.<span style="color: #660066;">index</span> <span style="color: #339933;">/</span> <span style="color: #CC0000;">900</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//The white pixels are the only ones we want to animate.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>isPixelWhite<span style="color: #009900;">&#40;</span>pixel<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//Pick a random angle.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> angle <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>Math.<span style="color: #660066;">random</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> <span style="color: #CC0000;">360</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; emit.<span style="color: #660066;">addParticle</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>color<span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;#&quot;</span><span style="color: #339933;">+</span>rgbToHex<span style="color: #009900;">&#40;</span>pixel.<span style="color: #660066;">r</span><span style="color: #339933;">,</span>pixel.<span style="color: #660066;">g</span><span style="color: #339933;">,</span>pixel.<span style="color: #660066;">b</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">,</span>x<span style="color: #339933;">:</span> pixel.<span style="color: #660066;">x</span><span style="color: #339933;">,</span> y<span style="color: #339933;">:</span> pixel.<span style="color: #660066;">y</span><span style="color: #339933;">,</span> angle<span style="color: #339933;">:</span>angle <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">/**<br />
&nbsp; &nbsp; * Mouse Move Handler...set the mouseX and MouseY variables<br />
&nbsp; &nbsp; * @param {Object} e Event Object<br />
&nbsp; &nbsp; * @returns Nothing<br />
&nbsp; &nbsp; * @type Void<br />
&nbsp; &nbsp; */</span><br />
&nbsp; &nbsp; $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#area'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">mousemove</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>e.<span style="color: #660066;">offsetX</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mouseX <span style="color: #339933;">=</span> e.<span style="color: #660066;">offsetX</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mouseY <span style="color: #339933;">=</span> e.<span style="color: #660066;">offsetY</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #000066; font-weight: bold;">else</span> <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>e.<span style="color: #660066;">layerX</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mouseX <span style="color: #339933;">=</span> e.<span style="color: #660066;">layerX</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mouseY <span style="color: #339933;">=</span> e.<span style="color: #660066;">layerY</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//Start animation loop.</span><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">function</span> animate<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; requestAnimFrame<span style="color: #009900;">&#40;</span> animate <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; draw<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; animate<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> oldx<span style="color: #339933;">,</span>oldy<span style="color: #339933;">,</span>newx<span style="color: #339933;">,</span>newy<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">/**<br />
&nbsp; &nbsp; * Draws each frame<br />
&nbsp; &nbsp; * @returns Nothing<br />
&nbsp; &nbsp; * @type Void<br />
&nbsp; &nbsp; */</span><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">function</span> draw<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> i<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; canvas.<span style="color: #660066;">width</span> <span style="color: #339933;">=</span> <span style="color: #CC0000;">900</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; canvas.<span style="color: #660066;">height</span> <span style="color: #339933;">=</span> <span style="color: #CC0000;">200</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//Render each particle in the emitter.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span>i<span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> emit.<span style="color: #660066;">getLength</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> p <span style="color: #339933;">=</span> emit.<span style="color: #660066;">getParticle</span><span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//Calculate the distance of the particle from the mouse.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> distx <span style="color: #339933;">=</span> p.<span style="color: #660066;">x</span> <span style="color: #339933;">-</span> mouseX<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> disty <span style="color: #339933;">=</span> p.<span style="color: #660066;">y</span> <span style="color: #339933;">-</span> mouseY<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> distance <span style="color: #339933;">=</span> Math.<span style="color: #660066;">sqrt</span><span style="color: #009900;">&#40;</span>distx<span style="color: #339933;">*</span>distx <span style="color: #339933;">+</span> disty<span style="color: #339933;">*</span>disty<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//If it's within the affected area.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>distance <span style="color: #339933;">&lt;</span> affecetedArea<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//Push the particle out of the way.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//p.x -= (Where the particle currently is - Where you want the particle to end up) / speed</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; p.<span style="color: #660066;">x</span> <span style="color: #339933;">-=</span> <span style="color: #009900;">&#40;</span>p.<span style="color: #660066;">x</span> <span style="color: #339933;">-</span> <span style="color: #009900;">&#40;</span>mouseX <span style="color: #339933;">+</span> affecetedArea <span style="color: #339933;">*</span> distx <span style="color: #339933;">/</span> distance<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> <span style="color: #CC0000;">5</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; p.<span style="color: #660066;">y</span> <span style="color: #339933;">-=</span> <span style="color: #009900;">&#40;</span>p.<span style="color: #660066;">y</span> <span style="color: #339933;">-</span> <span style="color: #009900;">&#40;</span>mouseY <span style="color: #339933;">+</span> affecetedArea <span style="color: #339933;">*</span> disty <span style="color: #339933;">/</span> distance<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> <span style="color: #CC0000;">5</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #000066; font-weight: bold;">else</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//Return the particle to it's original place.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>p.<span style="color: #660066;">x</span> <span style="color: #339933;">!=</span> p.<span style="color: #660066;">originalX</span> <span style="color: #339933;">||</span> p.<span style="color: #660066;">y</span> <span style="color: #339933;">!=</span> p.<span style="color: #660066;">originalY</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; p.<span style="color: #660066;">x</span> <span style="color: #339933;">-=</span> <span style="color: #009900;">&#40;</span>p.<span style="color: #660066;">x</span> <span style="color: #339933;">-</span> p.<span style="color: #660066;">originalX</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> <span style="color: #CC0000;">2</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; p.<span style="color: #660066;">y</span> <span style="color: #339933;">-=</span> <span style="color: #009900;">&#40;</span>p.<span style="color: #660066;">y</span> <span style="color: #339933;">-</span> p.<span style="color: #660066;">originalY</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> <span style="color: #CC0000;">2</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//Draw the particle</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ctx.<span style="color: #660066;">fillStyle</span> <span style="color: #339933;">=</span> p.<span style="color: #660066;">color</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ctx.<span style="color: #660066;">fillRect</span><span style="color: #009900;">&#40;</span>p.<span style="color: #660066;">x</span><span style="color: #339933;">,</span>p.<span style="color: #660066;">y</span><span style="color: #339933;">,</span>p.<span style="color: #660066;">width</span><span style="color: #339933;">,</span>p.<span style="color: #660066;">width</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <br />
<br />
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>

<p><a href="http://feedads.g.doubleclick.net/~a/_vb0fEZ4W50L0ElmsqXCXIdZVpk/0/da"><img src="http://feedads.g.doubleclick.net/~a/_vb0fEZ4W50L0ElmsqXCXIdZVpk/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/_vb0fEZ4W50L0ElmsqXCXIdZVpk/1/da"><img src="http://feedads.g.doubleclick.net/~a/_vb0fEZ4W50L0ElmsqXCXIdZVpk/1/di" border="0" ismap="true"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/Devirtuoso?a=QI2BeqOEeB0:vbXUap6S8W4:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/Devirtuoso?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Devirtuoso?a=QI2BeqOEeB0:vbXUap6S8W4:TzevzKxY174"><img src="http://feeds.feedburner.com/~ff/Devirtuoso?d=TzevzKxY174" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Devirtuoso?a=QI2BeqOEeB0:vbXUap6S8W4:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/Devirtuoso?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Devirtuoso?a=QI2BeqOEeB0:vbXUap6S8W4:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/Devirtuoso?i=QI2BeqOEeB0:vbXUap6S8W4:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Devirtuoso?a=QI2BeqOEeB0:vbXUap6S8W4:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/Devirtuoso?i=QI2BeqOEeB0:vbXUap6S8W4:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Devirtuoso?a=QI2BeqOEeB0:vbXUap6S8W4:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/Devirtuoso?i=QI2BeqOEeB0:vbXUap6S8W4:F7zBnMyn0Lo" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/Devirtuoso/~4/QI2BeqOEeB0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.devirtuoso.com/2011/09/canvas-image-manipulation-experiment/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.devirtuoso.com/2011/09/canvas-image-manipulation-experiment/</feedburner:origLink></item>
		<item>
		<title>Toggle Switches with JQuery and Checkboxes</title>
		<link>http://feedproxy.google.com/~r/Devirtuoso/~3/YmRmaOUervk/</link>
		<comments>http://www.devirtuoso.com/2011/05/toggle-switches-with-jquery-and-checkboxes/#comments</comments>
		<pubDate>Wed, 25 May 2011 14:30:58 +0000</pubDate>
		<dc:creator>Shawn</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[Front End Development]]></category>
		<category><![CDATA[How to]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://www.devirtuoso.com/?p=1324</guid>
		<description><![CDATA[iOS style checkboxes (toggle switches) are far more user friendly than ye ol&#8217; browser checkboxes.  Without feeling to sorry for your browser checkboxes, we&#8217;re going to go through creating new toggle switch hotness with jQuery. What are we building? Well I&#8217;m glad you asked.  We&#8217;re going to take a progressive enhancement approach to this.  We [...]]]></description>
			<content:encoded><![CDATA[<p>iOS style checkboxes (toggle switches) are far more user friendly than ye ol&#8217; browser checkboxes.  Without feeling to sorry for your browser checkboxes, we&#8217;re going to go through creating new toggle switch hotness with jQuery.<br />
<span id="more-1324"></span></p>
<h2>What are we building?</h2>
<p>Well I&#8217;m glad you asked.  We&#8217;re going to take a progressive enhancement approach to this.  We want to make sure that the checkboxes still work if JavaScript is turned off.  So with jQuery we&#8217;ll add the new toggle switches, and make them check off the hidden checkboxes when clicked.</p>
<div class="resources"><a class="Download" href="http://www.devirtuoso.com/Examples/toggleSwitch/toggleSwitch.zip" target="_blank">Download</a> <a class="Example" href="http://www.devirtuoso.com/Examples/toggleSwitch/" target="_blank">Example</a></div>
<h2>Getting Started: <span>The HTML</span></h2>
<p>Nothing to crazy going on here.  It&#8217;s just a simple form with some checkboxes.  I added a class to the checkboxes just for ease of use.  Not really necessary if you&#8217;d rather reference them by some other means.  Also I gave the body tag a class of &#8220;nojs&#8221; so we can change this to &#8220;js&#8221; with JavaScript.  This way we can react appropriately when someone doesn&#8217;t have javascript enabled.</p>
<div class="codecolorer-container html4strict default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><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 /></div></td><td><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/body.html"><span style="color: #000000; font-weight: bold;">body</span></a> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;nojs&quot;</span>&gt;</span><br />
&nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/h1.html"><span style="color: #000000; font-weight: bold;">h1</span></a>&gt;</span>Toggle Checkboxes<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/h1.html"><span style="color: #000000; font-weight: bold;">h1</span></a>&gt;</span><br />
&nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/form.html"><span style="color: #000000; font-weight: bold;">form</span></a> <span style="color: #000066;">action</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #000066;">method</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;get&quot;</span>&gt;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">&lt;!--</span><br />
<span style="color: #808080; font-style: italic;"> &nbsp; &nbsp; &nbsp;Enjoy Web</span><br />
<span style="color: #808080; font-style: italic;"> &nbsp; &nbsp;--&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span> &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/label.html"><span style="color: #000000; font-weight: bold;">label</span></a> <span style="color: #000066;">for</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;enjoy_web&quot;</span>&gt;</span>Do you enjoy web development?<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/label.html"><span style="color: #000000; font-weight: bold;">label</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/input.html"><span style="color: #000000; font-weight: bold;">input</span></a> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;checkbox&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;checkbox&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;enjoy_web&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;yes&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;enjoy_web&quot;</span> <span style="color: #000066;">checked</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">&lt;!--</span><br />
<span style="color: #808080; font-style: italic;"> &nbsp; &nbsp; &nbsp;Hate IE</span><br />
<span style="color: #808080; font-style: italic;"> &nbsp; &nbsp;--&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span> &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/label.html"><span style="color: #000000; font-weight: bold;">label</span></a> <span style="color: #000066;">for</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;enjoy_web&quot;</span>&gt;</span>Do you hate IE?<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/label.html"><span style="color: #000000; font-weight: bold;">label</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/input.html"><span style="color: #000000; font-weight: bold;">input</span></a> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;checkbox&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;checkbox&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;hate_ie&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;yes&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;hate_ie&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br />
<br />
<br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">&lt;!--</span><br />
<span style="color: #808080; font-style: italic;"> &nbsp; &nbsp; &nbsp;Sad Pandas</span><br />
<span style="color: #808080; font-style: italic;"> &nbsp; &nbsp;--&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span> &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/label.html"><span style="color: #000000; font-weight: bold;">label</span></a> <span style="color: #000066;">for</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;enjoy_web&quot;</span>&gt;</span>Do pandas make you sad?<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/label.html"><span style="color: #000000; font-weight: bold;">label</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/input.html"><span style="color: #000000; font-weight: bold;">input</span></a> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;checkbox&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;checkbox&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;sad_panda&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;yes&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;sad_panda&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br />
<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;&lt;<a href="http://december.com/html/4/element/a.html"><span style="color: #000000; font-weight: bold;">a</span></a> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;showCheckboxes&quot;</span>&gt;</span>Show Checkboxes<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/a.html"><span style="color: #000000; font-weight: bold;">a</span></a>&gt;&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br />
&nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/form.html"><span style="color: #000000; font-weight: bold;">form</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/body.html"><span style="color: #000000; font-weight: bold;">body</span></a>&gt;</span></div></td></tr></tbody></table></div>
<h2>The jQuery</h2>
<p>The first thing we need to tackle is progressive enhancement.  So we&#8217;re just going to change the body class to &#8220;js&#8221;, so now in our css we can hide all checkboxes when the javascript is enabled.</p>
<p>After that we add an anchor tag after each checkbox.  This will be our toggle switch with the magic of css styling.  When we create this anchor we&#8217;ll add a ref attribute which reference the checkbox that it will affect.  Also we&#8217;ll add a checked class to the anchor tag if the checkbox is already checked.</p>
<p>Then it just comes down to creating a click event for our new anchor tag.  This will just toggle on and off a checked attribute of the checkbox referenced in the anchor&#8217;s ref tag.</p>
<div class="codecolorer-container javascript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><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 /></div></td><td><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">/*<br />
&nbsp; &nbsp; &nbsp; Progressive enhancement. &nbsp;If javascript is enabled we change the body class. &nbsp;Which in turn hides the checkboxes with css.<br />
&nbsp; &nbsp; */</span><br />
&nbsp; &nbsp; $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'body'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;class&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;js&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">/*<br />
&nbsp; &nbsp; &nbsp; Add toggle switch after each checkbox. &nbsp;If checked, then toggle the switch.<br />
&nbsp; &nbsp; */</span><br />
&nbsp; &nbsp; &nbsp;$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.checkbox'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">after</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #000066; font-weight: bold;">is</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;:checked&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #3366CC;">&quot;&lt;a href='#' class='toggle checked' ref='&quot;</span><span style="color: #339933;">+</span>$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;id&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;'&gt;&lt;/a&gt;&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #009900;">&#125;</span><span style="color: #000066; font-weight: bold;">else</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #3366CC;">&quot;&lt;a href='#' class='toggle' ref='&quot;</span><span style="color: #339933;">+</span>$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;id&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;'&gt;&lt;/a&gt;&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp;<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp;<span style="color: #006600; font-style: italic;">/*<br />
&nbsp; &nbsp; &nbsp; When the toggle switch is clicked, check off / de-select the associated checkbox<br />
&nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.toggle'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #003366; font-weight: bold;">var</span> checkboxID <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;ref&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #003366; font-weight: bold;">var</span> checkbox <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#'</span><span style="color: #339933;">+</span>checkboxID<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>checkbox.<span style="color: #000066; font-weight: bold;">is</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;:checked&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;checkbox.<span style="color: #660066;">removeAttr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;checked&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #009900;">&#125;</span><span style="color: #000066; font-weight: bold;">else</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;checkbox.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;checked&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;true&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">toggleClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;checked&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp;e.<span style="color: #660066;">preventDefault</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<h2>CSS: <span>The Styling of the Toggle Switch</span></h2>
<p>There is nothing to crazy here.  If you&#8217;ve ever done a sprite button, you won&#8217;t find too much new here.  We&#8217;re just giving the anchor a background of toggle switch graphic and shifting it up and down depending on whether it has a checked class or not.</p>
<p>Also we&#8217;re hiding all checkboxes if javascript is enabled.</p>
<div class="codecolorer-container css default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><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 /></div></td><td><div class="css codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #6666ff;">.js</span> .checkbox<span style="color: #00AA00;">&#123;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">none</span><span style="color: #00AA00;">;</span><br />
<span style="color: #00AA00;">&#125;</span><br />
<br />
.toggle<span style="color: #00AA00;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">&quot;toggle.png&quot;</span><span style="color: #00AA00;">&#41;</span> <span style="color: #000000; font-weight: bold;">bottom</span> <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span><br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">block</span><span style="color: #00AA00;">;</span><br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">70px</span><span style="color: #00AA00;">;</span><br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">22px</span><span style="color: #00AA00;">;</span><br />
<span style="color: #00AA00;">&#125;</span><br />
<br />
<span style="color: #6666ff;">.toggle</span>.checked<span style="color: #00AA00;">&#123;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">background-position</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">top</span> <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span><br />
<span style="color: #00AA00;">&#125;</span></div></td></tr></tbody></table></div>
<h2>That&#8217;s it</h2>
<p>Not too hard was it?  You can play around with the code at <a href="http://jsfiddle.net/devirtuoso/KnGAc/" target="_blank">jsfiddle</a></p>

<p><a href="http://feedads.g.doubleclick.net/~a/bUisaB5rVXqdX6yoHL-xhkf4mMA/0/da"><img src="http://feedads.g.doubleclick.net/~a/bUisaB5rVXqdX6yoHL-xhkf4mMA/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/bUisaB5rVXqdX6yoHL-xhkf4mMA/1/da"><img src="http://feedads.g.doubleclick.net/~a/bUisaB5rVXqdX6yoHL-xhkf4mMA/1/di" border="0" ismap="true"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/Devirtuoso?a=YmRmaOUervk:zTw9CuMI8rk:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/Devirtuoso?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Devirtuoso?a=YmRmaOUervk:zTw9CuMI8rk:TzevzKxY174"><img src="http://feeds.feedburner.com/~ff/Devirtuoso?d=TzevzKxY174" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Devirtuoso?a=YmRmaOUervk:zTw9CuMI8rk:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/Devirtuoso?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Devirtuoso?a=YmRmaOUervk:zTw9CuMI8rk:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/Devirtuoso?i=YmRmaOUervk:zTw9CuMI8rk:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Devirtuoso?a=YmRmaOUervk:zTw9CuMI8rk:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/Devirtuoso?i=YmRmaOUervk:zTw9CuMI8rk:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Devirtuoso?a=YmRmaOUervk:zTw9CuMI8rk:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/Devirtuoso?i=YmRmaOUervk:zTw9CuMI8rk:F7zBnMyn0Lo" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/Devirtuoso/~4/YmRmaOUervk" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.devirtuoso.com/2011/05/toggle-switches-with-jquery-and-checkboxes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.devirtuoso.com/2011/05/toggle-switches-with-jquery-and-checkboxes/</feedburner:origLink></item>
		<item>
		<title>The Future of the Web is WebGL</title>
		<link>http://feedproxy.google.com/~r/Devirtuoso/~3/FbdzN8nL1y4/</link>
		<comments>http://www.devirtuoso.com/2011/03/the-future-of-the-web-is-webgl/#comments</comments>
		<pubDate>Fri, 04 Mar 2011 16:18:25 +0000</pubDate>
		<dc:creator>Shawn</dc:creator>
				<category><![CDATA[Experimental]]></category>
		<category><![CDATA[Front End Development]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[WebGL]]></category>

		<guid isPermaLink="false">http://www.devirtuoso.com/?p=1317</guid>
		<description><![CDATA[So what&#8217;s in store for the web in the future?  Is it more bejeweled games? Or is it 3d first person shooters?A big shout out goes to Human Engines and Gregg Tavares.  This is a demo I came accross of WebGL in all it&#8217;s glory and had to share it.  The performance is pretty good [...]]]></description>
			<content:encoded><![CDATA[<p>So what&#8217;s in store for the web in the future?  Is it more bejeweled games? Or is it 3d first person shooters?<span id="more-1317"></span>A big shout out goes to Human Engines and Gregg Tavares.  This is a demo I came accross of WebGL in all it&#8217;s glory and had to share it.  The performance is pretty good considering all the reflections and volumetrics.  Very cool stuff.</p>
<p>You can check out the experiment at: <strong>THIS REQUIRES GOOGLE CHROME</strong></p>
<p><a href="http://webglsamples.googlecode.com/hg/aquarium/aquarium.html" target="_blank">http://webglsamples.googlecode.com/hg/aquarium/aquarium.html</a></p>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="640" height="390" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowScriptAccess" value="always" /><param name="src" value="http://www.youtube.com/v/9pM9LBcKxK4&amp;hl=en_US&amp;feature=player_embedded&amp;version=3" /><param name="allowfullscreen" value="true" /><embed type="application/x-shockwave-flash" width="640" height="390" src="http://www.youtube.com/v/9pM9LBcKxK4&amp;hl=en_US&amp;feature=player_embedded&amp;version=3" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>

<p><a href="http://feedads.g.doubleclick.net/~a/X2IDoOhQIHEVptUR99vmv1ID9V4/0/da"><img src="http://feedads.g.doubleclick.net/~a/X2IDoOhQIHEVptUR99vmv1ID9V4/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/X2IDoOhQIHEVptUR99vmv1ID9V4/1/da"><img src="http://feedads.g.doubleclick.net/~a/X2IDoOhQIHEVptUR99vmv1ID9V4/1/di" border="0" ismap="true"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/Devirtuoso?a=FbdzN8nL1y4:Y5_FhnUMaS0:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/Devirtuoso?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Devirtuoso?a=FbdzN8nL1y4:Y5_FhnUMaS0:TzevzKxY174"><img src="http://feeds.feedburner.com/~ff/Devirtuoso?d=TzevzKxY174" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Devirtuoso?a=FbdzN8nL1y4:Y5_FhnUMaS0:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/Devirtuoso?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Devirtuoso?a=FbdzN8nL1y4:Y5_FhnUMaS0:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/Devirtuoso?i=FbdzN8nL1y4:Y5_FhnUMaS0:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Devirtuoso?a=FbdzN8nL1y4:Y5_FhnUMaS0:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/Devirtuoso?i=FbdzN8nL1y4:Y5_FhnUMaS0:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Devirtuoso?a=FbdzN8nL1y4:Y5_FhnUMaS0:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/Devirtuoso?i=FbdzN8nL1y4:Y5_FhnUMaS0:F7zBnMyn0Lo" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/Devirtuoso/~4/FbdzN8nL1y4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.devirtuoso.com/2011/03/the-future-of-the-web-is-webgl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.devirtuoso.com/2011/03/the-future-of-the-web-is-webgl/</feedburner:origLink></item>
	</channel>
</rss><!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Served from: www.devirtuoso.com @ 2012-01-30 12:13:52 -->

