Live DemoDownload Source Code

Getting Started

First I’ve downloaded a local copy of jQuery to keep with the other script files. Also we need a copy of the jQuery.scrollTo plugin which is a single .js file. I have created two alternate files index.html and styles.css for the page structure. We can break down the main contents first.

The heading contents should be straightforward with nothing overly complicated. The index file uses an HTML5 doctype along with the stylesheet and the two JS files we downloaded. Obviously there are alternatives for customizing the scroll effect, but in this situation it is much easier to implement a plugin. Inside the page HTML we can see how the navigation is setup.

All of the page is contained inside a wrapper using the ID #w. Another div #content marks the inner content on the page. This fixed navigation is kept within the page content for my demo, but you could theoretically move this anywhere else that fits nicely. Since it will be fixed you can always have the menu scrolling right along with the user no matter what placement.

The container #stickynav is used to keep all of the internal elements on top of the page content. I am using the CSS z-index property along with internal floats on all the list items. Notice the HREF values all point towards a hash sign located somewhere else on the page. We can use this value to determine where our slider should go.

Internal Content

After closing the navigation block we find a small number of content sections. There is a lot of extra spacing between content, just so you can see how it would behave in a typical webpage. Each block container is using the HTML5

element along with a class name .section.

The class is used for duplicate styles found in each of the content areas. It will save room in the stylesheet when copying over multiple properties for each element. By targeting the section ID we could apply unique backgrounds, text colors, box shadows, and other similar effects.

This method can include as many internal content sections as you need. Although the navigation menu can eventually grow too wide. In this case it could also be placed at the very top as a fixed navbar. I kept it within the content div so we can see how the solution works built around a page template. Let’s jump into the CSS styles for more detail.

CSS Page Design

I really wanted to distinguish between the top bar and this fixed sticky navigation. We could have fixed the very top brown navbar which also holds a link, but this can eat up a small portion of the layout. Instead I’ve created a new unordered list and styled each link to float along next to each other – keeping the menu tighter and more compact.

Looking at the container #stickynav you’ll notice this will span the entirety of the page width. Using a transparent background it certainly isn’t noticeable, but keep this in mind since you can expand the navigation even wider to fill the outer page wrapper.

Another interesting part of my stylesheet has the form inputs and page containers. These rules are all located at the bottom of the file along with typography updates. Notice how each header is centered on the page to offer space to the side for these navigation items. It wouldn’t be difficult to realign these headers to the right side giving even more space for navigation links.

I don’t have the contact form submitting anywhere but I did want it to have some decent custom styles. Certainly nothing special but it does reset the default fonts and colors. Also if you need to expand the central content area you can find the width: 750px property attached onto the outer wrapper. Nothing out of the ordinary but it is good to understand these basic styles.

Smooth Scrolling with jQuery

Now this final block of code is pretty simple even if you hardly understand scripting. I have added a new tag before my closing which targets the fixed nav anchor links. Whenever a user clicks we pull out the hash value and immediately scroll to that page section.

The jQuery .click() method includes a parameter for the event handler. With this parameter we cancel the default behavior so the browser will not jump down the page. Then jQuery scrollTo is run targeting the current link value this.hash.

The effect is simple yet handy because you can implement the page concept very quickly. I am sure there are other similar plugins related to jQuery scrollTo, and if you have the time it can be fun toying around with alternatives.

Live DemoDownload Source Code

Final Thoughts

Simpler websites don’t require a convoluted menu system and utilizing techniques like this can help when organizing content. I do hope this tutorial can provide some use for developers creating a simple webpage layout. jQuery is very extensible and it’s easy to expand this codebase into your own jQuery plugin. Feel free to download a copy of my source code and see if you can incorporate this effect with any future projects.