JQuery Highlight Nav scroll links not working

I am extremely new to JavaScript, so I apologize in advance. I am trying to create a one-page html document for a school project using a list of navigation links that change when the anchor scrolls. I tried various methods found on Jfiddle and through stackoverflow. This is the method I'm trying to execute now: http://jsfiddle.net/m2zQE/

 var topRange = 200, // measure from the top of the viewport to X pixels down
 edgeMargin = 20, // margin above the top or margin from the end of the page
 animationTime = 1200, // time in milliseconds
 contentTop = [];



$(document).ready(function () {

     // Stop animated scroll if the user does something
     $('html,body').bind('scroll mousedown DOMMouseScroll mousewheel keyup', function (e) {
         if (e.which > 0 || e.type == 'mousedown' || e.type == 'mousewheel') {
             $('html,body').stop();
         }
     });

     // Set up content an array of locations
     $('#nav').find('a').each(function () {
         contentTop.push($($(this).attr('href')).offset().top);
     });

     // Animate menu scroll to content
     $('#nav').find('a').click(function () {
         var sel = this,
             newTop = Math.min(contentTop[$('#nav a').index($(this))], $(document).height() - $(window).height()); // get content top or top position if at the document bottom
         $('html,body').stop().animate({
             'scrollTop': newTop
         }, animationTime, function () {
             window.location.hash = $(sel).attr('href');
         });
         return false;
     });

     // adjust side menu
     $(window).scroll(function () {
         var winTop = $(window).scrollTop(),
             bodyHt = $(document).height(),
             vpHt = $(window).height() + edgeMargin; // viewport height + margin
         $.each(contentTop, function (i, loc) {
             if ((loc > winTop - edgeMargin && (loc < winTop + topRange || (winTop + vpHt) >= bodyHt))) {
                 $('#nav li')
                     .removeClass('selected')
                     .eq(i).addClass('selected');
             }
         });
     });

     });

I'm still out of luck. I have already searched if I can debug the problem and tried to change the order of the code as well as the order of the jquery call.

Here is the link to the site: https://googledrive.com/host/0BwvPQbnPrz_LMlZDeGlFY2Yydmc/index.html

I used html5boilerplate as a starting point. Thanks in advance.

+2
1

,

Math.min(contentTop[$('#nav a').index($(this))], $(document).height() - $(window).height())

, NaN.

, , , scrollTop.

:

$('html, body').animate({
    scrollTop: $("#elementID").offset().top
}, 2000);

,

$('html, body').animate({
    scrollTop: $("#container-fulid:nth-child(2)").offset().top
}, 2000);

, , nth-child CSS3.

, , , bootstrap 3.0, scrollspy, , .

http://getbootstrap.com/javascript/#scrollspy

0

All Articles