I am a beginner in javascript and can't quite grasp what I need to change to make this work.
This is the link.
I have a container with a collapsable fixed navigation. You should be able to click on each of the nav items and scroll to the chapter. The thing is: it only works coming from the top or 'Chapter 1'. When I click on a nav chapter twice it goes up and down and doesn't just simply go to its anchor.
This is the javascript that I found when I had it set up without a fixed navigation — what to change for it to work the way I want?:
function scrollNav() {
$('.nav a').click(function(){
//Toggle Class
$(".active").removeClass("active");
$(this).closest('li').addClass("active");
var theClass = $(this).attr("class");
$('.'+theClass).parent('li').addClass('active');
//Animate
$('#container').stop().animate({
scrollTop: $( $(this).attr('href') ).offset().top - 180
}, 400);
return false;
});
$('.scrollTop a').scrollTop();
}
scrollNav();
Thanks a lot!