diff --git a/_layouts/default.html b/_layouts/default.html index 7bcd73c..4379dd3 100644 --- a/_layouts/default.html +++ b/_layouts/default.html @@ -85,5 +85,6 @@ + diff --git a/scripts/navhighlight.js b/scripts/navhighlight.js new file mode 100644 index 0000000..ce61703 --- /dev/null +++ b/scripts/navhighlight.js @@ -0,0 +1,28 @@ +(function ($) { + $(window).scroll(function() { + //console.log("They see me scrollin, they hatin"); + + //clear highlighting + $('a').removeClass("active"); + + //calc current viewport + var viewTop = $(window).scrollTop(); + var viewBottom = viewTop + $(window).height(); + + //for all h1 and h2 elements, check if they are visible + //performance tweak: stop each() after the first element is found to be behind view + $('h1, h2').each(function(i,e) { + //get element position; + var eTop = $(e).offset().top; + var eBottom = eTop + $(e).height(); + if (eTop >= viewTop) { + if (eBottom <= viewBottom) { + $('a[href="#'+e.id+'"]').addClass("active"); + } else { + console.log("Start skipping test with "+e.id); + return false; + } + } + }); + }); +})(jQuery); diff --git a/styles/site/site-navigation.less b/styles/site/site-navigation.less index 20f9fd4..4f59179 100644 --- a/styles/site/site-navigation.less +++ b/styles/site/site-navigation.less @@ -30,6 +30,9 @@ text-decoration: none; } } +.site-navigation a.active{ + background-color: #ff9; +} .site-navigation ul ul{ .mls; .pth;