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,
edgeMargin = 20,
animationTime = 1200,
contentTop = [];
$(document).ready(function () {
$('html,body').bind('scroll mousedown DOMMouseScroll mousewheel keyup', function (e) {
if (e.which > 0 || e.type == 'mousedown' || e.type == 'mousewheel') {
$('html,body').stop();
}
});
$('#nav').find('a').each(function () {
contentTop.push($($(this).attr('href')).offset().top);
});
$('#nav').find('a').click(function () {
var sel = this,
newTop = Math.min(contentTop[$('#nav a').index($(this))], $(document).height() - $(window).height());
$('html,body').stop().animate({
'scrollTop': newTop
}, animationTime, function () {
window.location.hash = $(sel).attr('href');
});
return false;
});
$(window).scroll(function () {
var winTop = $(window).scrollTop(),
bodyHt = $(document).height(),
vpHt = $(window).height() + edgeMargin;
$.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.