fix: if heading contains non English characters, cannot scroll properly (#228)

This commit is contained in:
hitzhangjie 2020-08-02 06:47:51 +08:00 committed by GitHub
parent e781be1620
commit 89b8d152a9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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;