diff options
author | Brando Zhang <347830597@qq.com> | 2020-12-08 05:56:35 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-08 05:56:35 +0300 |
commit | ed6f93aca9ddf4df496ba8715e04bd5813333254 (patch) | |
tree | 71f4bdbd277cd0ceef3bda64ba5d7e9474879e00 | |
parent | 3e09b77eabeb3e0309d5a96819eea6aa0b7fdd05 (diff) |
Fix: non-hash nav-item can be redirected
-rw-r--r-- | assets/js/script.js | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/assets/js/script.js b/assets/js/script.js index 7e7f1aa..9123063 100644 --- a/assets/js/script.js +++ b/assets/js/script.js @@ -69,13 +69,16 @@ $(document).ready(function () { // Smooth scrolling var scrollLink = $(".scroll"); scrollLink.click(function (e) { - e.preventDefault(); - $("body,html").animate( - { - scrollTop: $(this.hash).offset().top, - }, - 1000 - ); + let elem = $(this.hash) + if (elem.length) { + e.preventDefault(); + $("body,html").animate( + { + scrollTop: elem.offset().top, + }, + 1000 + ); + } }); $(".navbar-nav>li>a").on("click", function () { |