How To Design a Single Page Scrolling Site With Twitter Bootstrap

Today’s post is all about enabling a very cool web design technique natively in a Twitter Bootstrap layout. We will be integrating a jQuery-based smooth scrolling effect that works responsively.

View The Demo | Download the Source



You Will Need: 

Twitter Bootstrap provides for an awesome foundation to be creative upon. This is a great example of combining resources together to create a unique product. Check out our video for the full tutorial.

The idea of a single page scrolling website is certainly not a new one. However, it can be refined by adding in a simple easing effect to smoothly scroll from section to section, rather than the usual jumping navigation. Twitter Bootstrap already comes packed with scrollspy and great CSS attributes that will make integration a snap.

To get started I recommend downloading the jQuery one page nav plugin by Trevor Davis. Next we can simply add the proper files into our project. Into your plugins javascript file add the jQuery.scrollTo.js content first, then proceed with adding the jquery.nav.js content. Once added we are almost done with our JavaScript. Simply add the code below to the bottom of your html page to activate the scripts.

<script type="text/javascript">// <![CDATA[
$('#top-nav').onePageNav({
         currentClass: 'active',
         changeHash: true,
         scrollSpeed: 1200
         });
// ]]></script>

Ensure this code is placed below the area where you call jQuery

The JavaScript above features the primary call to our navigation while activating the “One Page Nav” plugin. In this case we have used a “ul” with an id of “top-nav”. But feel free to use any id that you would prefer, just ensure this jQuery call is adjusted properly.

Adding advanced functionality to Bootstrap can be a simple process. I would encourage you to play around with a number of plugins, and do not be limited by what is only on the Bootstrap documentation site. There are tons of great responsive resources our there to try, and Bootstrap is the perfect foundation to get started on.

About Brock Nunn

Brock Nunn is a web designer and developer specializing in building custom WordPress for over three years. Brock operates through his company Brock Nunn Web Design offering clients personal service with outstanding results. You can follow Brock on twitter @banunn.

5 Comments

  • Rami says:

    Excellent post, thank you. attachment_id seems to be broken on the ‘Download the Source’ href.

  • Fred Loorret says:

    Nice tutorial,

    But not very handy on mobile phones and specially on the iPad it makes not much sense.

    When you scroll to “Portfolio” how do you get back!?

    Maybe jQuery scroll to top!

  • Max says:

    Hey Brock! Awesome article. We built a single-page scrolling site for our company here: http://drifty.co/

    Basically, we just used standard jQuery animations for the scrolling, which I found to be a bit easier than using the common scrolling plugins for jQuery. You can see the code I used at the bottom of that if you view the source.

    We also did the same on our Bootstrap builder product Jetstrap: http://jetstrap.com/

    It’s a simple but cool effect, thanks for sharing your solution!

  • Matt says:

    Hello Brock,

    I’ve tried using this and it works great until i try changing the offset (I want to stop scrolling 40 px from the to of the section. This appears to work at first then does a terrible jump back to 0px offest which looks horrible. Do you know how to get the offset to work with your download?

    Many thanks!

  • Praveen says:

    Gr8 work Brock,

    I liked the idea of having single page for entire site. I have have added you on my blog list.
    Keep up the good work.
    Thanks

Leave a Reply

What is 5 + 3 ?
Please leave these two fields as-is:
IMPORTANT! To be able to proceed, you need to solve the following simple math (so we know that you are a human) :-)
Start planning your project today. Get Started