diff options
| author | Reorx <novoreorx@gmail.com> | 2022-04-10 17:43:04 +0800 |
|---|---|---|
| committer | Reorx <novoreorx@gmail.com> | 2022-04-10 21:33:27 +0800 |
| commit | d50ce4575db054c1873e659c57a7ff1636b067e5 (patch) | |
| tree | daeb7f7211cc0d7054e964f68edd7eb33a4f24eb | |
| parent | 829bb016914e55405c56c3c2a0d5488c1a02ecae (diff) | |
add param DisableSmoothScroll
| -rw-r--r-- | layouts/partials/footer.html | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/layouts/partials/footer.html b/layouts/partials/footer.html index f5f04cf..9415aaa 100644 --- a/layouts/partials/footer.html +++ b/layouts/partials/footer.html @@ -24,6 +24,7 @@ {{- partial "extend_footer.html" . }} <script> + (function() { let menu = document.getElementById('menu') if (menu) { menu.scrollLeft = localStorage.getItem("menu-scroll-position"); @@ -32,17 +33,18 @@ } } + const disableSmoothScroll = '{{- if (.Param "DisableSmoothScroll") -}}1{{- end -}}' == '1'; + if (window.matchMedia('(prefers-reduced-motion: reduce)').matches || disableSmoothScroll) { + return; + } + // only run this code if smooth scroll should be enabled document.querySelectorAll('a[href^="#"]').forEach(anchor => { anchor.addEventListener("click", function (e) { e.preventDefault(); var id = this.getAttribute("href").substr(1); - if (!window.matchMedia('(prefers-reduced-motion: reduce)').matches) { - document.querySelector(`[id='${decodeURIComponent(id)}']`).scrollIntoView({ - behavior: "smooth" - }); - } else { - document.querySelector(`[id='${decodeURIComponent(id)}']`).scrollIntoView(); - } + document.querySelector(`[id='${decodeURIComponent(id)}']`).scrollIntoView({ + behavior: "smooth" + }); if (id === "top") { history.replaceState(null, null, " "); } else { @@ -50,7 +52,7 @@ } }); }); - + })(); </script> {{- if (not site.Params.disableScrollToTop) }} |
