<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>AddyOsmani.com &#124; Where User Interface Ideas Grows</title>
	<atom:link href="http://addyosmani.com/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://addyosmani.com/blog</link>
	<description>This is the home of Addy Osmani (Web Developer, Designer &#38; Author). Here you can find some great tips and tutorials on everything to do with web development and even a few useful code samples!</description>
	<lastBuildDate>Mon, 30 Aug 2010 01:37:50 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>WanderWall &#8211; A jQuery, CSS3 &amp; HTML5 Hover-Based Interface</title>
		<link>http://addyosmani.com/blog/wanderwall/</link>
		<comments>http://addyosmani.com/blog/wanderwall/#comments</comments>
		<pubDate>Mon, 23 Aug 2010 01:58:48 +0000</pubDate>
		<dc:creator>Addy</dc:creator>
				<category><![CDATA[Code Samples]]></category>
		<category><![CDATA[Design]]></category>
		<category><![CDATA[@font-face]]></category>
		<category><![CDATA[animated background]]></category>
		<category><![CDATA[background animation]]></category>
		<category><![CDATA[css3]]></category>
		<category><![CDATA[css3 indent effects]]></category>
		<category><![CDATA[css3 rotation]]></category>
		<category><![CDATA[hover]]></category>
		<category><![CDATA[hover based interface]]></category>
		<category><![CDATA[html5]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[jquery animated]]></category>
		<category><![CDATA[jquery animation]]></category>
		<category><![CDATA[jquery html5]]></category>
		<category><![CDATA[jquery user interface]]></category>
		<category><![CDATA[wanderwall]]></category>
		<category><![CDATA[wonderwall]]></category>

		<guid isPermaLink="false">http://addyosmani.com/blog/?p=1018</guid>
		<description><![CDATA[&#160; Hey guys. Today I&#8217;m going to teach you how to create a useful hover-based user interface using jQuery, CSS3, HTML5 and @font-face. Why a hover-based interface? you might ask. Well, with the popularity of touch-based web applications simplifying the way that people can use sites on mobile devices, I think that there&#8217;s room for [...]]]></description>
			<content:encoded><![CDATA[
<p><a href="http://addyosmani.com/blog/wanderwall/"><img width="530" height="342" border="0" src="http://addyosmani.com/blog/wp-content/uploads/wanderwalls2.jpg" alt="" /></a>&nbsp;</p>
<p>Hey guys. Today I&#8217;m going to teach you how to create a useful <a href="http://www.addyosmani.com/resources/wanderwall/index.html">hover-based</a> user interface using jQuery, CSS3, HTML5 and @font-face. Why a hover-based interface? you might ask. Well, with the popularity of touch-based web applications simplifying the way that people can use sites on mobile devices, I think that there&#8217;s room for us to look into ways of making it even easier for people to use sites in desktop-based browsers too. Today&#8217;s project,<a target="_blank" href="http://www.addyosmani.com/resources/wanderwall/index.html">WanderWall</a>, achieves that and what we&#8217;ll be creating today could easily be used for a portfolio or business site but the concepts you&#8217;ll learn could certainly be used to expand the idea further.</p>
<p><span id="more-1018"></span></p>
<p>If you&#8217;d like to check out a demo before we get started, feel free to check out one of three available below.</p>
<p>&nbsp;</p>
<div style="width: 500px;"><a href="http://www.addyosmani.com/resources/wanderwall/index.html" style="width: 100px; color: white; float: left;" class="large blue awesome tipper" target="_blank">View Demo 1</a>  <a href="http://www.addyosmani.com/resources/wanderwall/index2.html" style="width: 50px; color: white; float: left;" class="large blue awesome tipper" target="_blank">2</a>  <a href="http://www.addyosmani.com/resources/wanderwall/index3.html" style="width: 50px; color: white; float: left;" class="large blue awesome tipper" target="_blank">3</a> <a href="http://www.addyosmani.com/resources/wanderwall/jquerywanderwall.rar" style="width: 80px; color: white; float: left;" class="large blue awesome tipper" target="_blank">Download</a></div>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>you can also watch a screencast about WanderWall <a target="_blank" href="http://screenr.com/1P0">here</a>.</p>
<p style="text-align: center;"><img width="520" height="287" border="0" class="aligncenter size-full wp-image-1028" title="screenshot1" src="http://addyosmani.com/blog/wp-content/uploads/wand.jpg" alt="" /></p>
<p>&nbsp;</p>
<p><strong>What is a Hover-Based Interface?</strong></p>
<p>A hover-based interface is one where the majority (or all) of the user interaction on the page can be controlled by a user hovering over an element with their cursor. Hover-based interfaces require less work to see more content than a typical click based page, but do need some thought to be put into their design and structure so that the user knows how to navigate around. <a href="http://www.addyosmani.com/resources/wanderwall/index.html">WanderWall</a> uses a hover-based interface. Some might ask, well, mobile device&#8217;s don&#8217;t necessarily support the hover-over state, so should we really consider using them?.</p>
<p>I think the answer to this is definitely a firm yes. If you look at a number of the most popular site&#8217;s out there, they actually have two versions of their site available &#8211; one used for desktop browsers (full layout) and another which is optimized for mobile (touch focused). I think that hover UIs are certainly something we could consider for the former, but we of course would evaluate suitability on a site by site basis. I&#8217;m not saying that every site out there should adopt the concept, but there are cases where it would make navigation a quicker experience for users.</p>
<p><strong>Why Is WanderWall useful?</strong></p>
<p>That&#8217;s a very good question. I&#8217;m going to use a portfolio site as an example here as they tend to contain fewer pages. Even on a standard portfolio site, users typically have to click through a few different links to browse through the site (or &#8216;page&#8217; if it&#8217;s a one-page portfolio with anchor text). This only gets compounded as the sites you&#8217;re looking at grow larger. There&#8217;s nothing wrong with clicking par-se (it&#8217;s successfully worked as an action for years), but consider that users in general are lazy (I include myself in this group) &#8211; anything you can do to decrease the amount of work they have to do to look around your site will mean that they&#8217;re able to view your content more quickly.</p>
<p>What does this mean for you? Well if it&#8217;s a portfolio site, it may just mean more requests for work if you&#8217;ve been able to get the visitor&#8217;s interest before they got bored of clicking. Obviously this all depends on the quality of content etc as well, but if your average visitor spends less than 2 minutes on your page, who is going to have to work &#8216;less&#8217; to see your material &#8211; the person that clicks or the person that hovers?.</p>
<p>&nbsp;</p>
<p style="text-align: center;"><img width="420" height="171" class="aligncenter size-full wp-image-1029" title="screen4" alt="" src="http://addyosmani.com/blog/wp-content/uploads/2010/08/screen4.jpg" /></p>
<p>&nbsp;</p>
<p><strong>How Does WanderWall work?</strong></p>
<p style="text-align: center;"><strong><img width="500" height="331" src="http://addyosmani.com/blog/wp-content/uploads/2010/08/mock.gif" alt="" title="MockFlow" class="aligncenter size-full wp-image-1084" /></strong></p>
<p><a href="http://www.addyosmani.com/resources/wanderwall/index.html">WanderWall</a> is composed of two key components that interact with each other. Before we get started I should mention that for my demos I have included a background-image containing multiple parts to it (a pseudo-sprite) used in the header. We shall refer to this as the header-wallpaper.&nbsp; The components (without mentioning styling) are as follows:</p>
<p>1. Header-Slider: When a user hovers over one of the &#8216;frames&#8217; (links) in the header, this animates down to a position in the header-wallpaper with a unique background specific to that particular link. Once the header-wallpaper has been rendered, text specific to that section then fades in &#8211; essentially a subtitle or tagline for that page.</p>
<p>2. Page-Slider: At the same time that the user has hovered over a link in the header-slider, a corresponding &#8216;page&#8217; element slides into view (this is basically a div container which may contain text, images, video &#8211; any HTML content at all).</p>
<p>When a user hovers away from a particular link, the last page that they were looking at remains in view. The reason for this is that if there is further content on the page you may wish them to be able to hover-over on, scroll-down or click, they are able to do so.</p>
<p><strong>How does WanderWall make use of CSS3, @font-face and HTML5?</strong></p>
<p>CSS3 is used for the styling and design in WanderWall and assists with text-indentation, background-gradients and rotation. With the exception of my optional background-image, this allows the project to be relatively compact without sacrificing on design and asthetics. @font-face is used for the majority of typography and has been implemented in a cross-browser fashion with the assistance of Font-Squirrel&#8217;s excellent <a href="http://www.fontsquirrel.com/fontface/generator">generator</a>.</p>
<p>&nbsp;</p>
<p style="text-align: center;"><strong><img width="420" height="172" class="aligncenter size-full wp-image-1030" title="graph" alt="" src="http://addyosmani.com/blog/wp-content/uploads/2010/08/graph.jpg" /></strong></p>
<p>&nbsp;</p>
<p>I personally found font-face to be significantly faster than Cufon or sIFR in terms of the time taken to visibly-render, which makes sense as there is no JavaScript required to power it after page-load.&nbsp; HTML5 is used to power the data-tooltips that you find on the right-hand side of the screen. These leverage the &quot;data-&quot; attribute in HTML5.</p>
<p>For CSS purists, yes, you can of course achieve a similar effect without the need for the data-attribute here, but as I wished to include a sample of it&#8217;s potential usage, it&#8217;s been included in WanderWall as an optional feature. You can easily switch over to using jQuery based tooltips quite easily if you prefer.</p>
<p><strong>Let&#8217;s Create a WanderWall</strong></p>
<p>The first thing to do when creating a Hover-based interface is plan out how your interaction is going to work. I probably went through 12 different iterations planning this project before I was happy and it&#8217;s important to try thinking from a user&#8217;s perspective before you dive into the coding. Once that&#8217;s done, you&#8217;ll first want to write some HTML to define your page&#8217;s structure.</p>
<p><strong>HTML for the header frames (links)</strong></p>
<pre name="code" class="html">
<div id="wanderwall">
<div class="wrapper">
<div class="frame first" id="frame1">	<a alt="jQuery is used to power WanderWall's animations" href="#" id="link1" style="display: block;"> 	<span>jQuery</span> 	</a></div>
<div class="frame two" id="frame2">	<a alt="CSS3 is used for linear gradients and styling" href="#" id="link2" style="display: block;"> 	<span>CSS3</span> 	</a></div>
<div class="frame three" id="frame3"><a alt="HTML5 powers the data-tooltip tooltips" href="#" id="link3" style="display: block;"> <span>HTML5</span> </a></div>
<div class="frame fourth" id="frame4">	<a alt="Font-Face powers the fonts" href="#" id="link4" style="display: block;"> 	<span>@font-face</span> 	</a></div>
</div>
</div>
</pre>
<p><strong>HTML for the sliding pages</strong></p>
<pre name="code" class="html">
<div class="page">
<div class="mantletext">
<h3>jQuery</h3>
<h2>Wanderwall 1</h2>
</div>
</div>
<div class="page">
<div class="mantletext">
<h3>jQuery</h3>
<h2>Wanderwall 2</h2>
</div>
</div>
<div class="page">
<div class="mantletext">
<h3>jQuery</h3>
<h2>Wanderwall 3</h2>
</div>
</div>
<div class="page">
<div class="mantletext">
<h3>jQuery</h3>
<h2>Wanderwall 4</h2>
</div>
</div>
</pre>
<p>&nbsp;</p>
<p>In real life, you&#8217;ll probably define some very simple CSS to structure your design next, but to keep things simple, I&#8217;m first going to show you the important parts of the JavaScript in this project and then the final CSS3. (I recommend waiting until you&#8217;ve finishing the JavaScript side of things before &#8216;touching up&#8217; the design, but you do whatever feels most comfortable.)</p>
<p>&nbsp;</p>
<p><strong>jQuery For Background Animation (on frame hover)</strong></p>
<pre name="code" class="javascript">
$(&quot;div.frame a&quot;).hover(function()
	{

				var currentLink = $(this);
				hideTheRest(id); id = this.id.replace(&quot;link&quot;, &quot;&quot;);
				position = -295*id;
				marginnew =  pagewidth * id * -1;

                                /*Display the Home link if not currently on Default Page*/
				if(id &gt; 0)
				{
				  $('#homelink').show();
				}else{
				  $('#homelink').hide();
				}

				/*Move the page-slider in the correct direction depending on the ID*/
				$('.pageslider').stop().animate({marginLeft: marginnew}, 800);

				/*Animate the background*/
				$('#wanderwall').stop().animate({backgroundPosition:
                               '(50% ' + position +'px )'}, 500, function()
				{
				    distance = 0;
				    topdis   = -190;
				    text     = currentLink.attr('alt');
				    infoframe  = $('#infoframe');

				  /* Define offset for text*/
				  switch(id)
				  {
				    case &quot;1&quot;:
					     distance = 500;
						 break;
				    case &quot;2&quot;:
					     distance = 730;
						 break;
				    case &quot;3&quot;:
					     distance = 200;
						 break;
					case &quot;4&quot;:
					     distance = 400;
						 topdis = -198;
						 break;
				  }

				  infoframe.html(text);
				  infoframe.css('margin-left', distance + 'px');
				  infoframe.css('margin-top', topdis + 'px');
				  infoframe.fadeIn();
				});

	}, function()
	{

	   $('#infoframe').hide();
	   var id = this.id.replace(&quot;link&quot;, &quot;&quot;);
	   $('#wanderwall').stop().animate({backgroundPosition: '(50% 0px)'}, 500 );
	    showTheRest();

	});
</pre>
<p><strong>jQuery For Showing And Hiding Other Elements On Hover Of One</strong></p>
<pre class="javascript" name="code">
function hideTheRest(id){
		 for (var i=1; i&lt;5; i++){
			if (i!=id)
			{

				$('#frame' + i + ' a').css('display', 'block');
                                /*Set the alpha transparency*/
				$('#frame' + i).css('filter', 'alpha(opacity=80)');
                                /*Fast-fade animation*/
				$('#frame' + i).stop().fadeTo(&quot;fast&quot;,0);
                                /*Don-t display the link*/
				$('#frame' + i + ' a').css('display', 'none');

				}
			}
			$('#infoframe').css('visibility','visible');
		}

	function showTheRest(){

		for (var i=1; i&lt;5; i++){
				$('#frame' + i).stop().fadeTo(&quot;fast&quot;,0.8);
				$('#frame' + i).css('filter', 'alpha(opacity=80)');
			        $('#frame' + i + ' a').css('display', 'inline');
			        $('#frame' + i + ' a').css('display', 'block');
			}

			$('#infoframe').css('visibility','hidden');

		}
</pre>
<p>These are some extracts of the most important jQuery code used to power WanderWall. If you would like to take a deeper look into the code, I recommend checking out the source which can be downloaded at the beginning or end of this post. Let&#8217;s now take a look at some of the important CSS3.</p>
<p><strong>CSS3 for the background gradient and 3D &#8216;mantle&#8217; bar</strong></p>
<p style="text-align: center;"><strong><img width="492" height="161" class="aligncenter size-full wp-image-1086" title="css3" alt="" src="http://addyosmani.com/blog/wp-content/uploads/2010/08/css31.jpg" /></strong></p>
<pre name="code" class="css">
body{

background:
-webkit-gradient(
    linear,
    left bottom,
    left top,
    color-stop(0.09, rgb(153,153,153)),
    color-stop(0.55, rgb(242,242,242)),
    color-stop(0.78, rgb(240,237,240))
);
background:
-moz-linear-gradient(
    center bottom,
    rgb(153,153,153) 9%,
    rgb(242,242,242) 55%,
    rgb(240,237,240) 78%
);

}

#mantle { width:100%;  height:30px; background:
-webkit-gradient(
    linear,
    left bottom,
    left top,
    color-stop(0.09, rgb(153,153,153)),
    color-stop(0.55, rgb(242,242,242)),
    color-stop(0.78, rgb(252,252,252))
);

background:
-moz-linear-gradient(
    center bottom,
    rgb(153,153,153) 9%,
    rgb(242,242,242) 55%,
    rgb(252,252,252) 78%
);

-webkit-background-origin: padding;
-webkit-background-clip: content;
border-bottom:1px solid #fff;

		   }
</pre>
<p>&nbsp;</p>
<p><strong>CSS3 for Frame Rotation</strong></p>
<p style="text-align: center;"><strong><img width="448" height="206" border="0" alt="" class="aligncenter size-full wp-image-1087" title="rotate" src="http://addyosmani.com/blog/wp-content/uploads/rotating.jpg" /></strong></p>
<pre name="code" class="css">
.frame:hover{
 -webkit-transform: rotate(-9deg);
 -moz-transform: rotate(-9deg);
}
</pre>
<p>&nbsp;</p>
<p><strong>Cross-Browser @font-face</strong></p>
<pre name="code" class="css">
@font-face {
	font-family: 'LeagueGothicRegular';
	src: url('league_gothic-webfont.eot');
	src: local(''),
        url('league_gothic-webfont.woff') format('woff'),
        url('league_gothic-webfont.ttf') format('truetype'),
        url('league_gothic-webfont.svg#webfontwJ2IAlek') format('svg');
	font-weight: normal;
	font-style: normal;
}
</pre>
<p><strong>CSS3 @font-face consumption and text-shadow (indentation effect) Sample</strong></p>
<p style="text-align: center;"><img width="464" height="100" src="http://addyosmani.com/blog/wp-content/uploads/2010/08/wandertext.jpg" alt="" title="fontface" class="aligncenter size-full wp-image-1090" /></p>
<pre name="code" class="css">
color:#444444;
letter-spacing:-1px;
text-shadow:0 1px 0 #FFFFFF;
font-family: 'LeagueGothicRegular', sans-serif;
font-size-adjust: 0.55;
font-size:40px;
margin-top:30px;
</pre>
<p>&nbsp;</p>
<p>and that&#8217;s it!. You can very easily customize WanderWall for your own projects and remember that you&#8217;re not just limited to using 4 links/frames on the top. You can modify the code to have as many as you&#8217;d like and to look however you&#8217;d like too (in case for example you&#8217;d rather use buttons for the links instead of frames).</p>
<p style="text-align: center;">&nbsp;<img width="520" height="291" class="aligncenter size-full wp-image-1088" title="alternative" alt="" src="http://addyosmani.com/blog/wp-content/uploads/2010/08/alternative.jpg" /></p>
<p>Got a question? Check the FAQ real below real quick and if it&#8217;s not answered there, feel free to leave a comment below and I&#8217;ll do my best to help. Scroll down to the end of the post to get your download pack now.</p>
<p>&nbsp;</p>
<p><strong>Frequently Asked Questions</strong></p>
<p><em>-Does WanderWall work in all browsers? </em></p>
<p>I&#8217;ve attempted to make this project as cross-browser compatible as possible. It&#8217;s been tested on Safari, Chrome and FireFox for the Mac and Windows as well as IE6. If however you notice a quirk, let me know and I&#8217;ll try my best to get it fixed for the next release. Please note that due to the resolution of the one image I do use in this project, it may take a few moments to appear depending on your connection speed. That said, it loads in under a second on mine so you might not notice and delay.</p>
<p><em>-How do you create the background-image used in the header-wallpaper? </em></p>
<p>With the increase in both screen sizes and screen resolution we&#8217;ve noticed over the past few years, the background to the header needs to be able to cater for screens of any size (within reason). To start, you first need to create an image that&#8217;s approximately 3000&#215;1445 or over. I recommend taking a look at the theme examples in my images folder (test_3, test_5 etc) as this will give you an idea of where each &#8216;wallpaper&#8217; needs to end. If you prefer to keep your file-sizes down, you can always either opt to disable the animated background or use a simple-palette GIF file instead.</p>
<p>&nbsp;</p>
<p><strong>Demos and Sources</strong></p>
<p>I&#8217;ve created three demos that you can checkout below. Each has the same base content, but offers an alternative header-theme so you can see&nbsp; a few different ways that you can use the background-animation. The download pack contains all of these.</p>
<p>&nbsp;</p>
<div style="width: 500px;"><a href="http://www.addyosmani.com/resources/wanderwall/index.html" style="width: 100px; color: white; float: left;" class="large blue awesome tipper" target="_blank">View Demo 1</a>  <a href="http://www.addyosmani.com/resources/wanderwall/index2.html" style="width: 50px; color: white; float: left;" class="large blue awesome tipper" target="_blank">2</a>  <a href="http://www.addyosmani.com/resources/wanderwall/index3.html" style="width: 50px; color: white; float: left;" class="large blue awesome tipper" target="_blank">3</a> <a href="http://www.addyosmani.com/resources/wanderwall/jquerywanderwall.rar" style="width: 80px; color: white; float: left;" class="large blue awesome tipper" target="_blank">Download</a></div>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>Did you enjoy this article?. If so please feel free to share it with your friends or colleages by clicking the retweet button. Thanks and I hope the post came in useful!.</p>

<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Faddyosmani.com%2Fblog%2Fwanderwall%2F&amp;layout=standard&amp;&amp;width=450&amp;action=like&amp;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px;height:50px;margin-top:5px;"></iframe>]]></content:encoded>
			<wfw:commentRss>http://addyosmani.com/blog/wanderwall/feed/</wfw:commentRss>
		<slash:comments>51</slash:comments>
		</item>
		<item>
		<title>CSS3 In Under 5 Minutes &#8211; A Very Useful Screencast</title>
		<link>http://addyosmani.com/blog/css3-screencast/</link>
		<comments>http://addyosmani.com/blog/css3-screencast/#comments</comments>
		<pubDate>Mon, 09 Aug 2010 20:53:54 +0000</pubDate>
		<dc:creator>Addy</dc:creator>
				<category><![CDATA[Under 10 Minutes]]></category>
		<category><![CDATA[css3]]></category>
		<category><![CDATA[css3 button]]></category>
		<category><![CDATA[css3 buttons]]></category>
		<category><![CDATA[css3 design]]></category>
		<category><![CDATA[css3 explained]]></category>
		<category><![CDATA[css3 filter]]></category>
		<category><![CDATA[css3 float]]></category>
		<category><![CDATA[css3 image]]></category>
		<category><![CDATA[css3 photoshop]]></category>
		<category><![CDATA[css3 properties]]></category>
		<category><![CDATA[css3 rotate]]></category>
		<category><![CDATA[css3 screencast]]></category>
		<category><![CDATA[css3 skew]]></category>
		<category><![CDATA[css3 transform]]></category>
		<category><![CDATA[css3 transforms]]></category>
		<category><![CDATA[css3 tricks]]></category>
		<category><![CDATA[css3 tutorials]]></category>
		<category><![CDATA[differences css2 css3]]></category>
		<category><![CDATA[mozilla]]></category>
		<category><![CDATA[safari css3]]></category>
		<category><![CDATA[webkit border]]></category>

		<guid isPermaLink="false">http://addyosmani.com/blog/?p=1006</guid>
		<description><![CDATA[Hey guys. This week I thought it would be interesting to go through some of the core features being introduced in CSS3 that would be of interest to web designers in under 5 minutes. What better way to learn these than through a live example?.In today&#8217;s screencast I teach you how to take a plain [...]]]></description>
			<content:encoded><![CDATA[
<p><a href="http://addyosmani.com/css3"><img width="530" height="342" border="0" title="CSS3 In Under 5 Minutes" alt="" src="http://addyosmani.com/blog/wp-content/uploads/2010/08/css3u2.jpg" /></a></p>
<p>Hey guys. This week I thought it would be interesting to go through some of the core features being introduced in <strong>CSS3</strong> that would be of interest to web designers in under 5 minutes. </p>
<p>What better way to learn these than through a live example?.In today&#8217;s <a href="http://www.addyosmani.com/css3">screencast</a> I teach you how to take a plain CSS2 button and turn it into a crisp CSS3 button that&#8217;s just as good as it&#8217;s professionally designed Photoshop counterpart. There are no images used at all &#8211; just regular CSS3. To watch, just click <a href="http://www.addyosmani.com/css3">here</a> or the image above to go to the dedicated micro-site for this screencast.</p>
<p><span id="more-1006"></span></p>
<p>For those interested in exploring the topic further, I&#8217;ve also recorded a second <a href="http://www.addyosmani.com/css3">bonus</a> screencast that teaches you about CSS3 transforms. In this one, I cover features like rotation, skewing, scaling and more. Both screencasts are on the same page and you&#8217;re able to stream or download them to your iPad or iPhone too. I hope they come in useful!.</p>
<p>&nbsp;</p>

<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Faddyosmani.com%2Fblog%2Fcss3-screencast%2F&amp;layout=standard&amp;&amp;width=450&amp;action=like&amp;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px;height:50px;margin-top:5px;"></iframe>]]></content:encoded>
			<wfw:commentRss>http://addyosmani.com/blog/css3-screencast/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>RocketBar &#8211; A jQuery And CSS3 Persistent Navigation Menu</title>
		<link>http://addyosmani.com/blog/rocketbar/</link>
		<comments>http://addyosmani.com/blog/rocketbar/#comments</comments>
		<pubDate>Sun, 01 Aug 2010 04:22:52 +0000</pubDate>
		<dc:creator>Addy</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[bar]]></category>
		<category><![CDATA[css3]]></category>
		<category><![CDATA[css3 buttons]]></category>
		<category><![CDATA[css3 examples]]></category>
		<category><![CDATA[fixed-position]]></category>
		<category><![CDATA[javascript navigation]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[jquery fixed navigation]]></category>
		<category><![CDATA[jquery menu]]></category>
		<category><![CDATA[jquery navigation]]></category>
		<category><![CDATA[jquery still navigation]]></category>
		<category><![CDATA[menu]]></category>
		<category><![CDATA[navigation]]></category>
		<category><![CDATA[persistant]]></category>
		<category><![CDATA[persistent]]></category>
		<category><![CDATA[rocket]]></category>
		<category><![CDATA[rocketbar]]></category>

		<guid isPermaLink="false">http://addyosmani.com/blog/?p=957</guid>
		<description><![CDATA[Hey guys. In today&#8217;s post I&#8217;d like to present a new jQuery &#38; CSS3 demo I wrote called RocketBar. Let&#8217;s explore why I created it. Everyday on the web there&#8217;s something that we all do, almost regardless of the site that we&#8217;re on &#8211; we scroll down. If we&#8217;re reading a blog post, looking through [...]]]></description>
			<content:encoded><![CDATA[
<p><a href="http://www.addyosmani.com/blog/rocketbar"><img width="530" height="342" border="0" src="http://addyosmani.com/blog/wp-content/uploads/rocketship.jpg" alt="" /></a></p>
<p>Hey guys. In today&#8217;s post I&#8217;d like to present a new jQuery &amp; CSS3 demo I wrote called <strong><a href="http://www.addyosmani.com/resources/rocketbar">RocketBar</a>.</strong> Let&#8217;s explore why I created it. Everyday on the web there&#8217;s something that we all do, almost regardless of the site that we&#8217;re on &#8211; we scroll down. If we&#8217;re reading a blog post, looking through a product description or even just scouring through eBay listings..in every case we need to scroll back up to the top of the page if we want to use the site navigation again or perform a site search. RocketBar is a simple solution for this which shows you how you can easily provide your users a persistent form of site navigation without them needing to scroll back up.</p>
<p><span id="more-957"></span></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<div style="width: 500px;"><a href="http://www.addyosmani.com/resources/rocketbar/version2" style="width: 100px; color: white; float: left;" class="large blue awesome tipper" target="_blank">View Demo 1</a>  <a href="http://www.addyosmani.com/resources/rocketbar" style="width: 100px; color: white; float: left;" class="large blue awesome tipper" target="_blank">View Demo 2</a>  <a href="http://www.addyosmani.com/resources/rocketbar/rocketbar.zip" style="width: 80px; color: white; float: left;" class="large blue awesome tipper" target="_blank">Download</a></div>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><a href="http://www.addyosmani.com/resources/rocketbar/version2/" rel="thickbox"><img width="520" height="289" border="0" alt="" src="http://addyosmani.com/blog/wp-content/uploads/screenhalf.jpg" /></a></p>
<p>&nbsp;</p>
<p><strong>How Does It Work?</strong></p>
<p>The way it works is that when a user lands on your page they get to see the default navigation as usual. If they decide to start scrolling however, the top navigation detaches itself from the page and follows you as you scroll down. If you decide to go back to the top of the page (for whatever reason) the navigation goes back to the way it appeared before. This technique isn&#8217;t just limited to showing you the default menu in a way that detaches itself from the page, but the code could very easily be modified to show a completely different menu for those that scroll down (eg. just the more popular items in your site navigation and perhaps some share buttons). See Demo 1 for this version and Demo 2 for the standard version.</p>
<p>&nbsp;</p>
<p><img width="506" height="58" alt="" src="http://addyosmani.com/blog/wp-content/uploads/baroff.jpg" /></p>
<p><img width="503" height="71" alt="" src="http://addyosmani.com/blog/wp-content/uploads/baron.jpg" /></p>
<p>&nbsp; <img width="486" height="57" src="http://addyosmani.com/blog/wp-content/uploads/rocketbarxx.jpg" alt="" /></p>
<p>&nbsp;</p>
<p><strong>Why It is Useful?</strong></p>
<p>Why is navigation that follows your user useful? Well for starters, it saves time!. If I&#8217;m in the middle of reading about the latest gadget on a blog and decide to move to another section, it would take me less time to get there using <a href="http://www.addyosmani.com/resources/rocketbar">RocketBar</a> than it would scrolling to the top of the page and then looking for the relevant link on a conventional menu. Persistent navigation also gives your readers, customers or users an easier path to exploring your site &#8211; take for example a RocketBar with a simple search box on it. I hypothesize that the less time it takes for your user to get to the search bar, the more inclined they are to use it to see what else is available on your site (if they&#8217;re interested in the content).</p>
<p>If you&#8217;ve been designing for a few years, you&#8217;ll know that in concept this idea isn&#8217;t all that new &#8211; it could be just as easily executed using frames or just some fixed position CSS. The <strong>difference</strong> between those approaches and RocketBar however is that&nbsp; your site design and navigation doesn&#8217;t have to suffer from being completed fixed in nature to implement this idea. With RocketBar, You can still use that multi-level drop down menu, or finely crafted jQuery navigation you&#8217;ve come up with this effect with <strong>without</strong> having to worry about it being cut-off or dealing with issues like z-indexing if frames were used to implement the idea.</p>
<p>&nbsp;</p>
<p><strong>How Do I Create A RocketBar?</strong></p>
<p>The bar consists of two main components &#8211; the first is the jQuery code that powers it, adding the floating class and attributes to the bar that make it appear &#8216;detached&#8217; when the user scrolls up and down the page. The second element (which is completely optional) are the CSS3 buttons you find along the bar. We&#8217;re first going to take a look at the jQuery for the bar and then talk about the CSS3.</p>
<p>To begin, let&#8217;s define the HTML for our persistent navigation. This is simply a div container with a standard list which hosts a number of button elements used for our menu items. There are two styles available in the style.css file included with this project &#8211; the &#8216;default&#8217; class (blue theme) is used for elements which have pages of their own (eg. Links, Blog, Store) and the standard CSS applied to buttons (brown theme) is used for the menu item of the page you are currently on.</p>
<p>HTML</p>
<pre name="code" class="html">
<div id="floatingbar">
<ul>
<li><img border="0" alt="" src="images/rocketbar.png" /></li>
<li><a href="http://www.addyosmani.com"><button>Home</button></a></li>
<li><a href=""><button class="default">About</button></a></li>
<li><a href=""><button class="default">Services</button></a></li>
<li><a href=""><button class="default">Pricing</button></a></li>
<li><a href=""><button class="default">Blog</button></a></li>
<li><a href=""><button class="default">Contact</button></a></li>
<li><a href="javascript:#"><button title="Scroll" id="dirbutton" class="default">  		      <img border="0" alt="" src="images/bottomarrow.png" /> 		   </button></a></li>
</ul>
</div>
</pre>
<p><strong>JavaScript &#8211; Making use of $(window).scroll() </strong></p>
<p>Using the useful $(window).scroll() function it&#8217;s possible to perform actions on the page when a user scrolls up or down it. To utilize this, RocketBar defines two points of interest in the current window &#8211; the first is the top of the page relative to the position of the bar (see $top1) and the second is the middle of the current window ($mid1). When a user scrolls past $top1, we add the class <em>floater</em> to it which causes it to appear detached. This makes use of classic CSS fixed positioning to maintain the bar in position.</p>
<p>If however the bar is not past the top of the page (ie. when a user is either at the top of the page or scrolls back up) the class is removed and the menu goes back to its default state. Similarly, if you pass the middle of the page ($mid1) the scroll-down button turns into a scroll-up button and the graphics change. This is all fairly simple.</p>
<pre name="code" class="javascript">
var $top1= $('#floatingbar').offset().top + 20; //add additional necessary offset for Webkit
var $mid1 =  Math.floor($(window).height() / 2);

$(window).scroll(function()
{   

		if ($(window).scrollTop()&gt;$top1)
		{
		 $('#floatingbar').addClass('floater');
		}
		else
		{
		 $('#floatingbar').removeClass('floater');

		 }

		 if($(window).scrollTop() &gt; $mid1)
		  {
		     $('#dirbutton').
                                   find('img').
                                   attr('src','images/toparrow.png');
			 $('#dirbutton').data('mode','scrolldown');
		     $('#dirbutton').show();
		  }else
		  {
			 $('#dirbutton').
                                        find('img').
                                        attr('src','images/bottomarrow.png');
			 $('#dirbutton').data('mode','scrollup');

		  }
});
</pre>
<p><strong>JavaScript Animated Scroll Up/Down code</strong></p>
<p>As you can see above, one of the features of the RocketBar is a button that allows you to  scroll to the top or bottom of the page with a single click, regardless  of where you are. As this requires the use of an image that changes midway we make use of a simple jQuery image pre-load function to load up the images before a user starts using the main code routines. Here&#8217;s the code for both of these functions:</p>
<pre class="javascript" name="code">
$.preloadImages = function()
{
       for(var i = 0; i&quot;).attr(&quot;src&quot;, arguments[i]);
       }
}

$.preloadImages(&quot;images/toparrow.png&quot;,&quot;images/bottomarrow.png&quot;);

$('#dirbutton').click(function()
{
   $mode = $(this).data('mode');

   switch($mode)
   {
     case 'scrolldown':
	     $('html, body').animate({scrollTop:0}, 'slow');
		 return false;
		 break;
	 case 'scrollup':
	    $scrollpos = $('body').outerHeight();
	    $('html, body').animate({scrollTop:$scrollpos}, 'slow');
		return false;
		break;
   }

});
</pre>
<p><strong>CSS3 Buttons (For full code see style.css in the release)</strong></p>
<p>The CSS3 buttons used in RocketBar are based on a variation of the Aristo theme, inspired by previous work from Ryan Miglavs. I wanted to use these buttons as an example of just how far aesthetically clean and crisp&nbsp; form elements can be these days using CSS3 without needing to use any graphics at all. For anyone wanting to design their own Aristo/MetaLabs style buttons from scratch, here&#8217;s a break-down of the various CSS features required for them. You start off with a solid-color button with rounded edges and a simple border (remember to use border-radius cases for both Webkit and FireFox).</p>
<p><img width="450" height="280" border="0" alt="" src="http://addyosmani.com/blog/wp-content/uploads/diagram1.jpg" /></p>
<p>Next work on the typography to your button &#8211; I often personally opt for use of letter-spacing and bold common fonts such as Arial and Georgia as these are pretty much present on any platform these days (Helvetica is preferred if you&#8217;re just using flat graphics). After this we focus on the letter-press effect &#8211; this is made possible using an intelligently positioned text-shadow element placed behind the primary button text.</p>
<p>Once this is done work on the background gradients for your button (-webkit-gradient and -moz-linear-gradient will allow you to blend from one specified color to another). Finally, there&#8217;s the inner-shadow feature at the top of the button. This white line is what adds that extra &#8216;crisp&#8217; feel to these buttons and can be achieved using the inset option of the CSS box-shadow property.</p>
<p>There&#8217;s a lot more that goes into the hover and pressed-state cases but if you check out the style.css file in the release pack they should all be in there.</p>
<p>&nbsp;</p>
<pre name="code" class="css">
button {
	position: relative;
	margin: 0 .5em .5em .5em;
	padding: 0.5em 1.5em;
	font-size: 14px;
	font-weight: bold;
	font-family:Arial;
	color: #4f4f4f;
	text-shadow: 0 1px 1px #fff;
	background: #ddd;
	background: -webkit-gradient(linear, left top, left bottom, from(#ededed), to(#c4c4c4));
	background: -moz-linear-gradient(top, #ededed, #c4c4c4);
	border: 1px solid #acacac;
	border-top-color: #bdbdbd;
	letter-spacing:-1px;
	border-bottom-color: #949494;
	border-radius: .214em;
	-webkit-border-radius: .214em;
	-moz-border-radius: .214em;
	transition: all .2s ease-in-out;
	-webkit-transition: all .2s ease-in-out;
	-moz-transition: all .2s ease-in-out;
	-o-transition: all .2s ease-in-out;

	box-shadow: inset 0 1px 0 #fff;
    	-webkit-box-shadow: inset 0 1px 0 #fff;
    	-moz-box-shadow: inset 0 1px 0 #fff;
    	-o-box-shadow: inset 0 1px 0 #fff;

	cursor: pointer;
	}
	button:hover,
	button:focus {

		box-shadow: 0 0 7px rgba(0,0,0,0.4), inset 0 1px 0 #fff;
    		-webkit-box-shadow: 0 0 7px rgba(0,0,0,0.4), inset 0 1px 0 #fff;
    		-moz-box-shadow: 0 0 7px rgba(0,0,0,0.4), inset 0 1px 0 #fff;
    		-o-box-shadow: 0 0 7px rgba(0,0,0,0.4), inset 0 1px 0 #fff;
		}
	button:active {
		background: #ccc;
		background: -webkit-gradient(linear, left top, left bottom, from(#c3c3c3), to(#ebebeb));
		background: -moz-linear-gradient(top, #c3c3c3, #ebebeb);
		border-color: #a6a6a6;
		border-top-color: #939393;
		border-bottom-color: #bcbcbc;

		box-shadow: inset 0 -1px 0 #fff;
    		-webkit-box-shadow: inset 0 -1px 0 #fff;
    		-moz-box-shadow: inset 0 -1px 0 #fff;
    		-o-box-shadow: inset 0 -1px 0 #fff;
		}
</pre>
<p>and that&#8217;s it!. If you would like to check out a demo of RocketBar or download the sources, you can pick these up below.</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<div style="width: 500px;"><a href="http://www.addyosmani.com/resources/rocketbar/version2" style="width: 100px; color: white; float: left;" class="large blue awesome tipper" target="_blank">View Demo 1</a>  <a href="http://www.addyosmani.com/resources/rocketbar" style="width: 100px; color: white; float: left;" class="large blue awesome tipper" target="_blank">View Demo 2</a>  <a href="http://www.addyosmani.com/resources/rocketbar/rocketbar.zip" style="width: 80px; color: white; float: left;" class="large blue awesome tipper" target="_blank">Download</a></div>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>If you liked RocketBar please feel free to share it with your friends and colleagues by clicking <a class="retweet" href="http://addyosmani.com/blog/rocketbar/">RocketBar &#8211; A jQuery And CSS3 Persistant Navigation Menu</a></p>
<p>Remember, <strong>RocketBar</strong> is a proof of concept which does use CSS3. At the moment support for FireFox 3.6, Safari 4.0, Chrome and WebKit nightlies are guaranteed.&nbsp; While I&#8217;ve done my best to ensure that the navigation gracefully degrades in Internet Explorer, a live production version of the code would probably need integration of something like <a href="http://tagsoup.com/cookbook/css/fixed/">this</a> to make it work fully in IE.</p>

<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Faddyosmani.com%2Fblog%2Frocketbar%2F&amp;layout=standard&amp;&amp;width=450&amp;action=like&amp;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px;height:50px;margin-top:5px;"></iframe>]]></content:encoded>
			<wfw:commentRss>http://addyosmani.com/blog/rocketbar/feed/</wfw:commentRss>
		<slash:comments>41</slash:comments>
		</item>
		<item>
		<title>How To Create A jQuery Plugin In Under 5 Minutes &#8211; A Helpful Screencast</title>
		<link>http://addyosmani.com/blog/jquery-plugin-in-under-5-minutes/</link>
		<comments>http://addyosmani.com/blog/jquery-plugin-in-under-5-minutes/#comments</comments>
		<pubDate>Sat, 24 Jul 2010 00:52:24 +0000</pubDate>
		<dc:creator>Addy</dc:creator>
				<category><![CDATA[Under 10 Minutes]]></category>
		<category><![CDATA[author]]></category>
		<category><![CDATA[create]]></category>
		<category><![CDATA[how to create a jquery plugin]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[jquery plugin tutorial]]></category>
		<category><![CDATA[jquery plugins]]></category>
		<category><![CDATA[plugins]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[write a jquery plugin]]></category>

		<guid isPermaLink="false">http://addyosmani.com/blog/?p=948</guid>
		<description><![CDATA[Hey guys. As a follow up to HTML5 in Under 5 Minutes, in this week&#8217;s screencast I&#8217;m going to show you how to create a useful piece of jQuery code for making your own graphical tooltips and the I&#8217;m going to show you how to turn it into a fully customizable jQuery plugin. Click on [...]]]></description>
			<content:encoded><![CDATA[
<p><a href="http://addyosmani.com/jquerypluginin5mins/"><img width="530" height="342" border="0" src="http://addyosmani.com/blog/wp-content/uploads/howkoj.jpg" alt="" /></a></p>
<p>Hey guys. As a follow up to <a href="http://www.addyosmani.com/html5/">HTML5 in Under 5 Minutes</a>, in this week&#8217;s <a href="http://addyosmani.com/jquerypluginin5mins/">screencast</a> I&#8217;m going to show you how to create a useful piece of jQuery code for making your own graphical tooltips and the I&#8217;m going to show you how to turn it into a fully customizable jQuery plugin. Click on the <a href="http://addyosmani.com/jquerypluginin5mins/">preview</a> above to go to the dedicated micro-site for this screencast or <a href="http://addyosmani.com/jquerypluginin5mins/">here</a> to start watching it now. You can also download the sources from that page. I hope it helps!</p>

<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Faddyosmani.com%2Fblog%2Fjquery-plugin-in-under-5-minutes%2F&amp;layout=standard&amp;&amp;width=450&amp;action=like&amp;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px;height:50px;margin-top:5px;"></iframe>]]></content:encoded>
			<wfw:commentRss>http://addyosmani.com/blog/jquery-plugin-in-under-5-minutes/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>HTML5 In 5 Minutes &#8211; A Screencast You Just Can&#8217;t Miss!</title>
		<link>http://addyosmani.com/blog/html5-in-5-minutes/</link>
		<comments>http://addyosmani.com/blog/html5-in-5-minutes/#comments</comments>
		<pubDate>Mon, 12 Jul 2010 03:35:04 +0000</pubDate>
		<dc:creator>Addy</dc:creator>
				<category><![CDATA[Under 10 Minutes]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[audio]]></category>
		<category><![CDATA[audio tag]]></category>
		<category><![CDATA[canvas]]></category>
		<category><![CDATA[geotagging]]></category>
		<category><![CDATA[html5]]></category>
		<category><![CDATA[html5 canvas]]></category>
		<category><![CDATA[html5 demos]]></category>
		<category><![CDATA[html5 sql]]></category>
		<category><![CDATA[html5 tutorial]]></category>
		<category><![CDATA[localstorage]]></category>
		<category><![CDATA[sessionstorage]]></category>
		<category><![CDATA[video element]]></category>
		<category><![CDATA[video tag]]></category>

		<guid isPermaLink="false">http://addyosmani.com/blog/?p=938</guid>
		<description><![CDATA[Hey guys. I recorded you a screencast on HTML5 over the weekend &#8211; I hope you like it!. It covers a lot of the core features HTML5 will bring including code samples for any material covered. Just click on the HTML5 thumbnail above to be taken to the HTML5 in under 5 minutes micro-site where [...]]]></description>
			<content:encoded><![CDATA[
<p><a href="http://addyosmani.com/html5/"><img width="530" height="342" border="0" src="http://addyosmani.com/blog/wp-content/uploads/html5in5s.jpg" alt="" /></a></p>
<p>Hey guys. I recorded you a screencast on HTML5 over the weekend &#8211; I hope you like it!.  It covers a lot of the core features HTML5 will bring including code samples for any material covered. Just click  on the HTML5 thumbnail above to be taken to the HTML5 in under 5 minutes  micro-site where you can play or download the screencast. I hope it comes in useful! Thanks &#8211;  Addy.</p>

<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Faddyosmani.com%2Fblog%2Fhtml5-in-5-minutes%2F&amp;layout=standard&amp;&amp;width=450&amp;action=like&amp;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px;height:50px;margin-top:5px;"></iframe>]]></content:encoded>
			<wfw:commentRss>http://addyosmani.com/blog/html5-in-5-minutes/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Catch404 &#8211; A jQuery And CSS3 Modal Plugin For Handling Broken Links Elegantly</title>
		<link>http://addyosmani.com/blog/catch404/</link>
		<comments>http://addyosmani.com/blog/catch404/#comments</comments>
		<pubDate>Tue, 06 Jul 2010 22:17:42 +0000</pubDate>
		<dc:creator>Addy</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[404]]></category>
		<category><![CDATA[ajax 404]]></category>
		<category><![CDATA[ajax error]]></category>
		<category><![CDATA[ajax error handling]]></category>
		<category><![CDATA[ajax jquery]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[catch 404]]></category>
		<category><![CDATA[catch404]]></category>
		<category><![CDATA[errors]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[jquery 404]]></category>
		<category><![CDATA[jquery 404 handling]]></category>
		<category><![CDATA[jquery error handling]]></category>
		<category><![CDATA[jquery errors]]></category>
		<category><![CDATA[yahoo]]></category>
		<category><![CDATA[yql]]></category>

		<guid isPermaLink="false">http://addyosmani.com/blog/?p=887</guid>
		<description><![CDATA[&#160; Hey guys. I&#8217;ve got a brand new jQuery plugin for you today. Let&#8217;s talk about the problem we&#8217;re going to be solving with it first: Broken links and 404 Errors are a problem that have plagued almost all websites since the dawn of the internet &#8211; they&#8217;re just a really bad user experience and [...]]]></description>
			<content:encoded><![CDATA[
<p><a href="http://addyosmani.com/blog/catch404/"><img height="342" border="0" width="530" alt="" src="http://addyosmani.com/blog/wp-content/uploads/catch.jpg" /></a></p>
<p>&nbsp;</p>
<p>Hey guys. I&#8217;ve got a brand new jQuery plugin for you today. Let&#8217;s talk about the problem we&#8217;re going to be solving with it first: Broken links and 404 Errors are a problem that have plagued almost all websites since the dawn of the internet &#8211; they&#8217;re just a really bad user experience and we&#8217;ve all encountered them.</p>
<p>There&#8217;s nothing attractive about clicking a link hoping that it&#8217;ll take you to your destination only to find out that the page doesn&#8217;t exist. In most cases you&#8217;re left having to figure out what to do next &#8211; do you hit the back button? do you go googling the file to see if you can find it?. In some cases they can be a total show-stopper, so what can we do to change that?.</p>
<p>Today I&#8217;d like to present a new jQuery Plugin I wrote called Catch404. Through the magic of jQuery we&#8217;re going to catch 404 errors without your users even having to leave the page and then suggest some other options they&#8217;ve got using an inline jQuery Modal window. So, why it this useful and how does it work?.</p>
<p><span id="more-887"></span></p>
<p>&nbsp;</p>
<p><a href="http://www.addyosmani.com/resources/catch404/catch404.html" style="width: 180px; color: white;" class="large blue awesome tipper" target="_blank"> View Demo</a> &nbsp;<a href="http://www.addyosmani.com/resources/catch404/catch404.release.1.01.zip" style="width: 180px; color: white;" class="large blue awesome tipper" target="_blank">Download Source</a></p>
<p>&nbsp;</p>
<p><img height="322" width="528" alt="" src="http://addyosmani.com/blog/wp-content/uploads/diagram.jpg" /></p>
<p>&nbsp;</p>
<h2>Why Is Catch404 Useful?</h2>
<p>Let&#8217;s pretend that <b>this</b> is a broken link. Can you imagine that when your users click this link, instead of them being redirected to a 404 error on your site, a friendly modal message pops up on your current page saying that it&#8217;s not available?. In that same message box you can then give them a sense of direction so that they&#8217;re not lost &#8211; you could ask them to click on a contact link to report the link&#8217;s broken, offer an alternative mirror, recommend they do a site search for the file or just say that you&#8217;re experiencing hosting issues and the file will be back up soon. The choice is completely up to you. The benefit of Catch404 is that you can offer your users a better experience when errors are encountered on your site.</p>
<p>&nbsp;</p>
<p><img height="342" width="530" alt="" src="http://addyosmani.com/blog/wp-content/uploads/catch1.jpg" /></p>
<p>&nbsp;</p>
<h2>How Does Catch404 Work?</h2>
<p>The basic idea behind Catch404 is that you perform an Ajax query for a URL and handle the response provided accordingly, so if its a 404 error, we handle this error specifically. Now because cross-domain 404 handling with jQuery is something that has often been problematic to correctly implement, achieving this isn&#8217;t as straight-forward as it should be. Instead, the plugin uses a neat trick using the Yahoo YQL Engine to access the URL for us which returns a HTML string (local URLs don&#8217;t require this hack) &#8211; thanks to James Padolsey and Christian Heillman for their work in this area. Depending on the contents of this string response, we&#8217;re then able to handle the error from the same page the user tried clicking out from. In my plugin, a modal window is used to render the error message and it&#8217;s here that you&#8217;re able to define whatever message, links or tips that you would like to offer your users regarding the 404. This offers a much better user experience than traditional 404 handling because rather than taking them somewhere with no content, you&#8217;ve now got the option to either present them with an alternative mirror or advice through the modal window.</p>
<p>&nbsp;</p>
<p><img height="320" width="530" alt="" src="http://addyosmani.com/blog/wp-content/uploads/catch3.jpg" /></p>
<h2>Let&#8217;s take a look at the jQuery under the bonnet!</h2>
<p>As you can see in the code snippet below, the most advanced piece of code in this plugin is the part that performs the above 404 handling. Because we&#8217;re connecting up to a third party site (Yahoo) in order to access this URL, there is going to be a wait of about a second or two during our query and this is the case for URLs that are valid as well as those that aren&#8217;t. To ensure your users are aware of whats going on it can be useful to display a progress overlay on your page with the label &#8216;Checking URL status..&#8217; or something similar.</p>
<div class="gmail_quote">&nbsp;</div>
<pre class="javascript" type="javascript" name="code">
//Perform the Ajax JSON call to get the Yahoo YQL response for the URL
   function performAjaxCall(url,msg,container)
  {
    if(url.match('^http')){
      msg.html(' (checking...)');

      //connect to yahoo YQL to get a response for the URL
      $.getJSON(&quot;http://query.yahooapis.com/v1/public/yql?&quot;+
                &quot;q=select%20*%20from%20html%20where%20url%3D%22&quot;+
                encodeURIComponent(url)+
                &quot;%22&amp;format=xml'&amp;callback=?&quot;,
        function(data){
          if(data.results[0]){
            var data = filterData(data.results[0]);

             //if the url passes the test, navigate to it
			donav(url);
          } else {
            msg.html(' (404!)');
            //otherwise display the modal error window
	    fourPop();
          }
        }
      );
    }
</pre>
<div class="gmail_quote"><span style="font-family: 'Times New Roman'; font-size: medium;"></p>
<pre style="word-wrap: break-word; white-space: pre-wrap;">
   </pre>
<p></span></div>
<div class="gmail_quote">and now we define our modal window function as follows:</div>
<pre type="javascript" class="javascript" name="code">
function fourPop(){

		var popWidth = 500; //dim[0].split('=')[1];
		var popID = '404message';

		$('#' + popID).fadeIn().css({ 'width': Number( popWidth ) }).prepend('<a class="close" href="#"><img alt="Close" title="Close Window" class="btn_close" src="images/close_pop.png" /></a>');

		var popMargTop = ($('#' + popID).height() + 80) / 2;
		var popMargLeft = ($('#' + popID).width() + 80) / 2;

		//Apply Margin to Popup
		$('#' + popID).css({
			'margin-top' : -popMargTop,
			'margin-left' : -popMargLeft
		});

		//Fade in Background
		$('body').append('
<div id="fade">&nbsp;</div>

'); .
		$('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn();  

		return false;
	};

	//Close Popups and Fade Layer
	$('a.close, #fade').live('click', function() {
	  	$('#fade , .popup_block').fadeOut(function() {
			$('#fade, a.close').remove();
	}); 

		return false;
	});

    });
  }
</pre>
<div class="gmail_quote">&nbsp;</div>
<h2>How Do I Use Catch404 On My Site Or Page?</h2>
<p><img height="375" width="500" alt="" src="http://addyosmani.com/blog/wp-content/uploads/failwhale.jpg" /></p>
<p>Using Catch404 will help you keep those broken links and fail whales at bay, but the best news is it&#8217;s relatively easy to start using straight away. All you need to do is first include jQuery and catch404.js in your page and then call the catch404() function on a selector as follows &#8211;  it should apply it to the links with that particular class or id and you&#8217;re all set. In the following case I&#8217;m using the class &#8216;ajaxcheck&#8217; to indicate links on the page that I would like checked using Catch404.</p>
<div class="gmail_quote"><b><span style="font-weight: normal;">HTML</span></b></div>
<pre name="code" type="html" class="javascript"><a class="ajaxcheck" href="somepage.html"> 

This is a link to check

</a>
</pre>
<div class="gmail_quote"><b><span style="font-weight: normal;"><br />
</span></b></div>
<div class="gmail_quote"><b><span style="font-weight: normal;">JavaScript</p>
<pre name="code" type="javascript" class="javascript">
$(document).ready(function()
{

$(&quot;.ajaxcheck&quot;).catch404();

});
</pre>
<p></span></b></div>
<h2>Demo and Download</h2>
<p>To see a fully featured demo of Catch404 in action, just click the demo button below. You can also download the plugin and source files via the Download button if you&#8217;d like to start using it in your projects.</p>
<p>&nbsp;</p>
<p><a href="http://www.addyosmani.com/resources/catch404/catch404.html" style="width: 180px; color: white;" class="large blue awesome tipper" target="_blank"> View Demo</a> &nbsp;<a href="http://www.addyosmani.com/resources/catch404/catch404.release.1.01.zip" style="width: 180px; color: white;" class="large blue awesome tipper" target="_blank">Download Source</a></p>
<p>&nbsp;</p>
<p>Thanks for reading and I hope Catch404 helps you to keep those broken links, 404&#8242;s and fail whales at bay. To share this article with your friends click <a href="http://addyosmani.com/blog/catch404/" class="retweet">Catch404 &#8211; A jQuery And CSS3 Modal Plugin For Handling Broken Links Elegantly</a> now. Good luck with your projects!</p>
<p>- Addy.</p>

<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Faddyosmani.com%2Fblog%2Fcatch404%2F&amp;layout=standard&amp;&amp;width=450&amp;action=like&amp;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px;height:50px;margin-top:5px;"></iframe>]]></content:encoded>
			<wfw:commentRss>http://addyosmani.com/blog/catch404/feed/</wfw:commentRss>
		<slash:comments>51</slash:comments>
		</item>
		<item>
		<title>Web Design For Every Culture (with jQuery And the Google Translate API)</title>
		<link>http://addyosmani.com/blog/web-design-for-every-culture/</link>
		<comments>http://addyosmani.com/blog/web-design-for-every-culture/#comments</comments>
		<pubDate>Sun, 20 Jun 2010 15:30:08 +0000</pubDate>
		<dc:creator>Addy</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[cultural web design]]></category>
		<category><![CDATA[culture]]></category>
		<category><![CDATA[designing]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[google translate]]></category>
		<category><![CDATA[google translate api]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[jquery localization]]></category>
		<category><![CDATA[local]]></category>
		<category><![CDATA[local design]]></category>
		<category><![CDATA[localization]]></category>
		<category><![CDATA[translate]]></category>
		<category><![CDATA[translation]]></category>
		<category><![CDATA[web design]]></category>
		<category><![CDATA[web design culture]]></category>

		<guid isPermaLink="false">http://addyosmani.com/blog/?p=850</guid>
		<description><![CDATA[Hey guys. Today I&#8217;d like us to look at a topic that can sometimes be overlooked in web design projects &#8211; the power of designing based on culture. Lets start off with a simple question &#8211; do you know how many of your visitors come from countries where English isn&#8217;t their first language?. I didn&#8217;t [...]]]></description>
			<content:encoded><![CDATA[
<p><a href="http://addyosmani.com/blog/web-design-for-every-culture"><img height="342" border="0" width="530" src="http://addyosmani.com/blog/wp-content/uploads/culture(1).jpg" alt="" /></a></p>
<p>Hey guys. Today I&#8217;d like us to look at a topic that can sometimes be overlooked in web design projects &#8211; the power of designing based on culture. Lets start off with a simple question &#8211; do you know how many of your visitors come from countries where English isn&#8217;t their first language?.</p>
<p>I didn&#8217;t until quite recently and the statistics really surprised me. Over half..that&#8217;s right..over<strong> </strong>half of the visitors to my site come from countries with a different first language (and a different culture). Knowing this opens up a number of new opportunities for site owners that find themselves a similar boat.</p>
<p><span id="more-850"></span></p>
<p>For starters, you can improve the experience these visitors get on your site by simply introducing translated versions of your articles or even a design that compliments their culture. Not only this but you can also open your site up to a much much broader audience, simply by making your posts easily available in multiple languages and making your content location friendly.</p>
<p>In this article, we&#8217;re first going to discuss the concept of localization in more detail with the help of Christian Arno (an expert in this field from translation company Lingo24) and I&#8217;m then going to show you how you can start offering ajax translation of your posts or pages using jQuery and the Google Translation API.</p>
<p>&nbsp;&nbsp; &nbsp;</p>
<p><strong>Web design for every culture </strong></p>
<p>&nbsp;</p>
<p>There are 1.8bn people now online around the world (according to <a href="http://www.internetworldstats.com/">Internet World Stats</a>), of which only 495.8m are English speakers. That means that as soon as your site is online, it&rsquo;s accessible by all of those people, but less than a third of your potential audience will be able to read your site if you stick to English as your only language.</p>
<p>This is especially important if you&rsquo;re an online business, since a study by the <a href="http://www.commonsenseadvisory.com/Research/Report_Abstracts/060926_R_global_consumer/tabid/1258/Default.aspx">Common Sense Advisory</a> found that 85% of online shoppers, even those who speak multiple languages, will only buy from a site where they can read about the product in their own native language.</p>
<p>If you want to effectively sell to all those online shoppers who aren&rsquo;t native English speakers, then the key is to localise. You need to identify exactly which countries will have a gap in the market for your product or service, and then create individual domains for each country, with local URLs, and preferably hosted on servers in the target country (to assist with your local search engine page rankings).</p>
<p>When it comes to building localised sites, there are a few things to keep in mind. You can&rsquo;t just create the one template for every URL and simply switch the language, as different cultures have different requirements and preferences when it comes to website design. Your aim should be to create a template which will stay consistent in its branding, but also be flexible enough to change slightly between local versions. Here are a few of the points you should keep in mind.</p>
<p>&nbsp;</p>
<p><strong>Multicultural design</strong></p>
<p>&nbsp;</p>
<p>There are fundamental differences in design between sites designed for <a href="http://en.wikipedia.org/wiki/High_context_culture">&lsquo;High Context&rsquo;</a> and <a href="http://en.wikipedia.org/wiki/Low_context_culture">&lsquo;Low Context&rsquo;</a> cultures. For instance, take a look at the differences between Youtube, which was designed with a Western, &lsquo;Low Context&rsquo; culture in mind, and the Chinese version <a href="http://www.tudou.com/">Tudou</a>. Playing a video on Youtube involves the clip simply playing on your main screen, with the option for full screen &#8211; but playing&nbsp; a video on Tudou takes you into a virtual cinema, with a background designed to look like a theatre and a host of pop-up animations.</p>
<p>This is a good illustration of the fundamental difference between &lsquo;low context&rsquo; cultures, which like minimalism and straight-up information, and &lsquo;high context&rsquo; cultures, which get a lot more of their information from the background or context of a site.</p>
<p>Essentially, you need to look at your competitors in each market to see what they&rsquo;re doing successfully with their site designs, and then one-up them, while keeping an element of consistent branding across every site &ndash; for instance, look at the differences and similarities between Coke&rsquo;s <a href="http://www.coca-cola.se/">Swedish</a> site and its <a href="http://www.coca-cola.com.cn/">Chinese</a> site.</p>
<p>&nbsp;</p>
<p><strong>Navigation and colour</strong></p>
<p>&nbsp;</p>
<p>Your main issue with navigation is going to be the switch between left-to-right and right-to-left languages. Handily, cascading style sheets (CSS) make it quite easy to switch the direction of your text, or to flip your template, by adding the right-to-left dir=&quot;rtl&quot; attribute to the necessary areas &ndash; but more on CSS later.&nbsp; If you use a horizontal navigation bar, that will prevent problems caused by having to move your navigation bar from one side to the other. Alternatively, keeping your site as symmetrical as possible will save you from having to redesign your page when switching the direction of your language.</p>
<p>You should also think carefully about the colour scheme you go for with each site. Obviously you don&rsquo;t want to be changing colours drastically between each site, but you should also be aware that colours have different meanings in different cultures, as shown by this <a href="http://www.globalization-group.com/edge/resources/color-meanings-by-culture/?utm_source=Translation+Bloopers+%26+Blunders+%7C+Translation+%26+Localization+Tips+%7C+Free+Subscription+%7C+GGI&amp;utm_campaign=c7ef00a4c2-Translation_Tips_2010-021_05_25_Colors&amp;utm_mediu">graph</a>. Going for a light coloured background with dark text is your best bet &ndash; and blue is generally considered to be the most universally acceptable colour.</p>
<p>&nbsp;</p>
<p><strong>CSS and Unicode UTF-8</strong></p>
<p>&nbsp;</p>
<p>Keeping your content separate from your design is rather handy when you have to change your text and images between multiple sites, so that&rsquo;s why CSS is your best choice for cross-cultural web designing. You&rsquo;ll also need a character encoder that can handle multiple scripts, from Latin, to Cyrillic, to Arabic and Simplified Chinese. Unicode UTF-8 does all that and more (90 scripts in total), and is supported by all the major browsers, making it your best bet as a character encoder.</p>
<p>&nbsp;</p>
<p><strong>Geolocation</strong></p>
<p>&nbsp;</p>
<p>Imagine being able to channel your visitors from any region in the world directly to a web page that&rsquo;s localised for their language and culture. Geolocation can identify a web surfer&rsquo;s location by checking the country in which their IP address is registered, and there are a number of companies &ndash; such as Hexa Software&rsquo;s <a href="http://www.ip2location.com/free.asp">IP2Location</a> and <a href="http://www.digitalenvoy.net/">Digital Envoy</a> -&nbsp; which collate IP addresses and can lease you access to integrated databases that allow you to funnel site visitors directly to their localised domain.</p>
<p>The only problem is that IP addresses aren&rsquo;t always hosted in the country where the end user resides &ndash; for instance, lots of servers are hosted in China, so while a visitor may live in Germany, their IP address will show up as being from China, and if you use geolocation you&rsquo;ll end up automatically routing them to your Chinese site.</p>
<p>In any case, if you have each localised domain hosted on a server in its target country, it will appear as the preferred option in the local Google search &ndash; for instance, if you have www.yourcompany.fr hosted on a server in France, when people search for &lsquo;your service&rsquo; on Google.fr, they&rsquo;ll get your French site, rather than www.yourcompany.com.</p>
<p>&nbsp;</p>
<p><strong>Translation and copy-writing for localised sites</strong></p>
<p>&nbsp;</p>
<p>Most importantly, you need to make sure that your content is correct and appropriate for each local site. While it may be tempting to just run your English copy through <a href="http://translate.google.com/">Google Translate</a> and post up the results, that&rsquo;s not your best option for a trustworthy, reliable looking site.</p>
<p>Machine translation is often fine to get the gist of a piece of foreign language text, but when it comes to marketing material, which requires a fine balance to be trustworthy and also sell to the customer, you&rsquo;re best off getting a professional who lives in the target country to either write your copy from scratch, or translate it and check for any potential points of offense or &lsquo;wrong notes&rsquo;. The last thing you want is to commit a translation faux pas, such as when General Motors introduced their new Chevy Nova into the Mexican market, obviously not realising that &lsquo;no va&rsquo; in Spanish means &lsquo;no go&rsquo;.</p>
<p>&nbsp;</p>
<p><strong>Translation widgets and inline translation</strong></p>
<p>&nbsp;</p>
<p>If you&rsquo;re running off a tight budget, though, and can&rsquo;t afford the expense of professional translation and copy writing, there&rsquo;s always the option of adding a translation widget to your home page, or using inline translation. There are plenty of translation engines out there, and by simply copying a bit of code into your site you&rsquo;ll get a box that lets visitors know they can automatically translate the text into any language.</p>
<p>Google Translate is probably the best known &ndash; and was the most popular in a recent <a href="http://www.globalbydesign.com/blog/2010/05/17/google-bing-and-babelfish-whats-the-best-translation-engine/">review</a> of translation engines &ndash; but it&rsquo;s not your only option. Microsoft also has a widget for <a href="http://www.microsofttranslator.com/widget/">Windows Live Translator</a>, and then there&rsquo;s widgets for <a href="http://handheld.softpedia.com/get/Internet-Utilities/Bing-Widget-79295.shtml">Bing</a>, which was voted superior for Italian and German translation, and pioneer <a href="http://www.widgetbox.com/widget/altavista-babelfish-site-translator">Babelfish</a>, which rates well for Chinese to English translation. There are plenty of others available with different specialisations, most of which are stocked at Widget Box.</p>
<p>Alternatively, for a smoother interaction experience, if you&rsquo;re up to date with inline functions you can build inline translation code into your site to offer your visitors an instantly localised browsing experience. Javascript libraries like jQuery offer a host of useful advice on how to use asynchronous JavaScript and XML (Ajax) to incorporate code into your site and create rich and engaging websites that adapt intuitively to your visitors&rsquo; language needs and offer your visitors a high definition, &lsquo;no refresh&rsquo; browsing experience.</p>
<p>&nbsp;</p>
<p><strong>Harnessing the Google Translation API with jQuery</strong></p>
<p>To add instant jQuery translations to your site, I recommend the use of the jQuery Translate plugin. This nicely interfaces with the Google Translation API giving you instant access to translation of your content across a number of different languages. Here&#8217;s a <a href="http://jsbin.com/ozenu/edit">demo</a> of it in action on JS-Bin. To get started, first download the translate plugin <a href="http://code.google.com/p/jquery-translate/">here.</a></p>
<p>Next, include the plugin after jQuery as follows:</p>
<pre class="javascript" name="code">
&lt; script type=&quot;text/javascript&quot; src=&quot;js/jquery-1.4.2.min.js&quot;&gt;
&lt; script type=&quot;text/javascript&quot; src=&quot;js/jquery.translate-1.3.9.js&quot;&gt;
</pre>
<p>If you want to use the plugin on page load in most cases you can call it inside $(document).ready() but in some cases you have to define a callback function to be executed when the Language API is loaded. It&#8217;s not $(document).ready() but $.translate.ready():</p>
<pre class="javascript" name="code">
$(document).ready(function(){
  //this will work,
  //returns a jQuery object and translates the text when the Language API is loaded
  $('body').translate('english');

  //this will work too,
  //returns an internal object and translates the text when the Language API is loaded
  $.translate( 'some text', 'de', {
    complete: function(){
                console.log( this.translation )
    }
  });

  //this won't (always) work!
  //the Language API may not be loaded, the return value cannot be determined
  $.translate.getLanguages();

  //this will work, as it will be executed when the Language API is loaded
  $.translate.ready(function(){
    $.translate.getLanguages()
  })

  //you can also use a shorter alias as in jQuery:
  $.translate(function(){
    $.translate.getLanguages()
  })

})
</pre>
<p>
As you can see above you can translate an html element (first example) or only some text (second example). This plugin is great because you could easily add in a few flag icons to the top of your articles and trigger the Google Translate API to translate your post&#8217;s content via Ajax. Remember that if you&#8217;re applying the translate function to &#8216;body&#8217;, your layout may need to be flexible enough to accomodate longer text labels. The safest way to apply it in my opinion would be to just the post-container or in the case of a standard site, the container of your main text. Use your best judgement here!</p>
<p>&nbsp;</p>
<p><strong>In conclusion</strong></p>
<p>By researching your markets and getting some assistance from in-country experts before you build and launch your localised sites, you can save yourself a lot of hassle later, and have a much better chance of finding success with your localised sites first time, no matter what culture you&rsquo;re marketing to.</p>
<p><strong><br />
About the guest author</strong></p>
<p>Christian Arno is the founder and Managing Director of <a href="http://www.lingo24.com/">global translation agency and localisation specialists</a> Lingo24. Launched in 2001, Lingo24 now has over 120 employees spanning four continents and clients in over sixty countries. In the past twelve months, they have translated over thirty million words for businesses in every industry sector and their projected turnover for 2010 is &pound;6.3m.</p>

<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Faddyosmani.com%2Fblog%2Fweb-design-for-every-culture%2F&amp;layout=standard&amp;&amp;width=450&amp;action=like&amp;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px;height:50px;margin-top:5px;"></iframe>]]></content:encoded>
			<wfw:commentRss>http://addyosmani.com/blog/web-design-for-every-culture/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>jQuery &amp; CSS Sprite Animation Explained In Under 5 Minutes</title>
		<link>http://addyosmani.com/blog/jquery-sprite-animation/</link>
		<comments>http://addyosmani.com/blog/jquery-sprite-animation/#comments</comments>
		<pubDate>Mon, 31 May 2010 01:03:19 +0000</pubDate>
		<dc:creator>Addy</dc:creator>
				<category><![CDATA[Under 10 Minutes]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[animated]]></category>
		<category><![CDATA[animation]]></category>
		<category><![CDATA[css sprite animation]]></category>
		<category><![CDATA[css sprites]]></category>
		<category><![CDATA[examples]]></category>
		<category><![CDATA[javascript sprite]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[jquery sprite animation]]></category>
		<category><![CDATA[sprite]]></category>
		<category><![CDATA[spritely]]></category>
		<category><![CDATA[sprites]]></category>

		<guid isPermaLink="false">http://addyosmani.com/blog/?p=778</guid>
		<description><![CDATA[&#160; Today we&#8217;re going to take a look at sprite animation. There&#8217;s been a lot of talk this year about the future of technologies like Adobe&#8217;s Flash and for good reason &#8211; with the performance of JavaScript frameworks having come so far since they were first conceived, it&#8217;s now possible to create equally as powerful [...]]]></description>
			<content:encoded><![CDATA[
<p><a href="http://addyosmani.com/blog/jquery-sprite-animation/"><img width="530" height="342" border="0" src="http://addyosmani.com/blog/wp-content/uploads/csssp.jpg" alt="" /></a></p>
<p>&nbsp;</p>
<p>Today we&#8217;re going to take a look at sprite animation. There&#8217;s been a lot of talk this year about the future of technologies like Adobe&#8217;s Flash and for good reason &#8211; with the performance of JavaScript frameworks having come so far since they were first conceived, it&#8217;s now possible to create equally as powerful animations and effects without needing to use any third party plugins.In today&#8217;s screencast I&#8217;m going to show you what a sprite is and just how easy it can be to create an entire animated scene using jQuery, CSS &amp; Sprites. You&#8217;ll also get to see some pretty cool out-in-the-wild examples of jQuery Sprite Animation in action, so why not check it out in my screencast below!</p>
<p><span id="more-778"></span></p>
<p>&nbsp;</p>
<p><object width="500" height="345" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,115,0" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"><param value="http://screenr.com/Content/assets/screenr_1116090935.swf" name="movie" /><param value="i=67218" name="flashvars" /><param value="true" name="allowFullScreen" /><embed width="500" height="345" pluginspage="http://www.macromedia.com/go/getflashplayer" allowfullscreen="true" flashvars="i=67218" src="http://screenr.com/Content/assets/screenr_1116090935.swf"></embed></object></p>
<p>Demos and text are available for anyone that wants to read/see them in the rest of the post.</p>
<p>&nbsp;</p>
<p><a href="http://www.addyosmani.com/resources/sprites/demo.html" style="width: 180px; color: white;" class="large blue awesome tipper" target="_blank"> View Demo</a> &nbsp;<a href="http://www.addyosmani.com/resources/sprites/spritesin5mins.zip" style="width: 180px; color: white;" class="large blue awesome tipper" target="_blank">Download Source</a></p>
<p>&nbsp;</p>
<p><img width="500" border="0" src="http://www.addyosmani.com/images/gopher.jpg" alt="" /></p>
<p>&nbsp;</p>
<p>Today&#8217;s animations are created using a really useful jQuery plugin called Spritely. You can download the Spritely plugin <a href="http://spritely.net/download/">here</a>. Spritely allows you to create your own animations using two simple functions.The pan() function which lets you pan (move) an image across the screen in a particular direction; and the sprite() function which lets you work with multiple frames and add more complex behaviours to your animations. In the screencast I show you how to first use pan() to create a moving silhouette of a city and then we use the sprite() function to add an animated plane to it. To help you with your own creations, I&#8217;m including code for both of these below.</p>
<p>&nbsp;</p>
<h2>Basic Example using Pan()</h2>
<p>&nbsp;</p>
<p>How complex your animations can get really depend on what you&#8217;re trying to achieve. If you&#8217;re trying to create a moving landscape scene, you&#8217;ll probably be able to knock that out fairly quickly because all you need to do is pan your images across the screen at a particular speed.</p>
<p><img width="500" border="0" src="http://www.addyosmani.com/images/citymove.jpg" alt="" /></p>
<p>Here&#8217;s the sample code I used to create the city skyline panning effect:</p>
<p>&nbsp;</p>
<p><strong>The jQuery</strong></p>
<pre class="javascript" name="code">
			$(document).ready(function() {
				$('#city').pan({fps: 30, speed: 2, dir: 'left'});
				});
</pre>
<p>&nbsp;</p>
<p><strong>The HTML</strong></p>
<pre class="html" name="code">
<div id="city">&nbsp;</div>
</pre>
<p>&nbsp;</p>
<p><strong>The CSS</strong></p>
<pre class="css" name="code">
		body {
			background: #fff;
			margin:0 auto;
		}

		/*City Silhouette*/
		#city {
			position: absolute;
			width: 99%;
			height: 416px;
			background: transparent url(city.png) 0 130px repeat-x;
			border: 1px solid black;
		}
</pre>
<p>&nbsp;</p>
<h2>Advanced Example Using Pan() &amp; Sprite()</h2>
<p>&nbsp;</p>
<p>If however you&#8217;d like to create something a little more detailed like a 2D or 3D character with movement, you&#8217;ll need to use a package like Maya, 3DMax or even Flash to output the animation as frames with a transparent background. Next, follow my steps below to create the jQuery animation for it.</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<ol>
<li>Output your frames as transparent PNG files to a directory on your drive. Because animation can sometimes be a memory intensive task, you&#8217;ll want to minimize this as much as possible. This can be achieved by outputting 1 frame for every 5-15 in your original animation. Don&#8217;t worry! The Spritely plugin supports setting custom frame-rates so you can still make your final animation look relatively smooth.</li>
<li>Use a Sprite Generation tool such as <a href="http://css-sprit.es">CSSSprit.es</a> or <a href="http://csssprites.com/">CSSSprites.com</a> to stitch your frames together as a single image file. Try to keep the final filesize down to within a few megabytes (I would say 2MB should really be the higher end of that filesize).</li>
<li>Next animate your content using Spritely as I did in my demo. You can find some sample code for this below.</li>
</ol>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><img width="500" border="0" src="http://www.addyosmani.com/images/skyline.jpg" alt="" /></p>
<p><strong>The jQuery</strong></p>
<pre class="javascript" name="code">
  (function($) {
			$(document).ready(function() {

			    /* City 1 */
				$('#city1').pan({fps: 30, speed: 1, dir: 'right'}); 

				/* City 2 - This gives the animation a depth of perspective
				as one city silhoette is slightly away from the other*/
				$('#city2').pan({fps: 30, speed: 2, dir: 'right'}); 

				/*The clouds and sky*/
				$('#sky').pan({fps: 30, speed: 0.5, dir: 'right'}); 

				/*The Plane animation*/
				var stage_left = (($('body').width() - 866) / 2);
				var stage_top = 30;

				/* Spritely's sprite function allows you to define
				more complex animations which contain more than 1
				frame. You can also use the spRandom feature to define
				random behaviour.
				*/
				$('#plane1').sprite({fps: 8, no_of_frames: 14})
					.spRandom({
						top: 40,
						left: stage_left + 20,
						right: 400,
						bottom: 140,
						speed: 3500,
						pause: 1000
					});

			});
		})(jQuery);
  </pre>
<p>&nbsp;</p>
<p><strong>The HTML</strong></p>
<pre class="html" name="code">
<div id="sky">&nbsp;</div>
<div id="city1">&nbsp;</div>
<div id="city2">&nbsp;</div>
<div id="plane1">&nbsp;</div>
<div id="content">
<div id="leftcontent">
<div id="rightcontent">&nbsp;</div>
</div>
</div>
</pre>
<p>&nbsp;</p>
<p><strong>The CSS</strong></p>
<pre class="css" name="code">
			body
			{
			background: #fff;
			margin:0 auto;
		     }

		#sky {
		  position:absolute;
		  width:100%;
		  height: 416px;
		  background: transparent url(sky.jpg) 0 0px repeat-x; 

		}

		#city {
			position: absolute;
			width: 100%;
			height: 416px;
			background: transparent url(city.png) 0 130px repeat-x;

		}

		#city2 {
			position: absolute;
			width: 100%;
			height: 416px;
			background: transparent url(city2.png) 0 130px repeat-x;
		}

		#plane1 {
			position: absolute;
			width: 730px;
			height: 167px;
			background: transparent url(planesprite.png) 0 50px no-repeat;
		}

		#content {

		   width: 100%;
		   position:relative;
		   clear:both;
		}

		#leftcontent {
		  width:70%;
		}

		#rightcontent {
		  width:30%;
		  background-color:blue;
		}
</pre>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>And thats it!. As with all my &#8216;Under 5 Minutes&#8217; series, you obviously won&#8217;t have learned absolutely everything there is to know about sprite animation, but hopefully you will have picked up many of the basics. Please feel free to download the source files and play around with them &#8211; I hope they come in useful!</p>
<p>&nbsp;</p>
<h2>Demo &amp; Download</h2>
<p>&nbsp;</p>
<p><a href="http://www.addyosmani.com/resources/sprites/demo.html" style="width: 180px; color: white;" class="large blue awesome tipper" target="_blank"> View Demo</a> &nbsp;<a href="http://www.addyosmani.com/resources/sprites/spritesin5mins.zip" style="width: 180px; color: white;" class="large blue awesome tipper" target="_blank">Download Source</a></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<h2>Conclusion</h2>
<p>&nbsp;</p>
<p>This tutorial was created to demonstrate how to create animations in jQuery using sprites. This powerful technique is a simple, effective way of creating cross-browser friendly animations that don&#8217;t need to rely on Flash or any third-party plugins to function. To see more demos of how Spritely is being used to add rich animated experiences to web pages, feel free to have a look at the Spritely gallery <a href="http://spritely.net/gallery/">here</a>. If you enjoyed today&#8217;s post, please share it with your friends and colleagues by clicking <a href="http://addyosmani.com/blog/jquery-sprite-animation/" class="retweet">jQuery &amp; CSS Sprite Animation Explained In Under 5 Minutes</a></p>

<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Faddyosmani.com%2Fblog%2Fjquery-sprite-animation%2F&amp;layout=standard&amp;&amp;width=450&amp;action=like&amp;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px;height:50px;margin-top:5px;"></iframe>]]></content:encoded>
			<wfw:commentRss>http://addyosmani.com/blog/jquery-sprite-animation/feed/</wfw:commentRss>
		<slash:comments>24</slash:comments>
		</item>
		<item>
		<title>jQuery Vs. JavaScript &#8211; The Masters Share Their Views On Vanilla JS</title>
		<link>http://addyosmani.com/blog/javascriptuncovered/</link>
		<comments>http://addyosmani.com/blog/javascriptuncovered/#comments</comments>
		<pubDate>Tue, 25 May 2010 00:03:05 +0000</pubDate>
		<dc:creator>Addy</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[chris coyier]]></category>
		<category><![CDATA[comparison]]></category>
		<category><![CDATA[david walsh]]></category>
		<category><![CDATA[debate]]></category>
		<category><![CDATA[james padolsey]]></category>
		<category><![CDATA[janko]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[javascript tutorial]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[jquery team]]></category>
		<category><![CDATA[jquery tips]]></category>
		<category><![CDATA[jquery tricks]]></category>
		<category><![CDATA[jquery vs javascript]]></category>
		<category><![CDATA[marco kupier]]></category>
		<category><![CDATA[mootools]]></category>
		<category><![CDATA[should i learn javascript]]></category>
		<category><![CDATA[soh tanaka]]></category>

		<guid isPermaLink="false">http://addyosmani.com/blog/?p=724</guid>
		<description><![CDATA[&#160; We&#8217;ve got a really great post for you today guys. We&#8217;re going to explore whether it&#8217;s fundamentally important for designers and developers to understand how to use vanilla JavaScript and not just it&#8217;s derivative frameworks and libraries such as jQuery and MooTools. You might be asking &#8216;why?&#8217;, but read on and you&#8217;ll find out!. [...]]]></description>
			<content:encoded><![CDATA[
<p><a href="http://addyosmani.com/blog/javascriptuncovered/"> <img border="0" alt="" src="http://addyosmani.com/blog/wp-content/uploads/masters.jpg" style="border: 0px none; display: inline;" /> </a></p>
<p>&nbsp;</p>
<p>We&#8217;ve got a really great post for you today guys. We&#8217;re going to explore whether it&#8217;s fundamentally important for designers and developers to understand how to use vanilla JavaScript and not just it&#8217;s derivative frameworks and libraries such as jQuery and MooTools. You might be asking &#8216;why?&#8217;, but read on and you&#8217;ll find out!. Because this is a topic that can invoke passion on both sides of the debate, I&#8217;ve asked a few familiar names to join the discussion including David Walsh, Chris Coyier, Marco Kupier, Janko Javanovic and James Padolsey. All of these authors use jQuery regularly and are in a good position to advise on the pros and cons of knowing vanilla JS.<br />
<span id="more-724"></span> Before we begin, I&#8217;d like to take this opportunity to introduce James Jackson as a new member of the site team who&#8217;s contribution to this post was invaluable. So let&#8217;s get started!.</p>
<p>We all know that JavaScript frameworks have made it significantly easier to create rich animated effects and interfaces in our web pages &#8211; the type of thing which previously would have taken a lot longer if we were writing everything from scratch. I&#8217;ve seen coders creating sliding effects and javascript animation for over 10 years but until now, the effort required to achieve the effects through plain JS were sometimes considered too much hassle. Throw in cross-browser compatibility issues and you had a nightmare. jQuery, MooTools and other frameworks have changed this.</p>
<p>They haven&#8217;t altered the underlying javascript (it&#8217;s important to point this out), but they have introduced an easier layer of access to JS and it&#8217;s core functionality which was previously missing. </p>
<p>The question we&#8217;re asking today is whether it&#8217;s important for people who use libraries like jQuery to understand how&nbsp; the underlying javascript works. My personal opinion is that it is &#8211; whilst you can &quot;get by&quot; knowing how to use many of the basic functins jQuery offers, I think that there&#8217;s a certain power in knowing why a particular selector should be used over another or how to create something from scratch if jQuery doesn&#8217;t particularly support executing it well.</p>
<p>Let&#8217;s now delve into this topic further with James.</p>
<p><span style="font-size: x-large;"><strong>jQuery Vs. JavaScript</strong></span></p>
<p>jQuery is the key to the Web 2.0 lock.</p>
<p>I&#8217;m not afraid to say it, and furthermore, I&#8217;m not afraid to utilize a well known buzz term like, &quot;Web 2.0&quot;.&nbsp; Now, throughout this article, I&#8217;m going to be referencing jQuery quite a bit but that&#8217;s only because it&#8217;s my favorite Javascript library and the one I know the best.&nbsp; You could easily support any number of other libraries in a similar fashion.</p>
<p>That said, jQuery has helped a whole new generation of coders approach that ever alluring, and always intimidating field of web scripting.&nbsp; Browsers themselves are greatly measured by how well (and quickly!) they can support Javascript, and jQuery alike.</p>
<p>Most people reading this article are likely already quite familiar with jQuery, so I&#8217;d like to take a generous step backward and talk about what lies beneath it.&nbsp; Javascript itself.</p>
<p>We all understand Javascript in different ways, possible by the vast variability of its usefulness, but at its core Javascript really showcases itself as a powerful, easy to use scripting language that is more accessible than many of its influences.&nbsp; The notorious C, and its derivitaves, is often understood as a pipe dream to many modern developers and yet every single Javascript programmer utilizes a syntax almost indisinguishable from C&#8217;s without ever realizing it.</p>
<p>jQuery further blurs the lines with its own, innovative syntax which causes its biggest strength to also be its biggest weakness: approachability.&nbsp; Within any system, its a common rule of thumb that the simpler it is to use, the more removed from the source material it gets.&nbsp; jQuery is no exception.</p>
<p>A great deal of jQuery programmers I have known since its inception have been drawn to jQuery for its simplicity, betwitched by its seeming ability to allow the average web designer to magically produce Javascript effects that were otherwise impossible.&nbsp; When a client wants something to zoom across the screen, or to showcase a slideshow of photographs, jQuery answers the call.&nbsp; With a few script includes and some copying and pasting, its not only possible but extremely effective.&nbsp; With the overwhelming amount of customization that jQuery Plugin developers put into their modules, coders can even have intricate control over these effects without ever touching a single line of raw Javascript.&nbsp; jQuery takes care of all of it for you.</p>
<p>The problem herein lies in the moment that every late-night script surgeon will inevitably encounter: when something doesn&#8217;t do *exactly* what we need it to.&nbsp; We try tweaking the settings, finding an alternative plugin or scaring ourselves witless looking at the wall of code within the plugins themselves.</p>
<p>Don&#8217;t worry &#8212; we&#8217;ve all been there.&nbsp; This frustration, however, doesn&#8217;t have to halt our programming process and can instead offer an exciting challenge.&nbsp; If we understand the underlying code well enough, then virtually nothing is outside of our grasp within the world of Javascript.</p>
<p>Virtually any element within a web page, through the most popular operating system on the planet &#8212; the web browser, is accessible and can have its attributes changed.&nbsp; New elements can be created, manipulated and even removed from existence.&nbsp; Your keyboard becomes your brush and the browser becomes your canvas.&nbsp; Literally, even now with HTML5.</p>
<p>jQuery provides a proverbial &#8216;Paint by Numbers&#8217; tool for us, but when we need to break away from the lines and numerical digits, the paper beneath needs to be understood as well.</p>
<p>I&#8217;m sure it goes without saying, but I&#8217;d bet that the average jQuery enthusiast without extensive knowledge of Javascript doesn&#8217;t fully realize what jQuery is: a collection of Javascript.&nbsp; It&#8217;s not a new environment, it&#8217;s not an expansion pack; it&#8217;s a big pile of Javascript that draws a curtain between you and Javascript.&nbsp; All the web&#8217;s a stage, and the DOM is its players.</p>
<p>Most readers, who are familiar with jQuery know of the $() identifier.&nbsp; It allows you to select, or create/remove, any element on a webpage and manipulate it.&nbsp; If we want to grab an element like this:</p>
<pre name="code" class="javascript">
<div id="example">&nbsp;</div>
</pre>
<p>Then all we require to select it is:</p>
<pre class="javascript" name="code">
$(&quot;#example&quot;)</pre>
<p>From there, we can affect it in the multitude of ways that jQuery provides.&nbsp; What does this $() mean, though, exactly?&nbsp; How does it work?&nbsp; Is it magic?</p>
<p>In all actuality, $()&#8217;s usefulness, speed and versatility is bound only by your understanding of it. Before we delve further into this, lets remember that $() is a jQuery selector which can take more than one parameter, element IDs separated by commas and returns elements as objects in an array. For the sake of simplicity, let&#8217;s imagine that we&#8217;re just trying to get the very first element matched in the DOM with a particular ID (in jQuery this translates to $(&#8216;#example&#8217;)[0]) In this case, we could achieve this in standard vanilla JavaScript as follows:</p>
<pre class="javascript" name="code">
document.getElementById(&quot;example&quot;)</pre>
<p>Now, because Javascript has this functionality included right into its core, calling elements in this way greatly speeds up jQuery (tests show that getElementById is faster than standard selection in jQuery, however, this is only when you want to grab elements of a particular ID rather than a collection of elements).&nbsp; Because we&#8217;re making it so that jQuery doesn&#8217;t have to churn through functions and translators, and instead can just use Javascript&#8217;s built-in functionality to jump right to the item. Again, let&#8217;s remember that jQuery actually provides us with ways of accessing elements by much more advanced selection techniques, however, if you know exactly what you&#8217;re after, vanilla can help.</p>
<p>What does this mean to you?&nbsp; SPEED.&nbsp;</p>
<p>By understanding this aspect of Javascript, you can literally cut whole chunks of processing time out of your plugins and scripts. We should note however that jQuery&#8217;s use of the Sizzle selector engine has done it&#8217;s best to eliminate redundancy when looking up elements in the DOM, but there are still gains to be made for those that understand the underlying javascript.</p>
<p>The Animate feature of jQuery, as mentioned above, allows us to move any element on a page around the browser&#8217;s view port with only a few lines of code:&nbsp;</p>
<pre name="code" class="javascript">
$(&quot;#element&quot;).animate({ left: 100px; });</pre>
<p>This makes moving #element 100 pixels to the right extremely simple.&nbsp; However, let&#8217;s assume that we want to add a wavy-animation to our element, so it doesn&#8217;t mearly glide to the left but instead waves around (as though our precious #element has had a few to many Box Model Martini&#8217;s).&nbsp; This is possible with jQuery, of course, and there are even plugins available to accomplish it.&nbsp; Let&#8217;s further assume that either we have a very specific vision for how it will animate or (more likely) our client does.</p>
<p>Either way, time will be spent.&nbsp; Whether its time spent looking for the appropriate plugin, or writing the code ourself.</p>
<p>If we briefly break down jQuery.Animate, we get a very simple process: an event occurring within an interval or timer, selecting the element (by ID) and changing its &#8216;style.left&#8217; property incrementally through CSS.&nbsp;. Animate() of course supports a wide range of features including intervals, easing and other plugins, but if we wanted to take animate at it&#8217;s most basic and wanted to re-create this in basic javascript (moving an element across the screen), lets see how we cold create that code.</p>
<pre class="javascript" name="code">
var example = null; // object

function doMove() {
  example.style.left = parseInt(example.style.left)+1+'px';
  setTimeout(doMove,20); // call doMove in 20msec
}

function init() {
  example = document.getElementById('example'); // get the &quot;example&quot; object
  example.style.left = '0px'; // set its initial position to 0px
  doMove(); // start animating
}

window.onload = init;
</pre>
<p>&nbsp;</p>
<p>And we&#8217;re done.&nbsp;Now obviously, there is a LOT more going on behind the animate function &#8211; it supports chaining, easing plugins and a greater level of modification than simply moving an item across the screen, but in its most basic form, that&#8217;s what we&#8217;re trying to achieve.</p>
<p>This is a more advanced example, so what if you want to mimic a much simpler function of jQuery?&nbsp; Say, the hide() command?</p>
<p>&nbsp;</p>
<pre name="code" class="javascript">
$(&quot;example&quot;).hide();</pre>
<p>&nbsp;</p>
<p>This comes in really handy, as you can hide elements that are not currently needed in your application.&nbsp; What does this function *do* exactly, though?&nbsp; As with so many things, the better we understand something, the better we can innovate.</p>
<p>Much of what makes Web Apps so functional (and, let&#8217;s admit it, pretty) is affecting their CSS attributes: their color, their opacity, their location on the screen, etc.&nbsp; The hide() function affects one of the most used CSS attributes: display.</p>
<p>To translate the above hide command, we could also imagine it like this:&nbsp;</p>
<p>&nbsp;</p>
<pre name="code" class="javascript">
 $(&quot;#example&quot;).css(&quot;display&quot;,&quot;none&quot;);</pre>
<p>&nbsp;</p>
<p>Of course, the hide() command gives you more control over the effect, but by using the css() command instead, we can now do some pretty interesting things, such as:</p>
<p>Blend an object in with the text, rather than putting it on its own line:</p>
<p>&nbsp;</p>
<pre name="code" class="javascript">
 $(&quot;#example&quot;).css(&quot;display&quot;,&quot;inline&quot;);</pre>
<p>&nbsp;</p>
<p>The opposite, take an inline element (e.g. &lt;strong&gt;) and make it take up a whole line:</p>
<p>&nbsp;</p>
<pre name="code" class="javascript">
 $(&quot;#example&quot;).css(&quot;display&quot;,&quot;block&quot;);</pre>
<p>&nbsp;</p>
<p>That&#8217;ll get someone&#8217;s attention!</p>
<p>Far too often, a jQuery developer will find themselves poking and prodding a bit of jQuery code, trying to get it to behave properly; when their answer is just a css() command away.</p>
<p>This is not to say that you have to choose between Javascript or jQuery, though.&nbsp; By combining the two, we can still use jQuery for what it&#8217;s best at: selecting elements and manipulating their attributes.&nbsp; For example, instead of using the whole line of document.getElementById(&quot;element&quot;) we can save ourselves some code by using $(&quot;#element&quot;).&nbsp; jQuery has a built-in checker for elements selected by that and will essentially translate it to our full &quot;getElementById&quot; line, anyhow, so we are literally just using it to abbreviate our code.</p>
<p>This is just the tip of the iceberg.&nbsp; Technically speaking, jQuery is a collection of snippets that allow someone to abide by the D.R.Y. (Don&#8217;t Repeat Yourself) method of programming.&nbsp; I urge you, however, to take advantage of jQuery, but not completely depend on it to code.</p>
<p>jQuery is a tool.&nbsp; Javascript is the garden.&nbsp; Together, they can allow us to cultivate endless abundance if utilized in harmony.</p>
<p>Knowing jQuery (among many other scripting libraries) in this modern world of web development is crucial.&nbsp; It provides quicker turn around times, opens your code up to a vast world of other developers and makes your code efficient, and easy to read.&nbsp; However, even the best tools are only as useful as the person who wields them.</p>
<p>If we have not only a better understanding of our tools, but also our environment, then we can help usher in &#8212; if not pioneer &#8212; the next era of web developers.</p>
<p>&nbsp;</p>
<p><span style="font-size: x-large;"><strong>Thoughts from:</strong></span><strong></p>
<p><span style="font-size: large;">David Walsh</span><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;</p>
<p><img width="200" vspace="10" hspace="10" height="200" align="left" style="padding: 10px;" alt="" src="http://addyosmani.com/blog/wp-content/uploads/david.jpg" /></p>
<p>&quot;Learning JavaScript is absolutely paramount to becoming an effective Web Designer or Developer.&nbsp; While the JavaScript libraries do as much as possible to ease the pain of some of JavaScript&#8217;s more time-consuming tasks, libraries cannot anticipate their every use.&nbsp; Without proper knowledge of JavaScript, a developer can spend hours debugging an issue that should really only take a few moments.&nbsp; Spending the time to become a &#8216;Vanilla JS&#8217; expert will allow a developer to more easily learn *any* of the popular frameworks, thus making that developer far more valuable.&quot;</p>
<p>&nbsp;</p>
<p><span style="font-size: large;"><strong>Chris Coyier</strong></span></p>
<p><img width="200" vspace="10" hspace="10" height="200" align="left" style="padding: 10px;" alt="" src="http://addyosmani.com/blog/wp-content/uploads/chris.jpg" /></p>
<p>&quot;I&#8217;d love to tell you all about how life will be better if you learn and understand JavaScript before you learn libraries. Or at least, that you should go back and get those fundamentals after starting out with libraries. Here is reality for me though: I&#8217;m terrible at vanilla JavaScript. It would be pretty hard for me to try and get day-to-day design work done if I couldn&#8217;t use jQuery. In fact, I probably just wouldn&#8217;t do it, and stick to design and markup. I&#8217;d love to go back and get those fundamentals, and I probably will over time, and it will make me better, but I&#8217;m also living proof that you can still get the job done being a library junkie.&quot;<span style="font-size: large;"><br />
</span></p>
<p>&nbsp;</p>
<p>&nbsp;<span style="font-size: large;"><strong>Janko Javanovic</strong></span></p>
<p><img width="200" vspace="10" hspace="10" height="200" align="left" style="padding: 10px;" alt="" src="http://addyosmani.com/blog/wp-content/uploads/janko.jpg" />&quot;I will be glad to give an opinion about js/jQuery. I agree that developers should have at least some understanding of JavaScript. jQuery and similar libraries might be a good way to get people interested in JavaScript in general. But in the other hand it might actually be a stumbling block &#8211; it&#8217;s so easy to use jQuery that many don&#8217;t need a deeper understanding of JS.</p>
<p>Lack of knowledge become obvious when developers need to modify/extend some jQuery code. They don&#8217;t understand it fully. And then they cry for help. So I&#8217;d say it would be better for them to learn a few things about JS and try figure things out themselves. Otherwise, chances are they will never learn.&quot;</p>
<p><span style="font-size: large;"><strong>Marco Kuiper</strong></span></p>
<p><img width="200" vspace="10" hspace="10" height="200" align="left" style="padding: 10px;" alt="" src="http://addyosmani.com/blog/wp-content/uploads/marco.jpg" /></p>
<p>&quot;Very interesting topic, especially since I learned jQuery before learning actual JavaScript myself (the only JavaScript I knew before that were the &quot;mouse following clock&quot; and &quot;disable right click&quot; stuff &#8211; you know, back in the days&#8230;). But at the time I started to get a hang of jQuery, I did wanted to learn more about JavaScript. Why? Basically because I wanted to get the maximum out of jQuery.</p>
<p>For example, take a look at speed. I learned that using an ID selector ( $(&quot;#myelement&quot;) ) is around 100 times faster than a class selector ( $(&quot;.myelement&quot;) ) . This is because the ID selector maps to the native &quot;getElementByID()&quot; JavaScript function. The same is for using tag selectors ( $(&quot;body&quot;) ), since that maps to the native &quot;getElementsByTagName()&quot; JavaScript function. The class selector loops through all the objects in the DOM to find the specified elements. There are more speed tricks for jQuery that you would know if you knew how JavaScript works.</p>
<p>I truly love the way how you can create elements in jQuery 1.4; Simply apply an element name to the jQuery core method and you&#8217;re ready to go ( $(&quot;&lt;div /&gt;&quot;) ). Before that way was implemented in jQuery, you could simply use the native JavaScript method &quot;document.createElement()&quot;. Although it isn&#8217;t as great as the way jQuery creates elements, it did allow you to create elements using JavaScript. Using those kind of methods even before it was added to the jQuery core, and you were sure to be one step ahead of the rest.</p>
<p>The last example I want to show you, is the use of parameters. The jQuery &quot;.bind()&quot; method attaches behavior to a specified element. The first parameter is the eventType, like &quot;click&quot;, &quot;mouseenter&quot; and &quot;mouseleave&quot;. How would you know which eventTypes you could specify, if you don&#8217;t know the implementation of JavaScript (&quot;object.onmouseenter&quot; etc.)? And why do you use all those curly brackets (when creating objects) and using functions as parameters ( $(&quot;#myelement&quot;).click(function() { var doStuff; } ); )? All that kind of stuff is JavaScript that you&#8217;re using. If you&#8217;re using it, use it and learn it correct.</p>
<p>So, if you want to get better at jQuery, take a look &quot;under the hood&quot; to see the JavaScript engine that is working hard for you. Learn and master it!&quot;</p>
<p>&nbsp;</p>
<p><span style="font-size: large;"><strong>James Padolsey</strong></span></p>
<p><img width="200" vspace="10" hspace="10" height="200" align="left" style="padding: 10px;" alt="" src="http://addyosmani.com/blog/wp-content/uploads/james.jpg" /></p>
<p>&quot;I agree that there is a problem with the terminology used throughout the jQuery community. jQuery uniquely appeals to people with minimal programming experience and that makes it all the more complicated to explain it in the right way. I&rsquo;ve always been a proponent of learning JavaScript and the DOM API before any library. I&rsquo;m not saying that this is the only way; obviously there are people who have learnt it the other way round, and they&rsquo;re just as proficient as you or I. But, still, there is a difficulty to overcome, and I think there&rsquo;s a lot of progress that needs to be made in the way that jQuery&rsquo;s paradigms and implementation are explained to beginners. I think you&rsquo;re right about &ldquo;wrapping&rdquo; being misleading, but, it is a helpful metaphor which gives beginners confidence when using jQuery.</p>
<p>Let&rsquo;s face it! Most people that use jQuery are not looking to become an expert. They don&rsquo;t care about its internals or what really happens when they call the magical dollar. They just want it to work. The people who really want to dig into it will do so by their own means.</p>
<p>I&rsquo;ve used some of these metaphors myself, such as &ldquo;caching&rdquo; &mdash; it can be misleading but most &ldquo;web&rdquo; people understand the term. If I said &ldquo;reference&rdquo; instead then I&rsquo;d have to explain what a reference is and how objects in JavaScript are different to primitive types, and how an identifier is simply a pointer to an object in &ldquo;memory&rdquo;&hellip; it gets complicated very quickly.</p>
<p>jQuery is one of those cool technologies that gives you tremendous power right off the bat! That&rsquo;s what appeals to beginners, I think. They feel powerful; they feel that they pretty-much understand jQuery and how it works. We wouldn&rsquo;t want to shatter that confidence by the realisation that they, in fact, still have a lot to learn about jQuery, JavaScript, and the DOM.</p>
<p>Don&rsquo;t get me wrong. I really do support the idea that beginners should be taught correctly right from square one, but I think it needs to be done delicately. You can&rsquo;t drown them with complicated words and ideas; that&rsquo;ll surely scare them away.&quot;</p>
<p>I would say that learning APIs and abstractions such as the DOM, jQuery, Mootools, Prototype, Dojo, ExtJS and others is quite pointless for the beginner because there are literally thousands of libraries, toolkits and frameworks that the beginner _could_ pick up&#8230;. Obviously the DOM is central but at the end of the day it&#8217;s just a bunch of method-names and argument signatures that you have to remember.</p>
<p>What needs to be taught is **JavaScript** &#8230; or rather, ECMAScript.. the real thing &#8212; i.e. hand out a copy of the ES3 specification. (actually, that&#8217;d definitely scare people)</p>
<p>The problem with learning JS is that most of the really good resources are simply not geared towards beginners. Websites like w3schools and &quot;javascript.about.com&quot; ARE geared towards beginners but their content is crap &#8212; it&#8217;ll get an individual past the noob phase but not any further. They need to be learning about primitives, objects, variable declaration, function declaration, function expressions, scope, closure, operator precedence, booleans&#8230; blah blah blah&#8230; The rhino book is what they all really need.</p>
<p>Most of the people using jQuery don&#8217;t even want to &quot;program&quot;, per se; they just want to add cool&#8217;ness to their websites. Telling them they defined a global instead of a local var, and they should probably use function declarations because it makes debugging easier is pointless because they really couldn&#8217;t care less. The devs that really care about code quality and all the stuff we love are already on the path to enlightenment.&quot;</p>
<p>&nbsp;</p>
<p><strong><span style="font-size: large;">Conclusions</span></strong></p>
<p>And that&#8217;s it guys. What are your thoughts on the topic?. Do <em>you</em> think that it&#8217;s important to have an understanding of basic JavaScript?. We&#8217;d all love to have an open discussion on this and we&#8217;d really like to hear your opinions in the comments section below.  If you liked the post, remember that you can easily share it with your friends and colleagues just be clicking the <a class="retweet" href="http://addyosmani.com/blog/javascriptuncovered/">jQuery Vs. JavaScript &#8211; The Masters Share Their Views On Vanilla JS</a> button. I hope you found this post useful guys!</p>
<p>.</p>

<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Faddyosmani.com%2Fblog%2Fjavascriptuncovered%2F&amp;layout=standard&amp;&amp;width=450&amp;action=like&amp;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px;height:50px;margin-top:5px;"></iframe>]]></content:encoded>
			<wfw:commentRss>http://addyosmani.com/blog/javascriptuncovered/feed/</wfw:commentRss>
		<slash:comments>31</slash:comments>
		</item>
		<item>
		<title>8 jQuery Performance &amp; Optimization Tips You Need In 2010</title>
		<link>http://addyosmani.com/blog/8-jquery-performance-tips/</link>
		<comments>http://addyosmani.com/blog/8-jquery-performance-tips/#comments</comments>
		<pubDate>Sat, 01 May 2010 10:50:00 +0000</pubDate>
		<dc:creator>Addy</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[jquery performance optimization optimal junit fireunit jquery unit testing root selectors optimizing benchmarking]]></category>

		<guid isPermaLink="false">http://addyosmani.com/blog/8-jquery-performance-optimization-tips-you-need-in-2010/</guid>
		<description><![CDATA[&#160; Great topic today!. Performance optimization. Performance optimization is an important aspect of any type of coding project, including those that use jQuery. Today I&#8217;m going to go through some quick useful jQuery coding and performance tips that I think are important for every JavaScript developer to bare in mind when writing their projects using [...]]]></description>
			<content:encoded><![CDATA[
<p><a href="http://addyosmani.com/blog/8-jquery-performance-tips/"><img width="530" height="342" border="0" src="http://addyosmani.com/blog/wp-content/uploads/2010/04/per.jpg" alt="per" style="border: 0px none; display: inline;" title="per" /></a></p>
<p>&nbsp;</p>
<p>Great topic today!. Performance optimization. Performance optimization is an important aspect of any type of coding project, including those that use jQuery. Today I&#8217;m going to go through some quick useful jQuery coding and performance tips that I think are important for every JavaScript developer to bare in mind when writing their projects using the jQuery framework. Some of these are going to be a little obvious whilst others are things that you might not have considered doing before.</p>
<p><span id="more-717"></span></p>
<p>Ask yourself this question. Do you think that your scripts are currently running as quickly as they could be?. Do they occupy the smallest filesize footprint and still deliver the same results as their un-optimized counterparts?. The answer to these questions in most cases is &lsquo;no&rsquo;.</p>
<p>Often in web development we&rsquo;re working against tight deadlines and can sometimes fall into a pattern of thinking that if our scripts work in all web browsers and aren&rsquo;t howling alert! help me! that our job is done. The truth is that if we were to all put in just a little bit more effort, we could actually deliver web applications and scripts that are both fully functional and as optimal as they can be.</p>
<p>Today I&rsquo;m going to give you 8 tips that will help you ensure that your jQuery projects stay optimized.</p>
<p><strong></p>
<h2>1. Stay up to date! Are you using methods and techniques that are obsolete?.</h2>
<p></strong></p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="http://addyosmani.com/blog/wp-content/uploads/2010/04/image9.png" class="thickbox"><img width="384" height="294" border="0" src="http://addyosmani.com/blog/wp-content/uploads/2010/04/image_thumb8.png" alt="image" style="border-width: 0px; display: inline;" title="image" /></a></p>
<p>When I say obsolete, I mean that there may be better ways to achieving code that you regularly write. The easiest way to find out if this is the case is to ask yourself this question:&nbsp; Do you know what the differences between jQuery 1.3.2 and jQuery 1.4.2 are?. If not, keep reading!</p>
<p>The jQuery team spend hundreds of combined hours every year churning out new functions and optimizing the existing ones in the jQuery library. Heck, I sometimes question if John Resig even sleeps, such is his dedication to making the library be as efficient as possible.</p>
<p>What this means is that if you&#8217;re able to use the latest features and techniques jQuery has to offer that are more optimal that what you&#8217;ve been using so far, you can get very cheap, very quick boosts in performance for your application.</p>
<p>We all know that it can be a lot easier just using the jQuery techniques you&rsquo;re already used to, but if it just takes a few minutes to read through the specs and pick up a few quick performance wins, then why not just do it?</p>
<p>Do you know what all of these do?</p>
<p>
Delegate/Undelegate<br />
nextUntil<br />
Chaining event handlers<br />
Controlling a functions context<br />
Does a element have something? (.has)<br />
Element Unwrapping<br />
Determining an object&#8217;s type</p>
<p>If not, here are the tutorials and references for the jQuery:</p>
<ul>
<li><strong>1.4</strong> features: <a href="http://net.tutsplus.com/tutorials/javascript-ajax/jquery-1-4-released-the-15-new-features-you-must-know/">http://net.tutsplus.com/tutorials/javascript-ajax/jquery-1-4-released-the-15-new-features-you-must-know/</a></li>
<li><strong>1.4.1</strong> features: <a href="http://api.jquery.com/category/version/1.4.1/">http://api.jquery.com/category/version/1.4.1/</a></li>
<li><strong>1.4.2</strong> core features: <a href="http://www.learningjquery.com/2010/03/using-delegate-and-undelegate-in-jquery-1-4-2">http://www.learningjquery.com/2010/03/using-delegate-and-undelegate-in-jquery-1-4-2</a> and&nbsp; <a href="http://api.jquery.com/category/version/1.4.2/">http://api.jquery.com/category/version/1.4.2/</a></li>
</ul>
<p>you can also find tons of 1.4.2 snippets in my recent jQuery <a href="http://addyosmani.com/blog/?s=snippets">snippet posts</a>.</p>
<p>&nbsp;</p>
<p><strong></p>
<h2>2. Context-aware jQuery Code Execution &ndash; Are you loading code that isn&rsquo;t needed?</h2>
<p></strong></p>
<p>&nbsp;</p>
<p>There are some developers that will load all of the jQuery code for a site on every page, regardless of whether or not it&rsquo;s going to be used there or not. (Don&rsquo;t worry, if you&rsquo;ve done this before, the good news is you can always change that habit!).</p>
<p>What you need to remember is that jQuery still has to take time to execute that code and if its not needed you can get a quick performance gain by checking whether you&#8217;re on a page which requires that script to run.</p>
<p>This can be achieved in many ways such as defining a class or ID unique to each page&rsquo;s content and checking for it&#8217;s existence before you run it&#8217;s specific code or even through server-side processing if you want to run check on the filename being accessed.</p>
<p>As long as you can do your best to only load code that&rsquo;s needed, you&rsquo;ll get some quick performance boosts that may not have been there if you hadn&rsquo;t thought about this in advance.</p>
<p>&nbsp;</p>
<p><strong></p>
<h2>3. jQuery Unit Testing</h2>
<p></strong></p>
<p>&nbsp;</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="http://addyosmani.com/blog/wp-content/uploads/2010/04/image10.png" class="thickbox"><img width="436" height="241" border="0" src="http://addyosmani.com/blog/wp-content/uploads/2010/04/image_thumb9.png" alt="image" style="border-width: 0px; display: inline;" title="image" /></a></p>
<p>
How many of you have actually written unit tests for your JavaScript or jQuery code this week?. I&#8217;m hearing crickets and one man in the corner saying &lsquo;me&rsquo;. Uh oh. I think that there&#8217;s a tendency for us web developers to&nbsp; forget that just like Java, C++ or .NET, JavaScript is a programming language equally as capable of having bugs as the others and to minimize this, spend just that extra little bit of time on your project writing some unit tests for your code. It&rsquo;s really really easy to.</p>
<p>Not only is it good as a software engineering best practice, but it&rsquo;s also something you need if your code is going into a live production system which could be accessed by a large audience. You want your code to be fully functional and to be structured in such a way that you know exactly how it&rsquo;s going to behave and can anticipate quirks in advance.</p>
<p>One right off the top of my head is if you&rsquo;re using Ajax to load up some of your page content. If things are taking a longer to load up than they should, wouldn&rsquo;t it be nicer if your app output a &lsquo;Connection Issue Detected, please try refreshing&rsquo; message rather than just hanging for ages?. Believe me, your users will appreciate your attention to detail.</p>
<p>If you&#8217;re looking for some powerful JavaScript unit testing tools, QUnit and FireUnit are both quite useful and I&#8217;d recommend checking them out. Nettuts also put out a really straightforward <a href="http://net.tutsplus.com/tutorials/javascript-ajax/how-to-test-your-javascript-code-with-qunit/">article</a> last year on how to use QUnit to test your jQuery code and I&rsquo;d recommend giving it a read some time.</p>
<p><strong></p>
<h2>4. Benchmark Your jQuery Code</h2>
<p></strong></p>
<p>&nbsp;</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="http://addyosmani.com/blog/wp-content/uploads/2010/04/image11.png" class="thickbox"><img width="370" height="284" border="0" src="http://addyosmani.com/blog/wp-content/uploads/2010/04/image_thumb10.png" alt="image" style="border-width: 0px; display: inline;" title="image" /></a></p>
<p>How fast is your code? If you&rsquo;re looking for a simple way to improve the performance of your code, simply log the amount of time it takes for your functions to execute and use that as a starting point for your optimization strategy.</p>
<p>The Firebug console makes it very easy for any JavaScript developer to log debug information in the same way you would with any other language&rsquo;s IDE so consider using it. Logging might sound very simple, but it can actually turn up quirks in your code you may not have realized existed or which may need optimization.</p>
<p>Now if you&rsquo;re looking for even more accurate results (remember, Firebug is an add-on and will introduce marginal delays to your stats because it&rsquo;s GUI needs to be updated dynamically), close Firebug and create your own own simple logging tool as follows (note: this is a very basic example and you&rsquo;ll need to edit the code as per your needs).</p>
<p>JavaScript</p>
<pre class="javascript" name="code">
function t() {
    var time = new Date();
    return time.getTime();
} 

$(window).load(function() {
    var s = t(); 

    for (var i=0; i&lt;10000; i=i+1) {
        $('#content').html(&quot;hello&quot;);
    }
    $('#out').append( (t()-s) +'ms');
});
</pre>
<p>HTML</p>
<pre class="html" name="code">
<div>Time:</div>
<div>Content:</div>
</pre>
<p>Benchmarking ensures that you know how fast your code runs, not just in one browser but potentially in all of them. This can be of significant importance when you&rsquo;re talking about large jQuery applications or apps that rely heavily on JavaScript based animations or Ajax.</p>
<p>&nbsp;</p>
<p><strong></p>
<h2>5. Keep download times to a minimum with one compressed master JS file.</h2>
<p></strong></p>
<p>&nbsp;&nbsp;&nbsp; <a href="http://addyosmani.com/blog/wp-content/uploads/2010/04/image12.png" class="thickbox"><img width="446" height="295" border="0" src="http://addyosmani.com/blog/wp-content/uploads/2010/04/image_thumb11.png" alt="image" style="border-width: 0px; display: inline;" title="image" /></a></p>
<p>Page-load speeds are an ever increasingly important factor in performance optimization and one only needs to look at Google&rsquo;s inclusion of this in page rankings to realize just how important decreasing the number of files you need to load is.</p>
<p>How many WordPress, Corporate or Portfolio sites to you visit where if you look at the source code, you&#8217;ll see maybe 10 or 12 different JavaScript files that need to be loaded before the page is ready to be used?. If you want your pages to load quicker, just ensure that you use a compression and concatenation tool that will put all your scripts into the same file so you can still update them separately but they&#8217;ll be delivered at the same time on your live site. This way you&#8217;ll achieve both a smaller JavaScript footprint<br />
and your site only requiring one JS file to download for your code.</p>
<p>(A sidenote with that is, please try to cut down on the number of document.ready and window.load instances in your page. If your code will all be running out of the same file, it probably makes sense to just have one instance of these running).</p>
<p>These resources will help you achieve all of the above and are free whether<br />
you are using a PC or Mac:</p>
<p><a href="http://jscompress.com/">http://jscompress.com/</a> (for any sites)<br />
<a href="http://www.halmatferello.com/lab/wp-js/">http://www.halmatferello.com/lab/wp-js/</a> (for WordPress users)<br />
<a href="http://ant.apache.org/manual/CoreTasks/concat.html">http://ant.apache.org/manual/CoreTasks/concat.html</a> (for Ant users)&nbsp;&nbsp;</p>
<p><strong></p>
<h2>6. Context Vs. Find</h2>
<p></strong></p>
<p>&nbsp;</p>
<p>It&rsquo;s true, where possible you should always try to run your selections based on a context however it&rsquo;s useful just to bare in mind that when you&rsquo;re passing a context to the jQuery constructor, it creates an extra unnecessary extra function call.</p>
<p>jQuery&rsquo;s insides run content.find(selector) anyway, so you can technically skip that step if you&rsquo;re working in a page structure that may not benefit greatly from using context. Below you can see an example of what I&rsquo;m talking about.</p>
<pre class="javascript" name="code">
//This is context is typically used.
$('div', context ).doSomethingOrOther();

//But here, you can do the same thing minus the extra
//instance and the additional function call
context.find('div').doSomethingOrOther();
</pre>
<p><strong></p>
<h2>7. Window.load all the way.</h2>
<p></strong></p>
<p>&nbsp;</p>
<p>Document.ready isn&rsquo;t a terrible thing, but it&#8217;s a habit that many developers still have including myself occasionally. It doesn&#8217;t matter where you&#8217;re using $(function(){}); or the full version of this, but truth be told it is significantly more optimal to be using Window.load in your applications.</p>
<p>The reason behind this idea is that document.ready happens during page render while&nbsp; objects are still downloading and that cause some stalls in your page. You don&rsquo;t want that. You can however reduce the CPU utilization during the page load by binding your jQuery functions to&nbsp; the $(window).load event &#8211; it occurs after all objects called by the HTML have fully completed downloading.</p>
<p>That&rsquo;s one line change that can give you scripts that little extra performance boost!.</p>
<p><strong> </strong></p>
<h2><strong>8.</strong> <strong>Strike A Balance Between Your Use Of JavaScript &amp; jQuery</strong></h2>
<p>&nbsp;</p>
<p>jQuery is a fantastic way to speed up work for almost anyone on the front-end. Remember however, that there are scenarios where jQuery may take longer to execute certain functions than if you were to use regular JavaScript. CSS styling is just one example that comes to mind.</p>
<p>Some of the other methods we&#8217;re all used to using like show() and hide() also have their own performance overheads so always remember to strike a balance between your code&#8217;s complexity and it&#8217;s overall efficiency. You can always mix plain JavaScript code with some jQuery and in most cases it should still run fine.</p>
<p>Another situation is this: If all you need to do is run two lines of JavaScript code, there isn&#8217;t a need for you to use jQuery (even in it&#8217;s minified form it&#8217;s still roughly 20-30kb&#8217;s worth of extra data that needs to be downloaded).&nbsp; Similarly, if you&#8217;re writing a large complex application try to use jQuery rather than writing overly long plain-JavaScript script.</p>
<p>Use best judgement here and you&#8217;ll find that you&#8217;ll get the both of both worlds and their combined performance advantages.</p>
<p>&nbsp;</p>
<p><strong>And that&rsquo;s it!. If you&rsquo;ve found this post useful please feel free to share it with your friends and colleagues by clicking the <a href="http://addyosmani.com/blog/8-jquery-performance-tips/" class="retweet">8 jQuery Performance &amp; Optimization Tips You Need</a> button. Until next time, may the $ be with you.</strong></p>

<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Faddyosmani.com%2Fblog%2F8-jquery-performance-tips%2F&amp;layout=standard&amp;&amp;width=450&amp;action=like&amp;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px;height:50px;margin-top:5px;"></iframe>]]></content:encoded>
			<wfw:commentRss>http://addyosmani.com/blog/8-jquery-performance-tips/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
	</channel>
</rss>
