$(window).scroll(function( ) {
that.updatePosition( );
that.updateMenuItems( );
});
The updateMenuItems() function is defined on line 3611
updateMenuItems : function( ) {
if (this.scrolling) return;
if($("#ViewToc").hasClass("viewCurrent") == true) {
var i = 0, scrollTop = 0;
scrollTop = $(window).scrollTop( );
scrollTop -= $("#header").outerHeight(true);
scrollTop -= $("#ViewToc .ctnr .ctnt h4").css("padding-top").replace("px", "") * 1;
scrollTop -= $("#ViewToc .ctnr .ctnt h4").css("margin-top").replace("px", "") * 1;
scrollTop += 60; //GRACE OFFSET
$("#ViewToc .ctnr .ctnt h4").each(function( ) {
if($(this).position( ).top <= scrollTop) i++;
});
$("#ViewTocMini .ctnr .ctnt h4").parent( ).removeClass("current");
$("#ViewTocMini .ctnr .ctnt h4:eq(" + (i - 1) + ")").parent( ).addClass("current");
}
},
I read this as saying, Once the user stops scrolling, if one of the sections has the class 'viewCurrent', then for each h4 in ViewToc, add 1 to i if the top of the section is less than the current position. Finally remove the class 'current' from whichever ViewTocMini element has it and set it on the element corresponding to i.
You just need to create a listener for each menu item and content location pair and toggle the right styles.
posted by michaelh at 10:04 AM on September 12, 2011