Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/AmazingRise/hugo-theme-diary.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/static
diff options
context:
space:
mode:
authoramazingrise <8315221+AmazingRise@users.noreply.github.com>2020-01-30 09:45:36 +0300
committeramazingrise <8315221+AmazingRise@users.noreply.github.com>2020-01-30 09:45:36 +0300
commitc5a771d8b6822b28ff66d70df166dac733cc9764 (patch)
tree42fe4260869b5b78b32a55b6803d0252d289c66a /static
parent06323c060dec93201b03d8334b8d49cbed3b9057 (diff)
Fix ToC scrollspy failed issue in new Hugo version.
Diffstat (limited to 'static')
-rw-r--r--static/js/toc.js18
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