diff options
author | amazingrise <8315221+AmazingRise@users.noreply.github.com> | 2020-01-30 09:45:36 +0300 |
---|---|---|
committer | amazingrise <8315221+AmazingRise@users.noreply.github.com> | 2020-01-30 09:45:36 +0300 |
commit | c5a771d8b6822b28ff66d70df166dac733cc9764 (patch) | |
tree | 42fe4260869b5b78b32a55b6803d0252d289c66a /static | |
parent | 06323c060dec93201b03d8334b8d49cbed3b9057 (diff) |
Fix ToC scrollspy failed issue in new Hugo version.
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 |