Q:

jQuery scrollTo.js keyboard control misbehaving

Here's a live version of the page in question: http://agoodman.com.au/index1.html
I'm using Bootstrap to build a one-pager website, and scrollTo is being used to scroll up/down the different sections. There is a top navbar, with the code:
<ul class="nav">
  <li class="active"><a href="#intro" onclick="$.scrollTo( '#intro', 600 );">Top</a></li>
  <li><a href="#service" onclick="$.scrollTo( '#service', 600 );">What we do</a></li>
  <li><a href="#howitworks" onclick="$.scrollTo( '#howitworks', 600 );">How it works</a></li>
  <li><a href="#fees" onclick="$.scrollTo( '#fees', 600 );">Our fees</a></li>
  <li><a href="#why" onclick="$.scrollTo( '#why', 600 );">Why do it?</a></li>
  <li><a href="#map" onclick="$.scrollTo( '#map', 600 );">Map</a></li>
  <li><a href="#contact" onclick="$.scrollTo( '#contact', 600 );">Contact</a></li>
</ul>​

The scrolling works fine when you click on the navbar with the mouse, no weird behaviour at all. I'm then using this jquery code to control the navbar with the up/down arrows of the keyboard:
$(document).keyup(function(e) {
          var p = $("li.active");
          if (e.keyCode === 38) {
          p.prev().find("a").click();
          } else if (e.keyCode === 40) {
          p.next().find('a').click();
          }
        });

This works, for the most part. However, there are two problems that I'd like to solve:
1. When pressing up/down, the page moves up/down one small jump (as if pressing an arrow key on any website does) and then scrolls to the next div. I tried putting event.preventDefualt(); in the jquery if/else statement but it didn't do anything. Any ideas on how to prevent the default up/down action here?
2. Pressing the "up" key causes the page to scroll up two sections rather than one. For instance, go to the "#why" section, then press up. It scrolls to "#fees" then scrolls again to "#howitworks". Perhaps scrollspy.js is conflicting here?
Would appreciate being pointed in the right direction in this one.
Cheers

A:

Use keydown. Then either return true and e.preventDefault() will do what you want.

