From 89b8d152a9f6c83eef086747bcb29f86da92b9d0 Mon Sep 17 00:00:00 2001 From: hitzhangjie Date: Sun, 2 Aug 2020 06:47:51 +0800 Subject: [PATCH] fix: if heading contains non English characters, cannot scroll properly (#228) --- assets/js/index.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/assets/js/index.js b/assets/js/index.js index 3b1a6b3..5705bd2 100644 --- a/assets/js/index.js +++ b/assets/js/index.js @@ -21,8 +21,15 @@ document.addEventListener("DOMContentLoaded", function () { // Bitty scrolling links script $("a[href^=\"#\"]").click(function(e) { e.preventDefault(); + //BUG fix: https://github.com/victoriadrake/hugo-theme-introduction/issues/108 + // + //let's get the right attribute `id` of the heading + v = e.target.href.replace(/http.*#/, '') + id = decodeURI(v) + $("html, body").animate({ - scrollTop: $(document.getElementById(this.hash.substr(1))).offset().top + //scrollTop: $(document.getElementById(this.hash.substr(1))).offset().top + scrollTop: $(document.getElementById(id)).offset().top }, 500); $("#nav-menu").removeClass("is-active"); return true;