<?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>Richard Shepherd &#187; link nudge</title>
	<atom:link href="http://www.richardshepherd.com/tag/link-nudge/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.richardshepherd.com</link>
	<description>Making the web. Better looking.</description>
	<lastBuildDate>Fri, 04 Jun 2010 18:03:25 +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>Using jQuery to nudge links</title>
		<link>http://www.richardshepherd.com/using-jquery-to-nudge-links/</link>
		<comments>http://www.richardshepherd.com/using-jquery-to-nudge-links/#comments</comments>
		<pubDate>Thu, 19 Mar 2009 07:58:20 +0000</pubDate>
		<dc:creator>richardshepherd</dc:creator>
				<category><![CDATA[Web]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[link nudge]]></category>

		<guid isPermaLink="false">http://www.growlingranger.com/?p=502</guid>
		<description><![CDATA[jQuery is so blooming useful! There&#8217;s an effect you&#8217;re seeing all over the web now, where links nudge over to the right when you mouse over them. So, here&#8217;s a simply tutorial to get jQuery link nudges onto your pages in just 5 minutes! First we need need to include the jQuery library in the [...]]]></description>
			<content:encoded><![CDATA[<p>jQuery is so blooming useful! There&#8217;s an effect you&#8217;re seeing all over the web now, where links nudge over to the right when you mouse over them.</p>
<p>So, here&#8217;s a simply tutorial to get jQuery link nudges onto your pages in just 5 minutes!</p>
<p>First we need need to include the jQuery library in the &lt;head&gt; section of your page, which we can do with something like this&#8230;</p>
<pre class="javascript" name="code">
<script type='text/javascript' src='http://code.jquery.com/jquery-latest.js'></script>
</pre>
<p>And then we need the actual jQuery code that does all the magic. Again, this is in the &lt;head&gt; of your page.</p>
<pre class="javascript" name="code">
<script language='JavaScript' type='text/javascript'>
$(document).ready(function(){
$('a.nudge').hover(function() {
   $(this).animate({ paddingLeft: '5px' }, 200);
   }, function() {
      $(this).animate({ paddingLeft: 0 }, 200);
   });
});
</script>
</pre>
<p>So what does that do?</p>
<p>First of all is the usual jQuery DOM ready command,</p>
<pre class="javascript" name="code">
$(document).ready(function(){
</pre>
<p>which ensures we don&#8217;t execute any code until all the DOM elements have been loaded. We then tell jQuery to take all <strong>&lt;a href=&#8221;anything here&#8221; class=&#8221;nudge&#8221;&gt;&lt;/a&gt;</strong> elements and add a function to them &#8211; in this case, whenever the user hovers over them.</p>
<pre class="javascript" name="code">
$(document).ready(function(){
</pre>
<p>When the user hovers over the link, we then run the following piece of code, which is a standard jQuery animate method:</p>
<pre class="javascript" name="code">
   $(this).animate({ paddingLeft: '5px' }, 200);
   }, function() {
      $(this).animate({ paddingLeft: 0 }, 200);
   });
</script>
</pre>
<p><strong>$(this)</strong> is referring the element we have hovered over. This is great, because it means we can use the class &#8216;nudge&#8217; on multiple elements on one page &#8211; in other words we can have whole menu systems with links that nudge.</p>
<p>We animate the link <strong>5px</strong> to the right by changing the padding-left css property (in javascript this is referred to as <strong>paddingLeft</strong> rather than padding-left. <strong>200</strong> is the time in milliseconds. Obviously you can change these values to whatever you like. You could also add in additional CSS properties to animate!</p>
<p>In the following line we then reverse the effect when the user takes the mouse off the link, reducing <strong>paddingLeft</strong> back to 0.</p>
<p>It really is that simple. This effect looks best when there&#8217;s a few links using it because you get this wonderful cascading effect.</p>
<p>If you want to see a great example of a site that uses the jQuery link nudge effect, check out the footer of Chris Coyiers fantastic <a href="http://css-tricks.com/" target="_blank">CSS Tricks</a> site.</p>
<p>Ranger, out.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.richardshepherd.com/using-jquery-to-nudge-links/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
