-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
  • 331,213
  • 40
  • 305
  • 339
J.Zil
  • 2,397
  • 7
  • 44
  • 78

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,892
  • 8
  • 43
  • 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
  • 169,008
  • 28
  • 173
  • 236