<?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>Paul Bennett - User Interface Developer &#187; Navigation</title>
	<atom:link href="http://pmbennett.net/tag/navigation/feed/" rel="self" type="application/rss+xml" />
	<link>http://pmbennett.net</link>
	<description></description>
	<lastBuildDate>Thu, 27 Oct 2011 15:10:11 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Fixed Scrolling Navigation</title>
		<link>http://pmbennett.net/2010/02/09/fixed-scrolling-navigation/</link>
		<comments>http://pmbennett.net/2010/02/09/fixed-scrolling-navigation/#comments</comments>
		<pubDate>Tue, 09 Feb 2010 18:09:30 +0000</pubDate>
		<dc:creator>paul</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Navigation]]></category>

		<guid isPermaLink="false">http://pmbennett.net/?p=232</guid>
		<description><![CDATA[<p>Recently, I was faced with the requirement to make a horizontal navigation bar fixed to the top of browser window, but only when the user scrolls past it. I had a quick Google around, and found a few plugins that did way more than I needed them to. I was certain this could be achieved in a couple of lines using jQuery, so I did it myself.</p>]]></description>
			<content:encoded><![CDATA[<p>The structure of the HTML was as follows:</p>
<pre><code>&lt;header class="centered"&gt;
  Header markup goes here
&lt;/header&gt;
&lt;div id="main_content"&gt;
  Content goes here
&lt;/div&gt;
&lt;div id="nav_bar"&gt;
  Navigation goes here
&lt;/div&gt;</code></pre>
<p>I used CSS to position the navigation absolutely in between the header and the main content, and then wrote a small amount of jQuery to do the rest.</p>
<pre><code>$(document).ready(function() {
	var yOffset = $("#nav_bar").offset().top;
	$(window).scroll(function() {
		if ($(window).scrollTop() &gt; yOffset) {
			$("#nav_bar").css({
				'top': 0,
				'position': 'fixed'
			});
		} else {
			$("#nav_bar").css({
				'top': yOffset + 'px',
				'position': 'absolute'
			});
		}
	});
});</code></pre>
<p>This piece of JavaScript starts by finding the offset of the navigation from the top of the document. Then, it defines the scroll event for the window object, which checks to see if the window has been scrolled past the navigation element. If this has occurred, it fixes the navigation to the top of the window. If not, the navigation is returned to it&#8217;s default state.</p>
]]></content:encoded>
			<wfw:commentRss>http://pmbennett.net/2010/02/09/fixed-scrolling-navigation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

