diff options
Diffstat (limited to 'static')
-rw-r--r-- | static/js/toc.js | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/static/js/toc.js b/static/js/toc.js new file mode 100644 index 0000000..2c5b9fb --- /dev/null +++ b/static/js/toc.js @@ -0,0 +1,18 @@ +$().ready(function(){ + $(window).bind('scroll', function() { + var currentTop = $(window).scrollTop(); + var currentBottom = $(window).scrollTop() + $(window).height(); + var pageBottom = $('#EOF').offset().top; + var elems = $(":header"); + elems.each(function(idx){ + var elemTop = $(this).offset().top; + var id = $(this).attr('id'); + var navElem = $('#' + id+ '-nav'); + if(currentTop >= elemTop || currentBottom >= pageBottom){ + navElem.addClass('toc-active'); + } else { + navElem.removeClass('toc-active'); + } + }) + }); +});
\ No newline at end of file |