-2

This is my code: http://jsfiddle.net/KCb5z/

The problem bit of code is here I think:

$(".nav").click(function (e) {
    e.preventDefault();
    var divId = $(this).attr('href');
    $('html, body').animate({
        scrollTop: $(divId).offset().top;
    }, 500);}
});

I think I have done something wrong with my bracketing because it doesn't seem to scroll correctly or even allow the persistent header to remain persistent. Can anyone show me where I went wrong please?

Rory McCrossan
  • 319,460
  • 37
  • 290
  • 318
J.Zil
  • 2,317
  • 7
  • 40
  • 75

2 Answers2

1

You can see the error from the browser console:

Uncaught SyntaxError: Unexpected token ;

The reason is because of ; after you've set the scrollTop value, you just need to remove it and it should work:

scrollTop: $(divId).offset().top;
// ---                          ^ remove this

Updated Fiddle

Felix
  • 37,443
  • 7
  • 40
  • 55
1

Apart from the spurious semicolon after .top

$('html, body').animate({scrollTop: $(divId).offset().top}, 500);

you might want to wrap the whole content thing in a div with a height and use overflow:auto to keep the menu

http://jsfiddle.net/mplungjan/7cZG7/

Also change the fiddle to head instead of onload

mplungjan
  • 155,085
  • 27
  • 166
  • 222