Template:ETH Zurich/scroll highlight.js

/* Use this to highlight current heading */ $(window).scroll(function(){ /* inspired by http://jsfiddle.net/8n06pvy9/9/ */

var windowPos = $(window).scrollTop(); $('#sidemenu li a[href^="#"]').each(function() {

           var currentLink = $(this);

if ($(currentLink.attr("href")).length > 0)

               {
               var refElement = $(currentLink.attr("href"));
               if (refElement.position().top <= windowPos && (refElement.position().top + refElement.height() + $("#sidemenu").height() ) > windowPos) {
                   $('#sidemenu li a').removeClass("current");
                   currentLink.addClass("current");
               }
               else{
                   currentLink.removeClass("current");
               }
           }

});


});